Skip to content
#2089
Auto-translated
Please help! I want to make it so that when a hero enters a tent, they can buy different stats for different prices. However, I don't understand how to make it so that when the player chooses what they want to buy, the script checks the amount of gold they have, and if they don't have enough, the hero can't make the purchase. Here's how I started writing the script:

function tradeF
TalkBoxForPlayers(1, nil, nil, nil, nil, "snar", 0, "path/name.txt", "path/name.txt", 0, "path/name.txt", "path/name.txt", "path/name.txt.", "path/name.txt");
end;
Trigger(OBJECT_TOUCH_TRIGGER, "trade", "tradeF");

function snar(player_id, choice)

monet = GetPlayerResource(1, GOLD);

if choice == 1
then SetPlayerResource(1, GOLD, monet-2000);
ChangeHeroStat("hero name", STAT_ATTACK, 1);
elseif choice == 2
then SetPlayerResource(1, GOLD, monet-3000);
ChangeHeroStat("hero name", STAT_ATTACK, 2);
elseif choice == 3
then SetPlayerResource(1, GOLD, monet-2000);
ChangeHeroStat("hero name", STAT_DEFENCE, 1);
elseif choice == 4
then SetPlayerResource(1, GOLD, monet-6000);
ChangeHeroStat("hero name", STAT_DEFENCE, 2);
TeachHeroSpell("hero name", 25);
end;
end;

Here, "trade" is the name of the object where the trading takes place.
I tried writing "if A and B then C" to specify a second condition (the required amount of gold) after "and" for obtaining the desired stats, but it turned into a complete mess.

Statistics

Welcome our newest member: Emil