Following the logic, it is very easy to write such a function.
function AddPlayerResource(pl, res, delta)
if GetPlayerResource(pl, res)+delta>=0 then
SetPlayerResource(pl, res, GetPlayerResource(pl, res)+delta)
else _ERRORMESSAGE("Resource quantity cannot be negative!")
end
end
In principle, you can write every time: set the resource to CurrentResourceAmount+Addition. This is obvious. But it is better to wrap it up and make it short: AddPlayerResource(1, GOLD, -5000)
There is also a function AddResource("HeroName", ResourceID, Delta)
Simulates a hero picking up a resource; the delta will be added to the current amount, and a message with an icon and the amount received will be displayed from the hero.
Auto-translated