Skip to content

Instantly share code, notes, and snippets.

@johnX9
Last active June 15, 2018 01:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnX9/9966ef5813f851cf990172187cb536a5 to your computer and use it in GitHub Desktop.
Save johnX9/9966ef5813f851cf990172187cb536a5 to your computer and use it in GitHub Desktop.
# 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