Page 1 of 1
onDie hook questions again.
Posted: Tue Apr 23, 2013 8:00 am
by Ryeath_Greystalk
The mod assett reference says the onDie hook get one parameter - the dying champion. How do I use that?
I made my clone party and the function I put
onDie = function(deadPlayer)
on my script I did
function knockedOut(deadPlayer)
x = deadPlayer:getOrdinal()
hudPrint(""..x)
end
but that crashed to desktop when a player died.
What I was doing, and it worked fine, was just going through each player and checking if they were alive, but I think there has got to be a more eloquent way of doing it.
Again thanks for your help and patience.
Re: onDie hook questions again.
Posted: Tue Apr 23, 2013 8:15 am
by alois
It crashed because you have not specified which function of your script_entity is called when the player dies:
In the "clone party" part
Code: Select all
onDie = function(deadPlayer)
return my_script.knockedOut(deadPlayer)
end
and then you add the function knockedOut to a script_entity named "my_script".
Code: Select all
function knockedOut(deadPlayer)
-- do whatever you like here
return true -- or, otherwise, the player will not die!
end
alois

Re: onDie hook questions again.
Posted: Tue Apr 23, 2013 8:43 am
by Ryeath_Greystalk
Thanks for the answer.
Unfortunately I had not saved my work before I tested and lost my script in the crash, so I tried to post here from memory. I will try again tomorrow using your example.
Re: onDie hook questions again.
Posted: Tue Aug 13, 2013 9:21 pm
by Scaramuth
Hi, I am trying to do something similar here. I want a script that will return a party to a location on death and tell the party how many times they have died total. In my party hook i have:
onDie = function(self)
return death_script.death(party)
end,
and I have an LUA script in the editior labled death_script with the following:
function death()
playSound("party_fall")
counter_death:increment
local x = counter_death:getValue()
hudPrint("Number of Tries:" x)
party:playParticleEffect(damage_screen.lua)
party:setPosition(5,14,3,1)
return false
end
I get the "function arguments expected near" error for every line following counter_death:increment. I've tried looking at other posts but can't figure out what it wants. Any help is appreciated.
Re: onDie hook questions again.
Posted: Wed Aug 14, 2013 11:42 am
by Komag
increment()
Re: onDie hook questions again.
Posted: Thu Aug 15, 2013 7:39 pm
by Scaramuth
Thanks for pointing out the ().
The bigger problem I am trying to figure out is how to hudPrint my x variable. as seen above the code just gives me an error, but I rewrote it to this:
Code: Select all
function death()
playSound("party_fall")
counter_death:increment()
local x = counter_death:getValue()
hudPrint("number of times killed:", x)
party:setPosition(5,14,1,1)
return false
end
and now I have no error message but the variable never prints, all i get is "number of times killed:"
Interestingly, if i use print instead of hudPrint it works fine. I would rather it show up on the hud though
Re: onDie hook questions again.
Posted: Thu Aug 15, 2013 7:45 pm
by JohnWordsworth
print is a function that takes multiple arguments and prints them all on one line with a tab separator. hudPrint only takes a single string variable (I guess, from what you're saying) and prints that to the screen.
So, you just need to build a single string from all of the input and pass that as one variable, instead of passing 'x' as a second parameter to the function;
hudPrint("Some text: " .. x);
The '..' sticks two values together into a single string. You can use it over and over to build a long string if required..
local value = "You have collected " .. X .. " out of " .. Y .. " somethings.";
Re: onDie hook questions again.
Posted: Thu Aug 15, 2013 8:16 pm
by Scaramuth
Awesome! Thank you!