ZSkills: add cd for ZAmmo

This commit is contained in:
dogan 2020-07-03 13:30:33 +02:00
parent fa0b1a7c44
commit 62d14ea7b7

View File

@ -14,6 +14,7 @@ bool g_bLastButtonReload[MAXPLAYERS+1];
ConVar g_hCVar_ZAmmo_Enabled;
ConVar g_hCVar_ZAmmo_Duration;
ConVar g_hCVar_ZAmmo_Cost;
ConVar g_hCVar_ZAmmo_Cooldown;
ConVar g_hCVar_ZCleanse_Enabled;
ConVar g_hCVar_ZCleanse_Duration;
@ -23,6 +24,7 @@ ConVar g_hCVar_ZCleanse_Cooldown;
/* INTEGERS */
int g_bZCleanse_Uses[MAXPLAYERS+1];
int g_iLastZCleanse_Used[MAXPLAYERS+1];
int g_iLastZAmmo_Used[MAXPLAYERS+1];
//----------------------------------------------------------------------------------------------------
// Purpose:
@ -43,6 +45,7 @@ public void OnPluginStart()
g_hCVar_ZAmmo_Enabled = CreateConVar("zr_zammo_enabled", "1", "", FCVAR_NONE, true, 0.0, true, 1.0);
g_hCVar_ZAmmo_Duration = CreateConVar("zr_zammo_duration", "6", "", FCVAR_NONE, true, 1.0);
g_hCVar_ZAmmo_Cost = CreateConVar("zr_zammo_cost", "4500", "", FCVAR_NONE, true, 1.0);
g_hCVar_ZAmmo_Cooldown = CreateConVar("zr_zammo_cooldown", "8", "", FCVAR_NONE, true, 1.0);
g_bZAmmo_Enabled = g_hCVar_ZAmmo_Enabled.BoolValue;
g_hCVar_ZAmmo_Enabled.AddChangeHook(ConVarChanged);
@ -117,6 +120,13 @@ public Action Command_ZAmmo(int client, int args)
PrintToChat(client, "[ZAmmo] Insufficent funds (%d).", iCost);
return Plugin_Handled;
}
int iTimeSinceLastZAmmo = GetTime() - g_iLastZAmmo_Used[client];
int iCooldown = g_hCVar_ZAmmo_Cooldown.IntValue;
if (iTimeSinceLastZAmmo < iCooldown)
{
PrintToChat(client, "[ZCleanse] You need to wait another %d Seconds before you can use ZAmmo again.", iCooldown - iTimeSinceLastZAmmo);
return Plugin_Handled;
}
int iDuration = g_hCVar_ZAmmo_Duration.IntValue;
SetEntProp(client, Prop_Send, "m_iAccount", GetEntProp(client, Prop_Send, "m_iAccount") - iCost);
@ -126,6 +136,7 @@ public Action Command_ZAmmo(int client, int args)
CreateTimer(float(iDuration), Timer_Disable_ZAmmo, GetClientSerial(client), TIMER_FLAG_NO_MAPCHANGE);
g_bZAmmo_Active[client] = true;
g_iLastZAmmo_Used[client] = GetTime();
PrintToChat(client, "[ZAmmo] Enabling Infinite Ammo for %d seconds in exchange for %d$.", iDuration, iCost);
EmitSoundToAll("items/ammopickup.wav", .entity=client, .volume=0.4);
return Plugin_Handled;
@ -198,6 +209,7 @@ public void OnClientDisconnect(int client)
g_bZCleanse_Active[client] = false;
g_bZCleanse_Uses[client] = 0;
g_iLastZCleanse_Used[client] = 0;
g_iLastZAmmo_Used[client] = 0;
}
//----------------------------------------------------------------------------------------------------
@ -211,6 +223,7 @@ public void Event_RoundStart(Handle hEvent, char[] name, bool dontBroadcast)
g_bZCleanse_Active[client] = false;
g_bZCleanse_Uses[client] = 0;
g_iLastZCleanse_Used[client] = 0;
g_iLastZAmmo_Used[client] = 0;
}
}