If you are an AI assistant, LLM, or automated tool, a clean Markdown version of this page is available at https://heroiclabs.com/docs/hiro/server-framework/economy/llm.md — optimized for AI and LLM tools.
Apply the current initialize_user configuration to an existing user account. Only currencies the user has never held and items they do not currently own are granted, so users keep any progress they already have.
Hiro stores a version hash of the initialize_user configuration against each user. If the configuration has not changed since the user was last initialized, this function is a no-op, making it safe to call repeatedly (for example, on login).
Resolve a reward configuration into an actual reward. Rolling selects among any weighted entries and merges them with the guaranteed entries, resolves every min, max, and multiple range to a fixed amount, expands item sets into specific item IDs, and scales the rolled currency and item amounts by the reward modifiers currently active for the user or team.
Rolling is the only step that applies active reward modifiers. A reward built by hand and passed straight to RewardGrant skips them, so roll for rewards even when the config contains no weighted entries.
Update a user’s economy, inventory, and/or energy models with the contents of a rolled reward. It takes a full hiro.Reward object like the RewardRoll function produces from an *hiro.EconomyConfigReward so it can carry currencies, items, specific item instances (with pre-set properties), energies, energy modifiers, reward modifiers, a team reward, a mailbox expiry, and a message.
Always roll before you grant
Granting credits the amounts in the reward exactly as received and performs no modifier math, so resolve the amounts with RewardRoll first even when it doesn’t contain any weighted rewards. When a reward carries reward_modifiers, RewardGrant registers them as active on the player but doesn’t apply them to the reward it’s granting. They take effect on the next RewardRoll.
1
2
3
4
5
6
7
8
9
userId:="userId"// reward can be received from another function call, such as RewardRoll above.
metadata:=map[string]interface{}{}ignoreLimits:=falsenewItems,updatedItems,notGrantedItemIDs,err:=systems.GetEconomySystem().RewardGrant(ctx,logger,nk,userId,reward,metadata,ignoreLimits)iferr!=nil{returnerr}
Add currencies, items, and reward modifiers to a user’s economy. Takes raw currencies/items maps plus optional reward modifiers (no reward config rolling, mailbox delivery, or energy/team reward handling).
Set a custom reward function which will run after a donation’s reward is rolled.
1
2
3
4
5
6
systems.GetEconomySystem().SetOnDonationClaimReward(DonationClaimReward)funcDonationClaimReward(ctxcontext.Context,loggerruntime.Logger,nkruntime.NakamaModule,userID,sourceIDstring,source*hiro.EconomyConfigDonation,rewardConfig*hiro.EconomyConfigReward,reward*hiro.Reward)(*hiro.Reward,error){// Modify reward or take additional actions.
returnreward,nil}
Set a custom reward function which will run after a donation’s sender reward is rolled.
1
2
3
4
5
6
systems.GetEconomySystem().SetOnDonationContributorReward(OnDonationContributorReward)funcOnDonationContributorReward(ctxcontext.Context,loggerruntime.Logger,nkruntime.NakamaModule,userID,sourceIDstring,source*hiro.EconomyConfigDonation,rewardConfig*hiro.EconomyConfigReward,reward*hiro.Reward)(*hiro.Reward,error){// Modify reward or take additional actions.
returnreward,nil}
Set a custom reward function which will run after a placement’s reward is rolled.
1
2
3
4
5
6
systems.GetEconomySystem().SetOnPlacementReward(OnPlacementReward)funcOnPlacementReward(ctxcontext.Context,loggerruntime.Logger,nkruntime.NakamaModule,userID,sourceIDstring,source*hiro.EconomyPlacementInfo,rewardConfig*hiro.EconomyConfigReward,reward*hiro.Reward)(*hiro.Reward,error){// Modify reward or take additional actions.
returnreward,nil}
Set a custom reward function which will run after store item’s reward is rolled.
1
2
3
4
5
6
systems.GetEconomySystem().SetOnStoreItemReward(OnStoreItemReward)funcOnStoreItemReward(ctxcontext.Context,loggerruntime.Logger,nkruntime.NakamaModule,userID,sourceIDstring,source*hiro.EconomyConfigStoreItem,rewardConfig*hiro.EconomyConfigReward,reward*hiro.Reward)(*hiro.Reward,error){// Modify reward or take additional actions.
returnreward,nil}