Page 1 of 1
Question regarding Monster:getHealth()
Posted: Fri Jul 26, 2013 7:08 pm
by SeyProdumen
Hello everyone,
I'm fairly new to scripting and I'm currently experimenting with creating a monster bossfight.
I understand that you can get a monster's HP through Monster:getHealth(). However, I'd like to create a script along the following lines:
Code: Select all
findEntity("monster")
if monster:getHealth("< 50") then
monster:destroy()
Fairly simple, but it doesn't seem to work, as getHealth() only registers the exact amount of HP, or does it?
I read that LUA does know the >/< symbols. Do I need to create a hook for this purpose?
Thanks in advance.
Re: Question regarding Monster:getHealth()
Posted: Fri Jul 26, 2013 7:28 pm
by JohnWordsworth
Just a few slight tweaks with regards to the structure of Lua are required. I'll post a version that should work, and then explain!
Code: Select all
local monster = findEntity("monster");
if monster:getHealth() < 50 then
monster:destroy();
end
So, first of all, you find the monster entity. I think if your monster is always going to have the ID monster, you can actually skip that line, as typing 'monster:getHealth()' tells the engine to look for an entity with that ID anyway.
Then you want to call the getHealth() method on the monster, (monster:getHealth()) which returns a number. You can compare this number to the value 50 in the if statement (if value < 50 then). Every if then also requires an end somewhere to balance it out too. This tells lua when to return to code to always run regardless of the if branch.
Re: Question regarding Monster:getHealth()
Posted: Fri Jul 26, 2013 7:53 pm
by SeyProdumen
Thank you for your quick answer!
I'm not sure I got it right though. The player is supposed to beat a strong monster by inserting torches into torch holders. Once this is completed, the monster should be destroyed and a number of other things happen, such as a door opening.
However there is the chance that a player just chews through the monster's endless hitpoints, in which case the door would not open, et cetera.
What I'm trying to do now is make sure that the monster is destroyed once a certain amount of damage is dealt.
It could not make it work with the script you provided, but I'm fairly sure the mistake is on my side.
However I'm beginning to realize that the lack of XP at the end of the fight would make it very unrewarding anyway, and I should definitely look into hooks...

Re: Question regarding Monster:getHealth()
Posted: Fri Jul 26, 2013 9:55 pm
by Ryeath_Greystalk
SeyProdumen wrote:Thank you for your quick answer!
I'm not sure I got it right though. The player is supposed to beat a strong monster by inserting torches into torch holders. Once this is completed, the monster should be destroyed and a number of other things happen, such as a door opening.
However there is the chance that a player just chews through the monster's endless hitpoints, in which case the door would not open, et cetera.
What I'm trying to do now is make sure that the monster is destroyed once a certain amount of damage is dealt.
It could not make it work with the script you provided, but I'm fairly sure the mistake is on my side.
However I'm beginning to realize that the lack of XP at the end of the fight would make it very unrewarding anyway, and I should definitely look into hooks...

One option come to mind. Make the monster immune to damage by using an onDamage hook and return false. That way the player can beat on the monster all day long and it will not die. Then when the player places a torch in the holder you can reduce the monsters health through scripting, or quite possibly not even messing with the monsters health, just leave him at full health until the torches are complete and then destroy him.
If you want to make the torches damage the monster then you may need to differentiate between player caused damage and scripted torch damage in your onDamage hook, which I haven't looked into the possibility of that yet.
As for experience you can always just give the players experience when the torches are completed.
Re: Question regarding Monster:getHealth()
Posted: Fri Jul 26, 2013 10:33 pm
by msyblade
here is a simple Exp script for you
Code: Select all
function exp()
hudPrint ("Gained 250 exp.")
for i=1,4 do
party:getChampion(i):gainExp(250)
end
end
And to do ryaeth's solution, connect the torchholders to a counter set to how many torch's need placed total. you may want to set the torchholder to decrement the counter on activation (torch placed) and increment the counter on deactivation (torch removed) so the player cannot just place and remove one torch on all of the holders. Then the counter connects to the script entity and activates when it reaches 0. I can also give you a script that does not allow torches to be removed at all if you like

Hope this all helps, and please don't hesitate to keep us updated on your progress or ask questions if any problems arise

Re: Question regarding Monster:getHealth()
Posted: Sun Jul 28, 2013 10:16 pm
by bongobeat
msyblade wrote:here is a simple Exp script for you
Code: Select all
function exp()
hudPrint ("Gained 250 exp.")
for i=1,4 do
party:getChampion(i):gainExp(250)
end
end
And to do ryaeth's solution, connect the torchholders to a counter set to how many torch's need placed total. you may want to set the torchholder to decrement the counter on activation (torch placed) and increment the counter on deactivation (torch removed) so the player cannot just place and remove one torch on all of the holders. Then the counter connects to the script entity and activates when it reaches 0. I can also give you a script that does not allow torches to be removed at all if you like

Hope this all helps, and please don't hesitate to keep us updated on your progress or ask questions if any problems arise

Hi there,
I think this a nothing to do with this post, but as I ve see this exp script:
do you know a way with a script to get xp from killing any monster with a special weapon?
I ve created a custom weapon who spawn a custom spell, but it dont gives any xp when killing a monster with it.
Re: Question regarding Monster:getHealth()
Posted: Mon Aug 12, 2013 12:26 am
by SeyProdumen
Thank you for all your answers! I read them just now as I was on holiday in the past 2 weeks. I haven't decided yet on how I'll do the boss fight in the end, but I'll have some more questions for sure.
