Skip to content

Commit

Permalink
Merge pull request #324 from KZGlobalTeam/dev
Browse files Browse the repository at this point in the history
3.3.0
  • Loading branch information
zealain authored May 30, 2022
2 parents 0469493 + 972a285 commit 9eef0cf
Show file tree
Hide file tree
Showing 31 changed files with 531 additions and 125 deletions.
9 changes: 9 additions & 0 deletions addons/sourcemod/scripting/gokz-core/commands.sp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ public Action CommandJoinTeam(int client, const char[] command, int argc)
char teamString[4];
GetCmdArgString(teamString, sizeof(teamString));
int team = StringToInt(teamString);

if (team == CS_TEAM_SPECTATOR)
{
if (!GOKZ_GetPaused(client) && !GOKZ_GetCanPause(client))
{
return Plugin_Handled;
}
}

GOKZ_JoinTeam(client, team);
return Plugin_Handled;
}
Expand Down
5 changes: 5 additions & 0 deletions addons/sourcemod/scripting/gokz-core/demofix.sp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ static void DoDemoFix()
{
case 0:
{
if (!mapRunning)
{
return;
}

GameRules_SetProp("m_bWarmupPeriod", 0);
}
case 1:
Expand Down
81 changes: 74 additions & 7 deletions addons/sourcemod/scripting/gokz-core/map/triggers.sp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ static int antiJumpstatTriggerTouchCount[MAXPLAYERS + 1];
static int mapMappingApiVersion = GOKZ_MAPPING_API_VERSION_NONE;
static int bhopTouchCount[MAXPLAYERS + 1];
static ArrayList triggerTouchList[MAXPLAYERS + 1]; // arraylist of TouchedTrigger that the player is currently touching. this array won't ever get long (unless the mapper does something weird).
static StringMap triggerTouchCounts[MAXPLAYERS + 1]; // stringmap of int touch counts with key being a string of the entity reference.
static StringMap antiBhopTriggers; // stringmap of AntiBhopTrigger with key being a string of the m_iHammerID entprop.
static StringMap teleportTriggers; // stringmap of TeleportTrigger with key being a string of the m_iHammerID entprop.
static StringMap timerButtonTriggers; // stringmap of legacy timer zone triggers with key being a string of the m_iHammerID entprop.
Expand Down Expand Up @@ -143,6 +144,15 @@ void OnClientPutInServer_MapTriggers(int client)
triggerTouchList[client].Clear();
}

if (triggerTouchCounts[client] == null)
{
triggerTouchCounts[client] = new StringMap();
}
else
{
triggerTouchCounts[client].Clear();
}

bhopTouchCount[client] = 0;

if (lastTouchSequentialBhopEntRefs[client] == null)
Expand Down Expand Up @@ -191,7 +201,14 @@ void OnPlayerRunCmd_MapTriggers(int client, int &buttons)
}
else if (touched.triggerType == TriggerType_Teleport)
{
TouchTeleportTrigger(client, touched, flags);
// Sometimes due to lag or whatever, the player can be
// teleported twice by the same trigger. This fixes that.
if (TouchTeleportTrigger(client, touched, flags))
{
RemoveTriggerFromTouchList(client, EntRefToEntIndex(touched.entRef));
i--;
triggerTouchListLength--;
}
}
}
}
Expand Down Expand Up @@ -299,6 +316,14 @@ public void OnAntiBhopTrigTouchStart_MapTriggers(const char[] output, int entity
return;
}

int touchCount = IncrementTriggerTouchCount(other, entity);
if (touchCount <= 0)
{
// The trigger has fired a matching endtouch output before
// the starttouch output, so ignore it.
return;
}

AddTriggerToTouchList(other, entity, TriggerType_Antibhop);
}

Expand All @@ -309,6 +334,7 @@ public void OnAntiBhopTrigTouchEnd_MapTriggers(const char[] output, int entity,
return;
}

DecrementTriggerTouchCount(other, entity);
RemoveTriggerFromTouchList(other, entity);
}

Expand All @@ -319,6 +345,14 @@ public void OnTeleportTrigTouchStart_MapTriggers(const char[] output, int entity
return;
}

int touchCount = IncrementTriggerTouchCount(other, entity);
if (touchCount <= 0)
{
// The trigger has fired a matching endtouch output before
// the starttouch output, so ignore it.
return;
}

char key[32];
GetEntityHammerIDString(entity, key, sizeof(key));
TeleportTrigger trigger;
Expand All @@ -338,6 +372,8 @@ public void OnTeleportTrigTouchEnd_MapTriggers(const char[] output, int entity,
return;
}

DecrementTriggerTouchCount(other, entity);

char key[32];
GetEntityHammerIDString(entity, key, sizeof(key));
TeleportTrigger trigger;
Expand Down Expand Up @@ -552,6 +588,34 @@ static void RemoveTriggerFromTouchList(int client, int trigger)
}
}

static int IncrementTriggerTouchCount(int client, int trigger)
{
int entref = EntIndexToEntRef(trigger);
char szEntref[64];
FormatEx(szEntref, sizeof(szEntref), "%i", entref);

int value = 0;
triggerTouchCounts[client].GetValue(szEntref, value);

value += 1;
triggerTouchCounts[client].SetValue(szEntref, value);

return value;
}

static void DecrementTriggerTouchCount(int client, int trigger)
{
int entref = EntIndexToEntRef(trigger);
char szEntref[64];
FormatEx(szEntref, sizeof(szEntref), "%i", entref);

int value = 0;
triggerTouchCounts[client].GetValue(szEntref, value);

value -= 1;
triggerTouchCounts[client].SetValue(szEntref, value);
}

static void TouchAntibhopTrigger(TouchedTrigger touched, int &newButtons, int flags)
{
if (!(flags & FL_ONGROUND))
Expand Down Expand Up @@ -582,22 +646,24 @@ static void TouchAntibhopTrigger(TouchedTrigger touched, int &newButtons, int fl
}
}

static void TouchTeleportTrigger(int client, TouchedTrigger touched, int flags)
static bool TouchTeleportTrigger(int client, TouchedTrigger touched, int flags)
{
bool shouldTeleport = false;

char key[32];
GetEntityHammerIDString(touched.entRef, key, sizeof(key));
TeleportTrigger trigger;
if (!teleportTriggers.GetArray(key, trigger, sizeof(trigger)))
{
// Couldn't get the teleport trigger from the trigger array for some reason.
return;
return shouldTeleport;
}

bool isBhopTrigger = IsBhopTrigger(trigger.type);
// NOTE: Player hasn't touched the ground inside this trigger yet.
if (touched.groundTouchTick == -1 && isBhopTrigger)
{
return;
return shouldTeleport;
}

float destOrigin[3];
Expand All @@ -615,11 +681,10 @@ static void TouchTeleportTrigger(int client, TouchedTrigger touched, int flags)
|| (!gotTriggerOrigin && trigger.relativeDestination))
{
PrintToConsole(client, "[KZ] Invalid teleport destination \"%s\" on trigger with hammerID %i.", trigger.tpDestination, trigger.hammerID);
return;
return shouldTeleport;
}

// NOTE: Find out if we should actually teleport.
bool shouldTeleport = false;
if (isBhopTrigger && (flags & FL_ONGROUND))
{
float touchTime = CalculateGroundTouchTime(touched);
Expand Down Expand Up @@ -653,7 +718,7 @@ static void TouchTeleportTrigger(int client, TouchedTrigger touched, int flags)

if (!shouldTeleport)
{
return;
return shouldTeleport;
}

bool shouldReorientPlayer = trigger.reorientPlayer
Expand Down Expand Up @@ -708,6 +773,8 @@ static void TouchTeleportTrigger(int client, TouchedTrigger touched, int flags)
{
TeleportPlayer(client, finalOrigin, finalPlayerAngles, gotDestAngles && trigger.useDestAngles, trigger.resetSpeed);
}

return shouldTeleport;
}

static float CalculateGroundTouchTime(TouchedTrigger touched)
Expand Down
7 changes: 4 additions & 3 deletions addons/sourcemod/scripting/gokz-core/misc.sp
Original file line number Diff line number Diff line change
Expand Up @@ -312,14 +312,15 @@ void JoinTeam(int client, int newTeam, bool restorePos)

static bool validJump[MAXPLAYERS + 1];
static float validJumpTeleportOrigin[MAXPLAYERS + 1][3];

static int lastInvalidatedTick[MAXPLAYERS + 1];
bool GetValidJump(int client)
{
return validJump[client];
}

static void InvalidateJump(int client)
{
lastInvalidatedTick[client] = GetGameTickCount();
if (validJump[client])
{
validJump[client] = false;
Expand All @@ -329,7 +330,7 @@ static void InvalidateJump(int client)

void OnStopTouchGround_ValidJump(int client, bool jumped, bool ladderJump, bool jumpbug)
{
if (Movement_GetMovetype(client) == MOVETYPE_WALK)
if (Movement_GetMovetype(client) == MOVETYPE_WALK && lastInvalidatedTick[client] != GetGameTickCount())
{
validJump[client] = true;
Call_GOKZ_OnJumpValidated(client, jumped, ladderJump, jumpbug);
Expand All @@ -350,7 +351,7 @@ void OnPlayerRunCmdPost_ValidJump(int client)

void OnChangeMovetype_ValidJump(int client, MoveType oldMovetype, MoveType newMovetype)
{
if (oldMovetype == MOVETYPE_LADDER && newMovetype == MOVETYPE_WALK) // Ladderjump
if (oldMovetype == MOVETYPE_LADDER && newMovetype == MOVETYPE_WALK && lastInvalidatedTick[client] != GetGameTickCount()) // Ladderjump
{
validJump[client] = true;
Call_GOKZ_OnJumpValidated(client, false, true, false);
Expand Down
7 changes: 6 additions & 1 deletion addons/sourcemod/scripting/gokz-core/teleports.sp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,12 @@ void MakeCheckpoint(int client)
{
GOKZ_PrintToChat(client, true, "%t", "Make Checkpoint", checkpointCount[client]);
}


if (!GetTimerRunning(client) && AntiCpTriggerIsTouched(client))
{
GOKZ_PrintToChat(client, true, "%t", "Anti Checkpoint Area Warning");
}

// Call Post Forward
Call_GOKZ_OnMakeCheckpoint_Post(client);
}
Expand Down
4 changes: 2 additions & 2 deletions addons/sourcemod/scripting/gokz-core/triggerfix.sp
Original file line number Diff line number Diff line change
Expand Up @@ -342,9 +342,9 @@ static bool DoTriggerFix(int client, bool filterFix = false)
{
char className[64];
GetEntityClassname(trigger, className, sizeof(className));
if (GetEntityFlags(client) & FL_BASEVELOCITY && StrEqual(className, "trigger_push"))
if (StrEqual(className, "trigger_push"))
{
// We are currently affected by a push trigger, do not try to touch it again to prevent double boost.
// Completely ignore push triggers.
continue;
}
// If the player is still touching the trigger on this tick, and Touch was not called for whatever reason
Expand Down
20 changes: 20 additions & 0 deletions addons/sourcemod/scripting/gokz-global.sp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ int gI_MapFileSize;
int gI_MapTier;

ConVar gCV_gokz_settings_enforcer;
ConVar gCV_gokz_warn_for_non_global_map;
ConVar gCV_EnforcedCVar[ENFORCEDCVAR_COUNT];

#include "gokz-global/api.sp"
Expand Down Expand Up @@ -259,6 +260,24 @@ public void GlobalAPI_OnInitialized()
SetupAPI();
}


public Action GOKZ_OnTimerStart(int client, int course)
{
KZPlayer player = KZPlayer(client);
int mode = player.Mode;

// We check the timer running to prevent spam when standing inside VB.
if (gCV_gokz_warn_for_non_global_map.BoolValue
&& GlobalAPI_HasAPIKey()
&& !GlobalsEnabled(mode)
&& !GOKZ_GetTimerRunning(client))
{
GOKZ_PrintToChat(client, true, "%t", "Warn Player Not Global Run");
}

return Plugin_Continue;
}

public void GOKZ_OnTimerStart_Post(int client, int course)
{
KZPlayer player = KZPlayer(client);
Expand Down Expand Up @@ -512,6 +531,7 @@ static void CreateConVars()
AutoExecConfig_SetCreateFile(true);

gCV_gokz_settings_enforcer = AutoExecConfig_CreateConVar("gokz_settings_enforcer", "1", "Whether GOKZ enforces convars required for global records.", _, true, 0.0, true, 1.0);
gCV_gokz_warn_for_non_global_map = AutoExecConfig_CreateConVar("gokz_warn_for_non_global_map", "1", "Whether or not GOKZ should warn players if the global check does not pass.", _, true, 0.0, true, 1.0);
gCV_gokz_settings_enforcer.AddChangeHook(OnConVarChanged);

AutoExecConfig_ExecuteFile();
Expand Down
32 changes: 30 additions & 2 deletions addons/sourcemod/scripting/gokz-hud.sp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <sourcemod>

#include <sdkhooks>
#include <gokz/core>
#include <gokz/hud>

Expand Down Expand Up @@ -30,6 +31,8 @@ public Plugin myinfo =
bool gB_GOKZRacing;
bool gB_GOKZReplays;
bool gB_MenuShowing[MAXPLAYERS + 1];
bool gB_JBTakeoff[MAXPLAYERS + 1];
bool gB_FastUpdateRate[MAXPLAYERS + 1];

#include "gokz-hud/commands.sp"
#include "gokz-hud/hide_weapon.sp"
Expand All @@ -43,7 +46,6 @@ bool gB_MenuShowing[MAXPLAYERS + 1];
#include "gokz-hud/tp_menu.sp"



// =====[ PLUGIN EVENTS ]=====

public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
Expand Down Expand Up @@ -80,6 +82,13 @@ public void OnAllPluginsLoaded()

gB_GOKZRacing = LibraryExists("gokz-racing");
gB_GOKZReplays = LibraryExists("gokz-replays");
for (int client = 1; client <= MaxClients; client++)
{
if (IsClientInGame(client))
{
OnClientPutInServer(client);
}
}
}

public void OnLibraryAdded(const char[] name)
Expand All @@ -103,6 +112,17 @@ public void OnLibraryRemoved(const char[] name)

// =====[ CLIENT EVENTS ]=====

public void OnClientPutInServer(int client)
{
SDKHook(client, SDKHook_PostThinkPost, OnPlayerPostThinkPost);
}

public void OnPlayerPostThinkPost(int client)
{
KZPlayer player = KZPlayer(client);
gB_JBTakeoff[client] = (gB_JBTakeoff[client] && !player.OnGround && !player.OnLadder && !player.Noclipping) || Movement_GetJumpbugged(client);
}

public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float vel[3], const float angles[3], int weapon, int subtype, int cmdnum, int tickcount, int seed, const int mouse[2])
{
if (!IsValidClient(client))
Expand Down Expand Up @@ -216,10 +236,17 @@ public void GOKZ_OnOptionChanged(int client, const char[] option, any newValue)
OnOptionChanged_Menu(client, hudOption);
OnOptionChanged_HideWeapon(client, hudOption);
OnOptionChanged_Options(client, hudOption, newValue);
if (hudOption == HUDOption_UpdateRate)
{
gB_FastUpdateRate[client] = GOKZ_HUD_GetOption(client, HUDOption_UpdateRate) == UpdateRate_Fast;
}
}
}


public void GOKZ_OnOptionsLoaded(int client)
{
gB_FastUpdateRate[client] = GOKZ_HUD_GetOption(client, HUDOption_UpdateRate) == UpdateRate_Fast;
}

// =====[ OTHER EVENTS ]=====

Expand Down Expand Up @@ -264,6 +291,7 @@ static void SetHUDInfo(KZPlayer player, HUDInfo info, int cmdnum)
info.ID = player.ID;
info.Jumped = player.Jumped;
info.HitPerf = player.GOKZHitPerf;
info.HitJB = gB_JBTakeoff[info.ID];
info.TakeoffSpeed = player.GOKZTakeoffSpeed;
info.IsTakeoff = Movement_GetTakeoffCmdNum(player.ID) == cmdnum;
info.Buttons = player.Buttons;
Expand Down
Loading

0 comments on commit 9eef0cf

Please sign in to comment.