Maybe I made a mistake with the "end" statements, but it doesn't seem like it.
Maybe I made a mistake with the "end" statements, but it doesn't seem like it.
New here? I'm Roha — want a quick tour?
Now, an error is reported on the lineif GetHeroName(defH) == "Shadwyn" and GetHeroName(attH) == "Nur" then
Maybe I just miscalculated with the ends, but it doesn't seem like it.
Added 4 hours 8 minutes ago
How do I write the code so that the hero who activated the object is teleported, if that hero belongs to the first player?
Trigger(OBJECT_TOUCH_TRIGGER,"portal","Portal_HaladF")
function Portal_HaladF(heroname)
if(GetObjectOwner(heroname) == 1) then
SetObjectPosition(heroname,56,90,0)
end
endHere, instead of "portal" in the trigger, you give your own name, and everything will work.
And so that you understand, perhaps, what the trick is with naming arguments:
Trigger(OBJECT_TOUCH_TRIGGER,"portal","Portal_HaladF")
function Portal_Halad(red_flower)
if(GetObjectOwner(red_flower) == 1) then
SetObjectPosition(red_flower,56,90,0)
end
endInstead of "heroname," "red_flower" appears. Do you agree that flowers have nothing to do with a hero? Of course, no one would name it that way because then you wouldn't be able to understand what the red flower is, but you need to understand the essence - the name itself is not important, the main thing is that it is inserted in the right place. If the trigger gives you the hero's name as the first argument, then it will give it to you regardless of how you name the variable.
What could be the reason here? Why doesn't the check for the hero's name or their affiliation with the first player work in the second function?
function Town_Portal_Tilgatal_Obelisk_F (heroname)
local player = GetObjectOwner(heroname)
if(player == 1) then
QuestionBox("/Maps/SingleMissions/L1/Portal_Halad.txt", "Portal_HaladF(player,[["..heroname.."]])", "Town_Portal_Torost_question_F(player,[["..heroname.."]])"); ----question: do you want to go to Halad? If yes - teleport, if no - offer Torost.
sleep(1)
else
print("not that hero");
end;
end;
Trigger(OBJECT_TOUCH_TRIGGER, "town_portal_Tilgatal", "Town_Portal_Tilgatal_Obelisk_F");Then, we slightly modify the callback function, taking into account that the player is passed first
function Portal_HaladF (player,heroname)
local player = player + 0 -- I'm explaining a trick here. When you pass arguments directly in quotes, they are all passed as strings.
-- in player at the function's input, there's "1", and if you add zero to a string containing a number, it becomes a number (i.e., it will just be 1).
if(player == 1) then
SetObjectPosition(heroname, 56, 90, 0);
else
print("not that hero"); -- here, there's a check for the player, so it's more appropriate to write "not that player"
end;
end;Now, let me explain what happened. You can pass arguments to the callback function manually (as in my example), but the standard argument passing is overwritten (I couldn't come up with a solution for this other than manually passing the parameters that the game was passing before. In this case, it's possible because only the player number is being passed). That is, we simply open the parentheses (yes, directly in quotes) and write the variables there. Important: numbers can be passed directly by simply specifying the variable in parentheses. This [["..heroname.."]] dinosaur is a way to pass a string. [[ ]] are also quotes. It's important that the quotes before the two dots match the quotes with which you open the
name of your function; otherwise, it won't work. This is a rather obscure thing, and it's worth reading about in Hottabych's guide.
P.S.
TalkBox would be suitable for your needs, but I'm afraid its use may cause difficulties.
Unfortunately, it doesn't work. The game displays:
[Script Warning!] Walue was NIL when getting global with name 'player'
Script Error: attempt to perform arithmetic on a nil value
P.S. I don't even know what TalkBox is.
SetObjectEnabled("testObj",nil)
Trigger(OBJECT_TOUCH_TRIGGER,"testObj","testF")
function testF(heroname)
local player = GetObjectOwner(heroname);
if(player == 1) then
QuestionBox(GetMapDataPath().."messages/broken_portal.txt","callbackF([["..player.."]],[["..heroname.."]])","callback_noF([["..player.."]],[["..heroname.."]])") -- arbitrary message from my folder.
end;
end;
function callbackF(player,heroname)
local x,y,floorID = GetObjectPosition(heroname) -- For testing, the hero is simply teleported to the same location
SetObjectPosition(heroname,x,y,floorID)
end;
function callback_noF(player,heroname)
local x,y,floorID = GetObjectPosition(heroname)-- For testing, the hero is simply teleported to the same location + 5 cells along all axes
SetObjectPosition(heroname,x+5,y+5,floorID)
endBelow is your already corrected code
function Town_Portal_Tilgatal_Obelisk_F (heroname)
local player = GetObjectOwner(heroname)
if(player == 1) then
QuestionBox("/Maps/SingleMissions/L1/Portal_Halad.txt", "Portal_HaladF([["..player.."]],[["..heroname.."]])", "Town_Portal_Torost_question_F([["..player.."]],[["..heroname.."]])"); ----question: do you want to go to Halad? If yes - we teleport, if not - we offer Torost.
sleep(1)
else
print("not that hero");
end;
end;
Trigger(OBJECT_TOUCH_TRIGGER, "town_portal_Tilgatal", "Town_Portal_Tilgatal_Obelisk_F");function Portal_HaladF (player,heroname)
SetObjectPosition(heroname, 56, 90, 0);
end;I hope it works. My head isn't working well tonight - I apologize if there is some stupid mistake, check the logic of what is happening five times just in case :)
SetObjectPosition(heroname,x+5,y+5,floorID)I didn't know that was possible, and it will be useful for one of my quests right now.
Good night).
Jewily, it’s working now. Thank you very much. And a second thank you forSetObjectPosition(heroname,x+5,y+5,floorID)I didn’t know you could do that, and it will be useful for one of my quests right now.
Good night).
function test()
local importantValue = random(10)
Trigger(4, "TestObject", "ImportantFunc")
ImportantFunc = function(hero, obj)
local value = %importantValue
print(hero, obj, value)
end
end
--This way, we pass the two original arguments + the important value from the parent function to the callback.
Jewilly, there is a way to pass all the necessary data to the callback using upvalues:function test() local importantValue = random(10) Trigger(4, "TestObject", "ImportantFunc") ImportantFunc = function(hero, obj) local value = %importantValue print(hero, obj, value) end end --This way, we pass the two original arguments + the important value from the parent function to the callback.