Skip to content

Instantly share code, notes, and snippets.

@johnX9 johnX9/Players.cpp
Last active Jun 15, 2018

Embed
What would you like to do?
# Players.hpp
//@abi action
void additem(const account_name account, item purchased_item);
# Players.cpp
void Players::additem(const account_name account, item purchased_item) {
playerIndex players(_self, _self);
auto iterator = players.find(account);
eosio_assert(iterator != players.end(), "Address for account not found");
players.modify(iterator, account, [&](auto& player) {
player.energy_points += purchased_item.power;
player.health_points += purchased_item.health;
player.level += purchased_item.level_up;
player.abilities.push_back(purchased_item.ability);
player.inventory.push_back(item{
purchased_item.item_id,
purchased_item.name,
purchased_item.power,
purchased_item.health,
purchased_item.ability,
purchased_item.level_up
});
});
print("Item Id: ", purchased_item.item_id);
print(" | Name: ", purchased_item.name.c_str());
print(" | Power: ", purchased_item.power);
print(" | Health: ", purchased_item.health);
print(" | Ability: ", purchased_item.ability.c_str());
print(" | Level up: ", purchased_item.level_up);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.