• Get all entities caught in explosion.
    8 replies, posted
I have a grenade that will, of course, explode. How do I make it unweld all props caught in the explosion?
There are several ways to do this, the optimal one being making your own explosion code. You could also use an env_explosion to deal the damage and attach a certain flag to it, like UnWeld. Then in [b][url=wiki.garrysmod.com/?title=Gamemode.EntityTakeDamage]Gamemode.EntityTakeDamage [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] you could check for inflictor.UnWeld to determine an entity was hit by your special explosion.
If you're firing an explosion using lua I think the value you put in is actually a distance. You could fill a table with the entities in the map, for each entity do a bit of pythag to calculate distance. If distance < explosion radius = unweld. Could be inelegant, but I figure the game is already doing something like this to dish out damage.
[QUOTE=theholygod;21236932]Could be inelegant, but I figure the game is already doing something like this to dish out damage.[/QUOTE] That's exactly why I didn't suggest it. It would be wasteful to calculate the same thing twice. Plus it really wouldn't work on bigger entities. Using env_explosion with a tag on it may look hackier but is actually a ton simpler.
Good point on the distance (though i suppose you could get the dimensions of the bounding box), don't you still need to loop through everything to see if it took damage though?
[QUOTE=theholygod;21237076]Good point on the distance (though i suppose you could get the dimensions of the bounding box), don't you still need to loop through everything to see if it took damage though?[/QUOTE] Whenever an entity takes damage [b][url=wiki.garrysmod.com/?title=Gamemode.EntityTakeDamage]Gamemode.EntityTakeDamage [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] is automatically called with all the revelent arguments. So all that's left to do is checking if the damage was inflicted by an entity that has been flagged. Or you could also check if the attacker is a player currently wielding a weapon that unwelds while making sure he used that weapon to do the damage. Actually if you want to make it so that any explosion will unweld entities (not just a specific one) you can simply filter them by the damage type they took or the entity that inflicted it, again in [b][url=wiki.garrysmod.com/?title=Gamemode.EntityTakeDamage]Gamemode.EntityTakeDamage [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b].
Completely forgot about that function. I was thinking about the SENT takedamage function. Thanks!
Couldn't you use [b][url=http://wiki.garrysmod.com/?title=Ents.FindInSphere]Ents.FindInSphere [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] when the grenade explodes and unweld everything that it finds?
[QUOTE=sintwins;21251820]Couldn't you use [b][url=http://wiki.garrysmod.com/?title=Ents.FindInSphere]Ents.FindInSphere [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] when the grenade explodes and unweld everything that it finds?[/QUOTE] Yes you could and no you couldn't. You could use that but it would be doing extra calculations on top of the explosion damage calculations. And you can't do that because it only compares the result of GetPos() so an entity might be physically within the explosion but receive no damage (think something big like a container).
Sorry, you need to Log In to post a reply to this thread.