Skip to content

Commit e02e6bc

Browse files
einyuxasherkin
authored andcommitted
Add TR_GetHitBoxIndex() native (#1085)
Fixes #1080
1 parent c7392ae commit e02e6bc

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

extensions/sdktools/trnatives.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,22 @@ static cell_t smn_TRGetHitGroup(IPluginContext *pContext, const cell_t *params)
998998
return tr->hitgroup;
999999
}
10001000

1001+
static cell_t smn_TRGetHitBoxIndex(IPluginContext *pContext, const cell_t *params)
1002+
{
1003+
sm_trace_t *tr;
1004+
HandleError err;
1005+
HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());
1006+
1007+
if (params[1] == BAD_HANDLE)
1008+
{
1009+
tr = &g_Trace;
1010+
} else if ((err = handlesys->ReadHandle(params[1], g_TraceHandle, &sec, (void **)&tr)) != HandleError_None) {
1011+
return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err);
1012+
}
1013+
1014+
return tr->hitbox;
1015+
}
1016+
10011017
static cell_t smn_TRGetEntityIndex(IPluginContext *pContext, const cell_t *params)
10021018
{
10031019
sm_trace_t *tr;
@@ -1102,6 +1118,7 @@ sp_nativeinfo_t g_TRNatives[] =
11021118
{"TR_StartSolid", smn_TRStartSolid},
11031119
{"TR_DidHit", smn_TRDidHit},
11041120
{"TR_GetHitGroup", smn_TRGetHitGroup},
1121+
{"TR_GetHitBoxIndex", smn_TRGetHitBoxIndex},
11051122
{"TR_ClipRayToEntity", smn_TRClipRayToEntity},
11061123
{"TR_ClipRayToEntityEx", smn_TRClipRayToEntityEx},
11071124
{"TR_ClipRayHullToEntity", smn_TRClipRayHullToEntity},

plugins/include/sdktools_trace.inc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,18 @@ native bool TR_DidHit(Handle hndl=INVALID_HANDLE);
633633
*/
634634
native int TR_GetHitGroup(Handle hndl=INVALID_HANDLE);
635635

636+
/**
637+
* Returns in which hitbox the trace collided if any.
638+
*
639+
* Note: if the entity that collided with the trace is the world entity,
640+
* then this function doesn't return an hitbox index but a static prop index.
641+
*
642+
* @param hndl A trace Handle, or INVALID_HANDLE to use a global trace result.
643+
* @return Hitbox index (Or static prop index).
644+
* @error Invalid Handle.
645+
*/
646+
native int TR_GetHitBoxIndex(Handle hndl=INVALID_HANDLE);
647+
636648
/**
637649
* Find the normal vector to the collision plane of a trace.
638650
*

0 commit comments

Comments
 (0)