hegrenade detonate

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
Kami
Global Moderator
Posts: 143
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

hegrenade detonate

Postby Kami » Tue Aug 07, 2018 6:43 pm

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'.
-
User avatar
VinciT
Member
Posts: 99
Joined: Thu Dec 18, 2014 2:41 am

Re: hegrenade detonate

Postby VinciT » Tue Aug 07, 2018 7:58 pm

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)
User avatar
satoon101
Project Leader
Posts: 2576
Joined: Sat Jul 07, 2012 1:59 am

Re: hegrenade detonate

Postby satoon101 » Tue Aug 07, 2018 7:59 pm

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.
Image
User avatar
VinciT
Member
Posts: 99
Joined: Thu Dec 18, 2014 2:41 am

Re: hegrenade detonate

Postby VinciT » Tue Aug 07, 2018 8:11 pm

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?
User avatar
Kami
Global Moderator
Posts: 143
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Re: hegrenade detonate

Postby Kami » Tue Aug 07, 2018 8:22 pm

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)
User avatar
satoon101
Project Leader
Posts: 2576
Joined: Sat Jul 07, 2012 1:59 am

Re: hegrenade detonate

Postby satoon101 » Tue Aug 07, 2018 9:33 pm

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.
Image
User avatar
Kami
Global Moderator
Posts: 143
Joined: Wed Aug 15, 2012 1:24 am
Location: Germany

Re: hegrenade detonate

Postby Kami » Wed Aug 08, 2018 9:03 am

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)
User avatar
satoon101
Project Leader
Posts: 2576
Joined: Sat Jul 07, 2012 1:59 am

Re: hegrenade detonate

Postby satoon101 » Thu Aug 09, 2018 3:48 am

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.
Image

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 9 guests