Posts from Scripts
local x, y, f = GetObjectPosition(hero_name);
then f will be the floor number.
BlueHeavenHero, if you write
local x, y, f = GetObjectPosition(hero_name);
then f will be the floor number.
I didn't think it could be this easy. Thanks, I'll try to do it again now.
BlueHeavenHero, I wrote such a function for my map:
function WhereAmI(obj)
local x, y, z = GetObjectPosition(obj);
if z == 0 then
return 0
elseif z == 1 then
return 1
end
endUsage:
if heroName == "Duncan" then
if WhereAmI( heroName ) == 0 then
DuncanInGround = 1
elseif WhereAmI( heroName ) == 1 then
DuncanInGround = 0
end
end
x, y, f = GetObjectPosition(hero_name);
It's recommended to give these variables longer names since they are visible throughout the entire script.
Hello everyone, I've been reading information about the talkboxforplayer function on the forum and elsewhere. Everything seems to be working except for one thing: the function doesn't recognize the hero that triggers it. The dialog box with options appears, the response texts are there, and the buttons are there, but the hero isn't recognized, and the army isn't granted.
The idea is this: a random hero touches a building, chooses a response, and receives an army.
The code itself was taken from Jack_of_shadows' Manuals:
The green color highlights the correct code that I copied, and the red color highlights the code that I wrote myself, which, of course, contains an error somewhere.
function DialogBox(icon, title, text, mode, callback, ...)
hero = human
if arg.n==1 then
TalkBoxForPlayers(GetCurrentPlayer(), icon, nil, text, nil, callback, mode, title, nil, 0, arg[1])
elseif arg.n==2 then
TalkBoxForPlayers(GetCurrentPlayer(), icon, nil, text, nil, callback, mode, title, nil, 0, arg[1], arg[2])
elseif arg.n==3 then
TalkBoxForPlayers(GetCurrentPlayer(), icon, nil, text, nil, callback, mode, title, nil, 0, arg[1], arg[2], arg[3])
elseif arg.n==4 then
TalkBoxForPlayers(GetCurrentPlayer(), icon, nil, text, nil, callback, mode, title, nil, 0, arg[1], arg[2], arg[3], arg[4])
elseif arg.n==5 then
TalkBoxForPlayers(GetCurrentPlayer(), icon, nil, text, nil, callback, mode, title, nil, 0, arg[1], arg[2], arg[3], arg[4], arg[5])
end;
end
Trigger (OBJECT_TOUCH_TRIGGER, "pokrov1", "Talk1");
function Talk1()
DialogBox("/UI/MessageBox/Message.xdb#xpointer(/Texture)","/UI/MessageBox/TalkBox/text.txt", "/Maps/Multiplayer/arena/voenachalnik1.txt", 1, "Talk1Callback", "/Maps/Multiplayer/arena/voenachalnik2.txt", "/Maps/Multiplayer/arena/voenachalnik3.txt", "/Maps/Multiplayer/arena/voenachalnik4.txt")
end
function Talk1Callback(pl, ans)
if (ans==1) and HasHeroSkill (human, 57)
then
AddHeroCreatures (human, 106, 50);
elseif (ans==2) and HasHeroSkill (human, 57)
then
AddHeroCreatures (human, 107, 50);
elseif (ans==3) and HasHeroSkill (human, 57)
then
AddHeroCreatures (human, 108, 50);
end;
end;
Thank you for your help.
green belly, I immediately see that your trigger isn't passing any arguments to the function with the DialogBox, i.e., to Talk1. Also, you seem to have incorrectly assigned the hero variable, with which you need to do something. First, you should remove the line hero = human from DialogBox (it's simply not needed there), replace the line function Talk1() with function Talk1(hero), and add the line human = hero to the function itself. Now, the script will know who human is so that it can give him creatures.
Thank you, I did it, and it worked.
Previously, I didn't specify or pass any variables or arguments.
Here I am again with TalkBoxForPlayers.
The problem is this: there's a working code snippet, and it's written 8 times for 8 players, triggered by touching 8 different objects. And that's where the biggest issue starts.
For the first 2 functions, everything works perfectly.
For functions 3-8, the dialog box isn't called.
For these same functions 3-8, the else messagebox line is called....
Here's the code:
function pokrov1F(hero)
human = hero
if HasHeroSkill(human, 80)
then
DialogBox("/UI/MessageBox/Message.xdb#xpointer(/Texture)","/UI/MessageBox/TalkBox/text.txt", "/Maps/Multiplayer/arena/pokrov1.txt", 1, "pokrov1otvetF", "/Maps/Multiplayer/arena/pokrov2.txt", "/Maps/Multiplayer/arena/pokrov3.txt", "/Maps/Multiplayer/arena/pokrov4.txt", "/Maps/Multiplayer/arena/pokrov5.txt")
Trigger (OBJECT_TOUCH_TRIGGER, "pokrov1", nil);
else MessageBox("/Maps/Multiplayer/arena/netpokrov.txt");
end;
end;
Trigger (OBJECT_TOUCH_TRIGGER, "pokrov1", "pokrov1F");
function pokrov1otvetF(pl, ans)
if (ans==1)
then
ChangeHeroStat(human, STAT_ATTACK, 3);
elseif (ans==2)
then
ChangeHeroStat(human, STAT_SPELL_POWER, 3);
elseif (ans==3)
then
ChangeHeroStat(human, STAT_KNOWLEDGE, 3);
elseif (ans==4)
then
ChangeHeroStat(human, STAT_LUCK, 2);
end;
end;
Of course, I change the parameters so that it works for different players.
I change them to the numbers 2, 3, and so on, up to 8; I've highlighted the parameters that are being changed in yellow.
I don't know where the problem is because in ALL the functions, the presence of perk 80 is actually checked, because when it's not present, the else messagebox is shown, but how is it that it works for numbers 1 and 2, but not after that?