Skip to content

Commit 873658a

Browse files
committed
feat: Added UTIL_TraceLine and TraceLineEx
1 parent f712726 commit 873658a

3 files changed

Lines changed: 34 additions & 3 deletions

File tree

sdk.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,15 @@ int UTIL_GetCommandClientIndex()
155155
return GetCommandClientIndex_();
156156
}
157157

158+
//---------------------------------------------------------------------------------
159+
// Purpose: Get a trace between two points in space. Masks can be set to hit specific things
160+
//---------------------------------------------------------------------------------
161+
void UTIL_TraceLine(const Vector& vecAbsStart, const Vector& vecAbsEnd, const unsigned int mask, const IHandleEntity* ignore, const int collisionGroup, trace_t* ptr)
162+
{
163+
static auto UTIL_TraceLine_ = reinterpret_cast<void (__cdecl*)(const Vector&, const Vector&, unsigned int, const IHandleEntity*, int, trace_t*)>(Memory::Scanner::Scan(SERVERDLL, "53 8B DC 83 EC 08 83 E4 F0 83 C4 04 55 8B 6B ?? 89 6C 24 ?? 8B EC 83 EC 6C 56 8B 43"));
164+
UTIL_TraceLine_(vecAbsStart, vecAbsEnd, mask, ignore, collisionGroup, ptr);
165+
}
166+
158167
/// CBaseEntity Class Functions \\\
159168
160169
//---------------------------------------------------------------------------------

sdk.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ void UTIL_ClientPrint(CBasePlayer* player, int msg_dest, const char* msg_name, c
6060
void UTIL_HudMessage(CBasePlayer* pPlayer, const HudMessageParams& textparms, const char* pMessage);
6161
CBasePlayer* UTIL_GetCommandClient();
6262
int UTIL_GetCommandClientIndex();
63+
void UTIL_TraceLine(const Vector& vecAbsStart, const Vector& vecAbsEnd, unsigned int mask, const IHandleEntity* ignore, int collisionGroup, trace_t* ptr);
6364

6465
// CBaseEntity functions
6566
void CBaseEntity__RemoveEntity(CBaseEntity* pEntity);

vscript.cpp

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,26 @@ static void ShowScoreboard(const int playerIndex, const bool enable)
296296
CBasePlayer__ShowViewPortPanel(playerIndex, "scores", enable);
297297
}
298298

299+
/**
300+
* @brief Improved version of TraceLine for VScript that allows for checking with bit masks and collision groups.
301+
* @param vecAbsStart Location to start trace line.
302+
* @param vecAbsEnd Location where the trace line should end.
303+
* @param mask Bit mask used for determining what objects should be hit.
304+
* @param ignore A entity for the trace line to ignore, typically this is for a trace line originating from a entity.
305+
* @param collisionGroup Collision group that the trace line can hit.
306+
* @return
307+
*/
308+
static float Script_UTIL_TraceLine(const Vector& vecAbsStart, const Vector& vecAbsEnd, const int mask, const HSCRIPT ignore, const int collisionGroup)
309+
{
310+
trace_t trace;
311+
UTIL_TraceLine(vecAbsStart, vecAbsEnd, mask, static_cast<const IHandleEntity*>(HSCRIPTENT(ignore)), collisionGroup, &trace);
312+
313+
if (trace.fractionleftsolid >= 1.0 && trace.startsolid)
314+
return 1.0f - trace.fractionleftsolid;
315+
316+
return trace.fraction;
317+
}
318+
299319
{
300320
CBasePlayer__ShowViewPortPanel(playerIndex, "scores", bEnable);
301321
}
@@ -343,9 +363,10 @@ void RegisterFuncsAndRun()
343363
"Supports printing localization strings but those that require formatting can't be formatted."
344364
"Vectors are used to consolidate some parameters so function isn't monstrously big."
345365
);
346-
ScriptRegisterFunction (g_pScriptVM, GetMaxPlayers, "Self-explanatory.");
347-
ScriptRegisterFunction (g_pScriptVM, ShowScoreboard, "Enable or disable displaying the score board for players.");
348-
ScriptRegisterFunction (g_pScriptVM, RemovePlayerUI, "Display UI for either banning or kicking so host can ban or kick a player.");
366+
ScriptRegisterFunction (g_pScriptVM, GetMaxPlayers, "Returns the current max players in the server.");
367+
ScriptRegisterFunction (g_pScriptVM, ShowScoreboard, "Enable or disable displaying the score board for players.");
368+
ScriptRegisterFunction (g_pScriptVM, RemovePlayerUI, "Display UI for either banning or kicking so host can ban or kick a player.");
369+
ScriptRegisterFunctionNamed(g_pScriptVM, Script_UTIL_TraceLine, "TraceLineEx", "Improved version of TraceLine that allows for checking with bit masks and collision groups.");
349370

350371
// Load up the main P2:MM VScript.
351372
g_pScriptVM->Run("IncludeScript(\"multiplayermod/p2mm\");");

0 commit comments

Comments
 (0)