mirror of
https://github.com/shavitush/bhoptimer.git
synced 2025-12-07 10:28:26 +00:00
Implemented Shavit_OnUserCmdPre. (#425)
This commit is contained in:
parent
315de440b8
commit
f944b3d936
@ -269,6 +269,23 @@ stock void FormatSeconds(float time, char[] newtime, int newtimesize, bool preci
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called before shavit-core processes the client's usercmd.
|
||||
* Before this is called, safety checks (fake/dead clients) happen.
|
||||
* Use this forward in modules that use OnPlayerRunCmd to avoid errors and unintended behavior.
|
||||
* If a module conflicts with buttons/velocity/angles being changed in shavit-core, this forward is recommended.
|
||||
* This forward will NOT be called if a player's timer is paused.
|
||||
*
|
||||
* @param client Client index.
|
||||
* @param buttons Buttons sent in the usercmd.
|
||||
* @param impulse Impulse sent in the usercmd.
|
||||
* @param vel A vector that contain's the player's desired movement. vel[0] is forwardmove, vel[1] is sidemove.
|
||||
* @param angles The player's requested viewangles. They will not necessarily be applied as SRCDS itself won't accept every value.
|
||||
* @param status The player's timer status.
|
||||
* @return Plugin_Continue to let shavit-core keep doing what it does, Plugin_Changed to pass different values.
|
||||
*/
|
||||
forward Action Shavit_OnUserCmdPre(int client, int &buttons, int &impulse, float vel[3], float angles[3], TimerStatus status);
|
||||
|
||||
/**
|
||||
* Called when a player's timer starts.
|
||||
* (WARNING: Will be called every tick when the player stands at the start zone!)
|
||||
|
||||
@ -57,6 +57,7 @@ Handle gH_Forwards_OnStyleChanged = null;
|
||||
Handle gH_Forwards_OnStyleConfigLoaded = null;
|
||||
Handle gH_Forwards_OnDatabaseLoaded = null;
|
||||
Handle gH_Forwards_OnChatConfigLoaded = null;
|
||||
Handle gH_Forwards_OnUserCmdPre = null;
|
||||
|
||||
// timer variables
|
||||
bool gB_TimerEnabled[MAXPLAYERS+1];
|
||||
@ -194,6 +195,7 @@ public void OnPluginStart()
|
||||
gH_Forwards_OnStyleConfigLoaded = CreateGlobalForward("Shavit_OnStyleConfigLoaded", ET_Event, Param_Cell);
|
||||
gH_Forwards_OnDatabaseLoaded = CreateGlobalForward("Shavit_OnDatabaseLoaded", ET_Event, Param_Cell);
|
||||
gH_Forwards_OnChatConfigLoaded = CreateGlobalForward("Shavit_OnChatConfigLoaded", ET_Event);
|
||||
gH_Forwards_OnUserCmdPre = CreateGlobalForward("Shavit_OnUserCmdPre", ET_Event, Param_Cell, Param_CellByRef, Param_CellByRef, Param_Array, Param_Array, Param_Cell);
|
||||
|
||||
LoadTranslations("shavit-core.phrases");
|
||||
|
||||
@ -840,19 +842,7 @@ public int Native_GetBhopStyle(Handle handler, int numParams)
|
||||
|
||||
public int Native_GetTimerStatus(Handle handler, int numParams)
|
||||
{
|
||||
int client = GetNativeCell(1);
|
||||
|
||||
if(!gB_TimerEnabled[client])
|
||||
{
|
||||
return view_as<int>(Timer_Stopped);
|
||||
}
|
||||
|
||||
else if(gB_ClientPaused[client])
|
||||
{
|
||||
return view_as<int>(Timer_Paused);
|
||||
}
|
||||
|
||||
return view_as<int>(Timer_Running);
|
||||
return GetTimerStatus(GetNativeCell(1));
|
||||
}
|
||||
|
||||
public int Native_StartTimer(Handle handler, int numParams)
|
||||
@ -1069,6 +1059,21 @@ public int Native_LoadSnapshot(Handle handler, int numParams)
|
||||
gI_SHSW_FirstCombination[client] = view_as<int>(snapshot[iSHSWCombination]);
|
||||
}
|
||||
|
||||
int GetTimerStatus(int client)
|
||||
{
|
||||
if(!gB_TimerEnabled[client])
|
||||
{
|
||||
return view_as<int>(Timer_Stopped);
|
||||
}
|
||||
|
||||
else if(gB_ClientPaused[client])
|
||||
{
|
||||
return view_as<int>(Timer_Paused);
|
||||
}
|
||||
|
||||
return view_as<int>(Timer_Running);
|
||||
}
|
||||
|
||||
void StartTimer(int client)
|
||||
{
|
||||
if(!IsValidClient(client, true) || GetClientTeam(client) < 2 || IsFakeClient(client))
|
||||
@ -1589,6 +1594,21 @@ public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3
|
||||
return Plugin_Changed;
|
||||
}
|
||||
|
||||
Action result = Plugin_Continue;
|
||||
Call_StartForward(gH_Forwards_OnUserCmdPre);
|
||||
Call_PushCell(client);
|
||||
Call_PushCellRef(buttons);
|
||||
Call_PushCellRef(impulse);
|
||||
Call_PushArrayEx(vel, 3, SM_PARAM_COPYBACK);
|
||||
Call_PushArrayEx(angles, 3, SM_PARAM_COPYBACK);
|
||||
Call_PushCell(GetTimerStatus(client));
|
||||
Call_Finish(result);
|
||||
|
||||
if(result != Plugin_Continue && result != Plugin_Changed)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
int iGroundEntity = GetEntPropEnt(client, Prop_Send, "m_hGroundEntity");
|
||||
bool bInStart = Shavit_InsideZone(client, Zone_Start, Track_Main);
|
||||
|
||||
|
||||
@ -784,13 +784,8 @@ void RemoveRagdoll(int client)
|
||||
}
|
||||
}
|
||||
|
||||
public Action OnPlayerRunCmd(int client, int &buttons)
|
||||
public Action Shavit_OnUserCmdPre(int client, int &buttons, int &impulse, float vel[3], float angles[3], TimerStatus status)
|
||||
{
|
||||
if(!IsPlayerAlive(client) || IsFakeClient(client))
|
||||
{
|
||||
return Plugin_Continue;
|
||||
}
|
||||
|
||||
int iGroundEntity = GetEntPropEnt(client, Prop_Send, "m_hGroundEntity");
|
||||
|
||||
// prespeed
|
||||
|
||||
@ -896,6 +896,7 @@ public void Shavit_OnResume(int client)
|
||||
gB_Record[client] = true;
|
||||
}
|
||||
|
||||
// OnPlayerRunCmd instead of Shavit_OnUserCmdPre because bots are also used here.
|
||||
public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3], float angles[3])
|
||||
{
|
||||
if(!gB_Enabled)
|
||||
|
||||
@ -1337,7 +1337,7 @@ bool AreVectorsEqual(float vec1[3], float vec2[3])
|
||||
return (vec1[0] == vec2[0] && vec1[1] == vec2[1] && vec1[2] == vec2[2]);
|
||||
}
|
||||
|
||||
public Action OnPlayerRunCmd(int client, int &buttons)
|
||||
public Action Shavit_OnUserCmdPre(int client, int &buttons, int &impulse, float vel[3], float angles[3], TimerStatus status)
|
||||
{
|
||||
if(!IsPlayerAlive(client) || IsFakeClient(client))
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user