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

Use client tick count for trigger touch time calculation #365

Merged
merged 1 commit into from
Oct 6, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions addons/sourcemod/scripting/gokz-core.sp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Handle gH_DHooks_OnTeleport;
Handle gH_DHooks_SetModel;

int gI_CmdNum[MAXPLAYERS + 1];
int gI_TickCount[MAXPLAYERS + 1];
bool gB_OldOnGround[MAXPLAYERS + 1];
int gI_OldButtons[MAXPLAYERS + 1];
int gI_TeleportCmdNum[MAXPLAYERS + 1];
Expand Down Expand Up @@ -178,6 +179,7 @@ public void OnClientDisconnect(int client)
public Action OnPlayerRunCmd(int client, int &buttons, int &impulse, float vel[3], float angles[3], int &weapon, int &subtype, int &cmdnum, int &tickcount, int &seed, int mouse[2])
{
gI_CmdNum[client] = cmdnum;
gI_TickCount[client] = tickcount;
OnPlayerRunCmd_MapTriggers(client, buttons);
OnPlayerRunCmd_Turnbinds(client, buttons, tickcount, angles);
return Plugin_Continue;
Expand Down
24 changes: 12 additions & 12 deletions addons/sourcemod/scripting/gokz-core/map/triggers.sp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ void OnPlayerRunCmd_MapTriggers(int client, int &buttons)

if (touched.triggerType == TriggerType_Antibhop)
{
TouchAntibhopTrigger(touched, buttons, flags);
TouchAntibhopTrigger(client, touched, buttons, flags);
}
else if (touched.triggerType == TriggerType_Teleport)
{
Expand Down Expand Up @@ -523,7 +523,7 @@ void OnStartTouchGround_MapTriggers(int client)
TouchedTrigger touched;
triggerTouchList[client].GetArray(i, touched);
// set the touched tick to the tick that the player touches the ground.
touched.groundTouchTick = GetGameTickCount();
touched.groundTouchTick = gI_TickCount[client];
triggerTouchList[client].SetArray(i, touched);
}
}
Expand Down Expand Up @@ -579,11 +579,11 @@ static void AddTriggerToTouchList(int client, int trigger, TriggerType triggerTy
TouchedTrigger touched;
touched.triggerType = triggerType;
touched.entRef = triggerEntRef;
touched.startTouchTick = GetGameTickCount();
touched.startTouchTick = gI_TickCount[client];
touched.groundTouchTick = -1;
if (GetEntityFlags(client) & FL_ONGROUND)
{
touched.groundTouchTick = GetGameTickCount();
touched.groundTouchTick = gI_TickCount[client];
}

triggerTouchList[client].PushArray(touched);
Expand Down Expand Up @@ -632,7 +632,7 @@ static void DecrementTriggerTouchCount(int client, int trigger)
triggerTouchCounts[client].SetValue(szEntref, value);
}

static void TouchAntibhopTrigger(TouchedTrigger touched, int &newButtons, int flags)
static void TouchAntibhopTrigger(int client, TouchedTrigger touched, int &newButtons, int flags)
{
if (!(flags & FL_ONGROUND))
{
Expand All @@ -653,7 +653,7 @@ static void TouchAntibhopTrigger(TouchedTrigger touched, int &newButtons, int fl
AntiBhopTrigger trigger;
if (antiBhopTriggers.GetArray(key, trigger, sizeof(trigger)))
{
float touchTime = CalculateGroundTouchTime(touched);
float touchTime = CalculateGroundTouchTime(client, touched);
if (trigger.time == 0.0 || touchTime <= trigger.time)
{
// disable jump
Expand Down Expand Up @@ -703,7 +703,7 @@ static bool TouchTeleportTrigger(int client, TouchedTrigger touched, int flags)
// NOTE: Find out if we should actually teleport.
if (isBhopTrigger && (flags & FL_ONGROUND))
{
float touchTime = CalculateGroundTouchTime(touched);
float touchTime = CalculateGroundTouchTime(client, touched);
if (touchTime > trigger.delay)
{
shouldTeleport = true;
Expand All @@ -728,7 +728,7 @@ static bool TouchTeleportTrigger(int client, TouchedTrigger touched, int flags)
}
else if (trigger.type == TeleportType_Normal)
{
float touchTime = CalculateStartTouchTime(touched);
float touchTime = CalculateStartTouchTime(client, touched);
shouldTeleport = touchTime > trigger.delay || (trigger.delay == 0.0);
}

Expand Down Expand Up @@ -793,15 +793,15 @@ static bool TouchTeleportTrigger(int client, TouchedTrigger touched, int flags)
return shouldTeleport;
}

static float CalculateGroundTouchTime(TouchedTrigger touched)
static float CalculateGroundTouchTime(int client, TouchedTrigger touched)
{
float result = float(GetGameTickCount() - touched.groundTouchTick) * GetTickInterval();
float result = float(gI_TickCount[client] - touched.groundTouchTick) * GetTickInterval();
return result;
}

static float CalculateStartTouchTime(TouchedTrigger touched)
static float CalculateStartTouchTime(int client, TouchedTrigger touched)
{
float result = float(GetGameTickCount() - touched.startTouchTick) * GetTickInterval();
float result = float(gI_TickCount[client] - touched.startTouchTick) * GetTickInterval();
return result;
}

Expand Down