Page 1 of 1
hegrenade detonate
Posted: Tue Aug 07, 2018 6:43 pm
by Kami
Hey guys,
I'm trying to use detonate() on a projectile_hegrenade entity in CS:GO with this code.
Syntax: Select all
@EntityPostHook(EntityCondition.equals_entity_classname("hegrenade_projectile"), 'start_touch')
def Entity_StartTouch(args, ret):
entity = make_object(Entity, args[1])
touching = make_object(Entity, args[0])
if touching.classname == "worldspawn":
if entity.get_key_value_string('targetname') == "cluster":
entity.detonate()
I get the following error:
Code: Select all
[SP] Caught an Exception:
Traceback (most recent call last):
File "..\addons\source-python\plugins\es_emulator\eventscripts\wcs\tools\ultimates\default2\default2.py", line 80, in Entity_StartTouch
entity.detonate()
File "..\addons\source-python\packages\source-python\memory\helpers.py", line 331, in __call__
return super().__call__(self._this, *args)
File "<string>", line 1, in <lambda>
RuntimeError: Access violation while writing address '1'.
-
Re: hegrenade detonate
Posted: Tue Aug 07, 2018 7:58 pm
by VinciT
I'm guessing the offset for
detonate() is outdated. I'd update it but I have no idea how to get CS:GO offsets.
However, I think this might help you:
Syntax: Select all
@EntityPostHook(EntityCondition.equals_entity_classname("hegrenade_projectile"), 'start_touch')
def Entity_StartTouch(args, ret):
entity = make_object(Entity, args[1])
touching = make_object(Entity, args[0])
if touching.classname == "worldspawn":
if entity.get_key_value_string('targetname') == "cluster":
detonate(entity)
def detonate(grenade):
# Make sure the grenade can actually take damage.
grenade.set_property_uchar('m_takedamage', 2)
grenade.health = 1
grenade.take_damage(1)
Re: hegrenade detonate
Posted: Tue Aug 07, 2018 7:59 pm
by satoon101
Would the
grenade_bounce event work for what you are trying to do? You can get the exact grenade by using the x, y, and z coordinates in the event.
Re: hegrenade detonate
Posted: Tue Aug 07, 2018 8:11 pm
by VinciT
I'm assuming Kami wants the grenade to detonate only if it hits the world.
Syntax: Select all
..
if touching.classname == "worldspawn":
..
Doesn't grenade_bounce get called when it touches other entities (players, props) as well?
Re: hegrenade detonate
Posted: Tue Aug 07, 2018 8:22 pm
by Kami
Thank you very much vincit I will give that a try.
I think the Problem with grenade_bounce was that it does not give you a way to identify the nade (Index for example)
Re: hegrenade detonate
Posted: Tue Aug 07, 2018 9:33 pm
by satoon101
Kami wrote:I think the Problem with grenade_bounce was that it does not give you a way to identify the nade (Index for example)
Yeah, you have to loop through all grenades and see which one is at the origin for the x, y, and z coordinates from the event.
Syntax: Select all
# Untested
@Event('grenade_bounce')
def _grenade_bounce(game_event):
coords = Vector(*[game_event[x] for x in 'xyz'])
for entity in EntityIter('hegrenade_projectile'):
if entity.origin == coords:
break
# if 'break' is never encountered, there was no such hegrenade
# for instance, it could have been a flashbang that bounced
else:
return
entity.detonate()
I only mention using the event because using the 'touch' hooks can come with a multitude of other issues. Not that this situation is encountering that, but just as a general rule I personally shy away from using them when there are other options.
Re: hegrenade detonate
Posted: Wed Aug 08, 2018 9:03 am
by Kami
Thank you both for your help!
This is what I am using now and it works pretty well
Syntax: Select all
@Event('grenade_bounce')
def _grenade_bounce(game_event):
coords = Vector(*[game_event[x] for x in 'xyz'])
for entity in EntityIter('hegrenade_projectile'):
if entity.origin == coords:
if entity.get_key_value_string('targetname') == "cluster":
detonate(entity)
break
else:
return
def detonate(grenade):
grenade.set_property_uchar('m_takedamage', 2)
grenade.health = 1
grenade.take_damage(1)
Re: hegrenade detonate
Posted: Thu Aug 09, 2018 3:48 am
by satoon101
One other quick note, if you just add the detonate directly in the 'if' clause, you can just change the 'break' to 'return' and remove the 'else' entirely.
Syntax: Select all
@Event('grenade_bounce')
def _grenade_bounce(game_event):
coords = Vector(*[game_event[x] for x in 'xyz'])
for entity in EntityIter('hegrenade_projectile'):
if entity.origin == coords:
if entity.get_key_value_string('targetname') == "cluster":
detonate(entity)
return
def detonate(grenade):
grenade.set_property_uchar('m_takedamage', 2)
grenade.health = 1
grenade.take_damage(1)
We'll have to update the CS:GO offsets at some point so that entity.detonate() will work correctly.