trace attack

Please post any questions about developing your plugin here. Please use the search function before posting!
User avatar
velocity
Senior Member
Posts: 220
Joined: Sat May 10, 2014 6:17 pm

trace attack

Postby velocity » Thu Oct 14, 2021 8:22 am

Hi! I was wondering if it is possible to detect a knife attack if it is a teammate and has godmode. I tried hooking "on_take_damage", but it doesn't fire. I have been looking at trace_attack, but it doesn't exist in the .ini data files. Any ideas? This is for css/csgo
Last edited by velocity on Thu Nov 25, 2021 11:45 am, edited 1 time in total.
User avatar
L'In20Cible
Project Leader
Posts: 1533
Joined: Sat Jul 14, 2012 9:29 pm
Location: Québec

Re: Detect knife attack

Postby L'In20Cible » Thu Oct 14, 2021 4:30 pm

Syntax: Select all

from entities.hooks import EntityCondition
from entities.hooks import EntityPreHook
from core import PLATFORM
from core import SOURCE_ENGINE

def get_trace_attack_function(entity):
offset = {
'orangebox': {'windows': 60, 'linux': 61},
'csgo': {'windows': 66, 'linux': 67}
}[SOURCE_ENGINE][PLATFORM]
return entity.pointer.make_virtual_function(
offset,
Convention.THISCALL,
# this, CTakeDamageInfo, Vector, trace_t, CDmgAccumulator
(DataType.POINTER, DataType.POINTER, DataType.POINTER,
DataType.POINTER, DataType.POINTER),
DataType.VOID
)

@EntityPreHook(EntityCondition.is_player, get_trace_attack_function)
def pre_trace_attack(stack_data):
...
User avatar
velocity
Senior Member
Posts: 220
Joined: Sat May 10, 2014 6:17 pm

Re: Detect knife attack

Postby velocity » Thu Oct 14, 2021 8:24 pm

Works! I have a problem with stack_data[1]


Code: Select all

@EntityPreHook(EntityCondition.is_player, get_trace_attack_function)
def pre_trace_attack(stack_data):
    victim = make_object(Player, stack_data[0])
    attacker = make_object(Player, stack_data[1])


Traceback (most recent call last):
File "../addons/source-python/plugins/tr/boost.py", line 711, in pre_trace_attack
attacker = make_object(Entity, stack_data[1])
File "../addons/source-python/packages/source-python/entities/_base.py", line 324, in _obj
return cls(index_from_pointer(ptr))

ValueError: Conversion from "Pointer" (<_memory.Pointer object at 0xe8ac8890>) to "Index" failed.
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Detect knife attack

Postby satoon101 » Thu Oct 14, 2021 8:40 pm

That's because the second argument isn't a player:

Syntax: Select all

# this, CTakeDamageInfo, Vector, trace_t, CDmgAccumulator
Image
User avatar
velocity
Senior Member
Posts: 220
Joined: Sat May 10, 2014 6:17 pm

Re: Detect knife attack

Postby velocity » Thu Oct 14, 2021 8:48 pm

oh I see, I thought it followed this, just like in sourcemod:

// TraceAttack
function Action (int victim, int &attacker, int &inflictor, float &damage, int &damagetype, int &ammotype, int hitbox, int hitgroup);


Well they seems a little cryptic to me? How would I get the attacker from that
User avatar
satoon101
Project Leader
Posts: 2697
Joined: Sat Jul 07, 2012 1:59 am

Re: Detect knife attack

Postby satoon101 » Thu Oct 14, 2021 8:57 pm

untested:

Syntax: Select all

from entities import TakeDamageInfo
from entities.hooks import EntityCondition
from entities.hooks import EntityPreHook
from memory import make_object


@EntityPreHook(EntityCondition.is_player, get_trace_attack_function)
def pre_trace_attack(stack_data):
victim = make_object(Player, stack_data[0])
take_damage_info = make_object(TakeDamageInfo, stack_data[1])

# player index of the player attacking
attacker_index = take_damage_info.attacker

# either the player index of the attacker or the index of the weapon if a projectile
# inflictor and attacker will be different if a projectile was used, but same if any gun/knife
inflictor = take_damage_info.inflictor

# index of the weapon that was used
# handles differentiating between attacker and inflictor automatically
# will be the attacking player's active weapon if a gun/knife was used
weapon = take_damage_info.weapon


* Edit: references for TakeDamageInfo:
http://wiki.sourcepython.com/developing ... DamageInfo

https://github.com/Source-Python-Dev-Te ... h#L84-L160
Image
User avatar
velocity
Senior Member
Posts: 220
Joined: Sat May 10, 2014 6:17 pm

Re: Detect knife attack

Postby velocity » Thu Oct 14, 2021 8:58 pm

yep! just arrived at the same: http://wiki.sourcepython.com/developing ... DamageInfo

thanks, works!

Return to “Plugin Development Support”

Who is online

Users browsing this forum: No registered users and 19 guests