PreHook: player_hurt

Please post any questions about developing your plugin here. Please use the search function before posting!
MrMalina
Member
Posts: 53
Joined: Mon Apr 08, 2013 2:40 pm
Location: Russian Federation

PreHook: player_hurt

Postby MrMalina » Sat Mar 07, 2015 3:40 pm

I needed to get event pre player_hurt.

From the examples on the site I was able to make it up:

Syntax: Select all

# =============================================================================
# >> IMPORTS
# =============================================================================
import memory

from memory import find_binary
from memory import make_object
from memory import Convention
from memory import DataType
from memory.hooks import PreHook
from basetypes import TakeDamageInfo
from core import PLATFORM

# =============================================================================
# >> CONSTANTS
# =============================================================================
if PLATFORM == 'windows':
ON_TAKE_DAMAGE_IDENTIFIER = b'\x55\x8B\xEC\x81\xEC\x44\x01\x2A\x2A\x56' \
b'\x89\x4D\xFC'
else:
ON_TAKE_DAMAGE_IDENTIFIER = '_ZN20CBaseCombatCharacter12OnTakeDamageERK15CTakeDamageInfo'

# =============================================================================
# >> GLOBAL VARIABLES
# =============================================================================
server = find_binary('cstrike/bin/server')
OnTakeDamage = server[ON_TAKE_DAMAGE_IDENTIFIER].make_function(Convention.THISCALL, (DataType.POINTER, DataType.POINTER), DataType.VOID)

# =============================================================================
# >> CALLBACK
# =============================================================================
@PreHook(OnTakeDamage)
def pre_on_take_damage(args):

info = make_object(TakeDamageInfo, args[0])

print(info.inflictor)
print(info.attacker)
print(info.weapon)


When you deal damage I get to the console: 2 0 0

If I replace args [0] to args [1] I get an error:
The attachment 1.jpg is no longer available


What am I doing wrong?

SP (build on March 2). Platform: Windows
Attachments
1.jpg
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Postby L'In20Cible » Sat Mar 07, 2015 8:23 pm

MrMalina wrote:When you deal damage I get to the console: 2 0 0
Unexpected values are normal if you are using args[0] since this is the this pointer (the CBaseCombatCharacter pointer).


MrMalina wrote:If I replace args [0] to args [1] I get an error:
Using the exact same code and replacing args[0] to args[1] works just fine for me.
User avatar
Ayuto
Project Leader
Posts: 2195
Joined: Sat Jul 07, 2012 8:17 am
Location: Germany

Postby Ayuto » Sat Mar 07, 2015 9:30 pm

Yeah, works fine for me, too. But it would be nice if you could just copy the error and post it here instead of making screenshots.

Return to “Plugin Development Support”

Who is online

Users browsing this forum: Bing [Bot] and 132 guests