Одиночные: Завеса срывается, Посол, Последний рывок, Эхо Пустоты
Кампания: Империя Единорога
Существа NCF
Орден Порядка: 1
Нейтралы: 1 2 3 4
New here? I'm Roha — want a quick tour?
Hmm, that's a shame. So, the problem lies elsewhere...
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);
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 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.
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'll keep it in mind for the future, thanks!
Then why not use a regular MessageBox?
Does the IsHeroAlive function check for the presence of a hero in the city garrison?
I didn't quite understand. The function returns 1 if the hero is alive, including if he is in the city garrison, otherwise it returns nil.