Jump to content

Recommended Posts

Hello, I have a question :). So, my question is would it be possible to get the value of damage my character took on the attacked event? Because there's stuff I want to do for my character depending on the amount of damage she took, if she took less than 25 damage, more than 50 damage, more than 100 damage ect. would that be possible :)? If someones knows if that's possible & tells me that would be totally awesome!!

Thanks so much for reading my question, have a great day/night :D!!!

 

Edited by SuperDavid

ListenForEvent("healthdelta",function(inst,data) if data.amount>xy then ...end; end))

 

edit:
just search all lua files for such events. It is really no magic ;) You can also search for "Event(" to find all possible events and look if there is one that might be intersting for you.
And then you will most like also find the PushEvent variant of it, were you can see what can be used.

In this case:
 

self.inst:PushEvent("healthdelta", { oldpercent = old_percent, newpercent = self:GetPercent(), overtime = overtime, cause = cause, afflicter = afflicter, amount = amount })

so you can check the cause if you want to.

Edited by Serpens
9 hours ago, Serpens said:

self.inst:PushEvent("healthdelta", { oldpercent = old_percent, newpercent = self:GetPercent(), overtime = overtime, cause = cause, afflicter = afflicter, amount = amount })

This would check how much damage I take from entities, right :)? Though how would I use this? I don't understand what to do with this code :(..

but thanks for your help Serpens :D!!!

Edited by SuperDavid
4 hours ago, SuperDavid said:

This would check how much damage I take from entities, right :)? Though how would I use this? I don't understand what to do with this code :(..

but thanks for your help Serpens :D!!!

?! You use it like every other event.
Not the code you quoted. Of course you use ListenForEvent I wrote above.  The PushEvent is only mentioned so you can see what is included in "data".

Edited by Serpens
1 hour ago, Serpens said:

you use ListenForEvent I wrote above

Okay, i'm really confused..

I did this

inst:ListenForEvent("healthdelta", function(inst, data)
if data.amount > 1 then
inst.components.health:DoDelta(20)
end
end)

and got this crash when I ate a bonestew" :495: stack overflow " also, the code never triggered when I got attacked.

 

Also, isn't event "healthdelta" just a event that monitors the player's health level? I don't want at like my character is below 200 health something happens. What I want to try to do is for example if my character is hurt by a attack & that attack dealed more than 100 damage I want to make stuff happen regardless of how much health my character has left!

@SuperDavid, you basically wrote the following:

  1. Event Trigger: healthdelta
  2. if data.amount is greater than 1 then
  3. Call health:DoDelta(20)
  4. Go to Step 1

Calling components.helath:DoDelta(20) triggers the healthdelta event which called components.health:DoDelta(20) which triggers the healthdelta event....

 

Edit:

You should probably look into this event if you're wanting to get damage when a player is attacked:

self.inst:PushEvent("attacked", { attacker = attacker, damage = damage, weapon = weapon, stimuli = stimuli, redirected=damageredirecttarget })
Edited by Kzisor
10 minutes ago, Kzisor said:

Calling components.helath:DoDelta(20) triggers the healthdelta event which called components.health:DoDelta(20) which triggers the healthdelta event....

What have I d-done :shock:?!

Haha, but I also did put something like

inst:ListenForEvent("healthdelta", function(inst, data)
if data.amount > 1 then
inst.components.talker:Say("Wow, that totally hurt!")
end
end)

and nothing happened, so even without that crash the event still does nothing :(...

1 minute ago, SuperDavid said:

What have I d-done :shock:?!

Haha, but I also did put something like


inst:ListenForEvent("healthdelta", function(inst, data)
if data.amount > 1 then
inst.components.talker:Say("Wow, that totally hurt!")
end
end)

and nothing happened, so even without that crash the event still does nothing :(...

*points to previous edit*

2 minutes ago, SuperDavid said:

@Kzisor So, I would do something like this, yes :)?


inst:ListenForEvent("attacked", function(inst, data)
if data.damage > 1 then
inst.components.sanity:DoDelta(10)
end
end)

 

Test it and find out, but you might also want to test for negative values as well.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...