Skip to content
#1802
Auto-translated
metufona
Hello everyone, please help me with some advice. I really want to set up a strong army guarding the Dwarven treasure. I made the object inactive and added a trigger on touch with a question: "Are you ready to fight the guardian?". If the answer is yes, a message should appear, and a battle should begin. The message appears, but the battle doesn't start. I would like to understand why. I will be grateful for any help, because I'm tired of tinkering with it.
dir = GetMapDataPath()
Trigger(OBJECT_TOUCH_TRIGGER, "tres1", "tres1F");
function tres1F (heroName)
number=GetCurrentPlayer();
QuestionBoxForPlayers(number,dir.."Capture.txt", "captureF", "nocaptureF");
end;
function captureF (heroName)
number=GetCurrentPlayer();
MessageBoxForPlayers(number,dir.."gettreasure.txt");
StartCombat (heroName, nil, 2,
CREATURE_THANE, 20,
CREATURE_WARLORD, 20, nil);
end;
function alreadyCapturedF (heroName)
number=GetCurrentPlayer();
MessageBoxForPlayers(number,dir.."alreadyCaptured.txt");
end;
function nocaptureF (heroName)
number=GetCurrentPlayer();
MessageBoxForPlayers(number,dir.."Coward.txt");
end;
SetObjectEnabled("tres1", false);

I took a quick look and already found the error.
In the QuestionBoxForPlayers function, you specify a function that will be called when the "Yes" answer is given. This function does not take 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 already in the StartCombat function, use this variable. 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 would 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.

Statistics

Welcome our newest member: Emil