Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TR_GetHitBoxIndex() native #1085

Merged
merged 3 commits into from Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions extensions/sdktools/trnatives.cpp
Expand Up @@ -998,6 +998,22 @@ static cell_t smn_TRGetHitGroup(IPluginContext *pContext, const cell_t *params)
return tr->hitgroup;
}

static cell_t smn_TRGetHitBoxIndex(IPluginContext *pContext, const cell_t *params)
{
sm_trace_t *tr;
HandleError err;
HandleSecurity sec(pContext->GetIdentity(), myself->GetIdentity());

if (params[1] == BAD_HANDLE)
{
tr = &g_Trace;
} else if ((err = handlesys->ReadHandle(params[1], g_TraceHandle, &sec, (void **)&tr)) != HandleError_None) {
return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[1], err);
}

return tr->hitbox;
}

static cell_t smn_TRGetEntityIndex(IPluginContext *pContext, const cell_t *params)
{
sm_trace_t *tr;
Expand Down Expand Up @@ -1102,6 +1118,7 @@ sp_nativeinfo_t g_TRNatives[] =
{"TR_StartSolid", smn_TRStartSolid},
{"TR_DidHit", smn_TRDidHit},
{"TR_GetHitGroup", smn_TRGetHitGroup},
{"TR_GetHitBoxIndex", smn_TRGetHitBoxIndex},
{"TR_ClipRayToEntity", smn_TRClipRayToEntity},
{"TR_ClipRayToEntityEx", smn_TRClipRayToEntityEx},
{"TR_ClipRayHullToEntity", smn_TRClipRayHullToEntity},
Expand Down
12 changes: 12 additions & 0 deletions plugins/include/sdktools_trace.inc
Expand Up @@ -633,6 +633,18 @@ native bool TR_DidHit(Handle hndl=INVALID_HANDLE);
*/
native int TR_GetHitGroup(Handle hndl=INVALID_HANDLE);

/**
* Returns in which hitbox the trace collided if any.
*
* Note: if the entity that collided with the trace is the world entity,
* then this function doesn't return an hitbox index but a static prop index.
*
* @param hndl A trace Handle, or INVALID_HANDLE to use a global trace result.
* @return Hitbox index (Or static prop index).
* @error Invalid Handle.
*/
native int TR_GetHitBoxIndex(Handle hndl=INVALID_HANDLE);

/**
* Find the normal vector to the collision plane of a trace.
*
Expand Down