trace attack
trace attack
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.
- L'In20Cible
- Project Leader
- Posts: 1536
- Joined: Sat Jul 14, 2012 9:29 pm
- Location: Québec
Re: Detect knife attack
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):
...
Re: Detect knife attack
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.
Re: Detect knife attack
That's because the second argument isn't a player:
Syntax: Select all
# this, CTakeDamageInfo, Vector, trace_t, CDmgAccumulator
Re: Detect knife attack
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
// 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
Re: Detect knife attack
untested:
* Edit: references for TakeDamageInfo:
http://wiki.sourcepython.com/developing ... DamageInfo
https://github.com/Source-Python-Dev-Te ... h#L84-L160
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
Return to “Plugin Development Support”
Who is online
Users browsing this forum: Bing [Bot] and 43 guests