Skip to content
#1804
Auto-translated
Juss456
I took a quick look and already found a mistake.
In the QuestionBoxForPlayers function, you define a function that will be called when the "Yes" answer is given. This function does not accept any parameters, i.e., in the line function captureF (heroName), the parentheses should be empty.
There is a solution, for example, like this: before this entire block, define a global variable, i.e., write a line like hero=''.
Then, in the function where QuestionBox is written, assign the hero's name to this variable like this: hero= heroName. And then use this variable in the StartCombat function. It will look something like this:
dir = GetMapDataPath()
hero='';
Trigger(OBJECT_TOUCH_TRIGGER, "tres1", "tres1F");
function tres1F (heroName)
number=GetCurrentPlayer();
hero=heroName;
QuestionBoxForPlayers(number,dir.."Capture.txt", "captureF", "nocaptureF");
end;
function captureF ()
number=GetCurrentPlayer();
MessageBoxForPlayers(number,dir.."gettreasure.txt");
StartCombat (hero, nil, 2,
CREATURE_THANE, 20,
CREATURE_WARLORD, 20, nil);
end;
function alreadyCapturedF (heroName)
number=GetCurrentPlayer();
MessageBoxForPlayers(number,dir.."alreadyCaptured.txt");
end;
function nocaptureF ()
number=GetCurrentPlayer();
hero='';
MessageBoxForPlayers(number,dir.."Coward.txt");
end;
SetObjectEnabled("tres1", nil);

I'd also like to note that it would be good to add a function to the StartCombat function that will be called after the battle. Thanks to it, you can reward the hero, remove the trigger from the building, etc.

Thank you very much, now everything works! I will keep in mind for the future that such functions should be written without parameters.
I was already planning to add a function after the battle in StartCombat, I'm just doing everything in stages so as not to get confused.

RedHeavenHero
Yes, and MessageBoxForPlayers takes not the player as the first parameter, but its filter GetPlayerFilter(number). There will be no visible difference if there are 1-2 players, but errors will occur for >2. It is also desirable to add a check to see if the player is a computer or not.
Only one player will have access to this object. Therefore, I'd rather leave it as is. But I will keep it in mind for the future, thank you!

Statistics

Welcome our newest member: dodoD0D0