onDie hook questions again.

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
Ryeath_Greystalk
Posts: 366
Joined: Tue Jan 15, 2013 3:26 am
Location: Oregon

onDie hook questions again.

Post 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.
alois
Posts: 112
Joined: Mon Feb 18, 2013 7:29 am

Re: onDie hook questions again.

Post 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 :)
Ryeath_Greystalk
Posts: 366
Joined: Tue Jan 15, 2013 3:26 am
Location: Oregon

Re: onDie hook questions again.

Post 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.
Scaramuth
Posts: 14
Joined: Thu Aug 08, 2013 7:57 pm

Re: onDie hook questions again.

Post 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:
SpoilerShow
onDie = function(self)
return death_script.death(party)
end,
and I have an LUA script in the editior labled death_script with the following:
SpoilerShow
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.
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: onDie hook questions again.

Post by Komag »

increment()
Finished Dungeons - complete mods to play
Scaramuth
Posts: 14
Joined: Thu Aug 08, 2013 7:57 pm

Re: onDie hook questions again.

Post 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
User avatar
JohnWordsworth
Posts: 1397
Joined: Fri Sep 14, 2012 4:19 pm
Location: Devon, United Kingdom
Contact:

Re: onDie hook questions again.

Post 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.";
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
Scaramuth
Posts: 14
Joined: Thu Aug 08, 2013 7:57 pm

Re: onDie hook questions again.

Post by Scaramuth »

Awesome! Thank you!
Post Reply