Forum

> > CS2D > Scripts > Return breakable entity Health
Forums overviewCS2D overview Scripts overviewLog in to reply

English Return breakable entity Health

5 replies
To the start Previous 1 Next To the start

old Return breakable entity Health

Promaster
User Off Offline

Quote
I wonder if there is any hook which returns breakable entitys health when a player are attacking a breakable entity?

If there is no addhook for that, can anyone develope a function for me that can returns breakable entity health when a player are attacking the entity?
edited 1×, last 12.12.17 05:11:34 pm

old Re: Return breakable entity Health

VaiN
User Off Offline

Quote
This should help you get started.

You can check if an entity is a breakable using
1
entity(x,y,"typename") == "Env_Breakable"
You can get the health of a breakable using
1
entity(x,y,"int1")
example:
1
2
3
4
local list = entitylist()
for _,e in pairs(list) do
  print("entity @ ("..e.x..","..e.y..") - "..entity(e.x,e.y,"typename") .. " = " .. entity(e.x,e.y,"int1"))
end

So what you want to do is loop through all entities using cs2d lua cmd entitylist and add the known breakable entities to a table with their x/y coordinates, and their health value. Then in the cs2d lua hook attack hook, interate through each one and check if the health value has changed.

old Re: Return breakable entity Health

Promaster
User Off Offline

Quote
@user VaiN: Thank you for you took your time to write the code Vain. But i have though about that i can make a list and name them after their health value. But my biggest problem is to identify the damage a players dealt to the entity.

old Re: Return breakable entity Health

Rainoth
Moderator Off Offline

Quote
Then after VaiN's "health value has changed", all you need to do is either get how much it has changed (you had health at 100 and now it's at 75, so the difference is 25) or you can check if any breakables were hit and then get the damage dealt through itemtype(player(id,"weapontype),"dmg")

The first method is of course way easier.
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview