Skip to content

Commit

Permalink
Add more event handlers to reset timer
Browse files Browse the repository at this point in the history
  • Loading branch information
DevRuto committed Jan 20, 2018
1 parent a12eaa2 commit bb40147
Showing 1 changed file with 44 additions and 16 deletions.
60 changes: 44 additions & 16 deletions scoreboardtimer.sp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public Plugin myinfo =
url = "https://github.com/RutoTV/GOKZ-Scoreboard-Timer"
};


// CSGO/SM events

public APLRes AskPluginLoad2(Handle h, bool late, char[] error, int err_max)
{
if (GetEngineVersion() != Engine_CSGO)
Expand All @@ -39,18 +42,31 @@ public void OnAllPluginsLoaded()
// TODO: do something with this
g_bGOKZ = LibraryExists("gokz-core");

if (!g_bGOKZ) {
if (!g_bGOKZ)
{
SetFailState("GOKZ-Core is required to run this plugin!");
}
}

public void GOKZ_OnFirstSpawn(int client)
{
KillClientTimer(client);
}

public void GOKZ_OnJoinTeam(int client, int team)
{
KillClientTimer(client);
}

public void OnClientDisconnect(int client)
{
KillClientTimer(client);
}

public Action TimerHandler(Handle timer, int client) {
if (ScoreboardTimers[client] == INVALID_HANDLE) {
public Action TimerHandler(Handle timer, int client)
{
if (ScoreboardTimers[client] == INVALID_HANDLE)
{
return;
}
float time = GOKZ_GetCurrentTime(client);
Expand All @@ -59,40 +75,48 @@ public Action TimerHandler(Handle timer, int client) {


// GOKZ Events
public void GOKZ_OnTimerStart_Post(int client, int course) {
public void GOKZ_OnTimerStart_Post(int client, int course)
{
ResetClient(client);
ScoreboardTimers[client] = CreateTimer(1.0, TimerHandler, client, TIMER_REPEAT);
}

public void GOKZ_OnPause_Post(int client) {
public void GOKZ_OnPause_Post(int client)
{
// Kill timer on pause
KillClientTimer(client);
}

public void GOKZ_OnResume_Post(int client) {
public void GOKZ_OnResume_Post(int client)
{
// Create new timer
ScoreboardTimers[client] = CreateTimer(1.0, TimerHandler, client, TIMER_REPEAT);
}

public void GOKZ_OnMakeCheckpoint_Post(int client) {
public void GOKZ_OnMakeCheckpoint_Post(int client)
{
SetAssist(client, GOKZ_GetCheckpointCount(client));
}

public void GOKZ_OnCountedTeleport_Post(int client) {
public void GOKZ_OnCountedTeleport_Post(int client)
{
SetDeath(client, GOKZ_GetTeleportCount(client));
}

public void GOKZ_OnTimerStopped(int client) {
public void GOKZ_OnTimerStopped(int client)
{
ResetClient(client);
}

public void GOKZ_OnTimerEnd_Post(int client, int course, float time, int teleportsUsed) {
public void GOKZ_OnTimerEnd_Post(int client, int course, float time, int teleportsUsed)
{
ResetClient(client);
}

// things
// helpers

void KillClientTimer(int client) {
void KillClientTimer(int client)
{
// https://forums.alliedmods.net/showthread.php?t=205039
if (ScoreboardTimers[client] != INVALID_HANDLE)
{
Expand All @@ -102,23 +126,27 @@ void KillClientTimer(int client) {
}

// Timer
void SetKills(int client, int kills) {
void SetKills(int client, int kills)
{
SetEntProp(client, Prop_Data, "m_iFrags", kills);
}

// Checkpoints
void SetAssist(int client, int assist) {
void SetAssist(int client, int assist)
{
//https://forums.alliedmods.net/showthread.php?t=198659
SetEntData(client, FindDataMapInfo(client, "m_iFrags") + 4, assist);
}

// Teleports
void SetDeath(int client, int death) {
void SetDeath(int client, int death)
{
SetEntProp(client, Prop_Data, "m_iDeaths", death);
}

// Reset timer
void ResetClient(int client) {
void ResetClient(int client)
{
if (ScoreboardTimers[client] != null)
{
KillTimer(ScoreboardTimers[client]);
Expand Down

0 comments on commit bb40147

Please sign in to comment.