#include #include #include /* BOOLS */ bool g_bEnabled; bool g_bActive[MAXPLAYERS+1]; /* CONVARS */ ConVar g_hCVar_Enabled; ConVar g_hCVar_Duration; ConVar g_hCVar_Cost ; //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- public Plugin myinfo = { name = "ZAmmo", author = "Neon", description = "Unlimited ammo for a short period of time", version = "1.0.0" }; //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- public void OnPluginStart() { g_hCVar_Enabled = CreateConVar("zr_zammo_enabled", "1", "", FCVAR_NONE, true, 0.0, true, 1.0); g_hCVar_Duration = CreateConVar("zr_zammo_duration", "5", "", FCVAR_NONE, true, 1.0); g_hCVar_Cost = CreateConVar("zr_zammo_cost", "5000", "", FCVAR_NONE, true, 1.0); g_bEnabled = g_hCVar_Enabled.BoolValue; if (g_bEnabled) HookEvent("weapon_fire", Event_WeaponFire); g_hCVar_Enabled.AddChangeHook(ConVarChanged); HookEvent("round_start", Event_RoundStart); RegConsoleCmd("sm_zammo", Command_ZAmmo); AutoExecConfig(); } //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- public void ConVarChanged(ConVar convar, const char[] oldValue, const char[] newValue) { g_bEnabled = convar.BoolValue; if (g_bEnabled) HookEvent("weapon_fire", Event_WeaponFire); else UnhookEvent("weapon_fire", Event_WeaponFire); } //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- public Action Command_ZAmmo(int client, int args) { if (!g_bEnabled) { ReplyToCommand(client, "[ZAmmo] is currently disabled."); return Plugin_Handled; } if (client == 0) { ReplyToCommand(client, "[ZAmmo] Can't use this from console."); return Plugin_Handled; } if (!IsPlayerAlive(client)) { ReplyToCommand(client, "[ZAmmo] This feature requires you to be alive."); return Plugin_Handled; } if (!ZR_IsClientHuman(client)) { ReplyToCommand(client, "[ZAmmo] This feature requires you to be Human."); return Plugin_Handled; } if(g_bActive[client]) { ReplyToCommand(client, "[ZAmmo] is already active for you."); return Plugin_Handled; } int iCost = g_hCVar_Cost.IntValue; if (GetEntProp(client, Prop_Send, "m_iAccount") < iCost) { ReplyToCommand(client, "[ZAmmo] Insufficent funds (%d).", iCost); return Plugin_Handled; } int iDuration = g_hCVar_Duration.IntValue; SetEntProp(client, Prop_Send, "m_iAccount", GetEntProp(client, Prop_Send, "m_iAccount") - iCost); SetEntPropFloat(client, Prop_Send, "m_flProgressBarStartTime", GetGameTime()); SetEntProp(client, Prop_Send, "m_iProgressBarDuration", iDuration); CreateTimer(float(iDuration), Timer_Disable, GetClientSerial(client), TIMER_FLAG_NO_MAPCHANGE); g_bActive[client] = true; ReplyToCommand(client, "[ZAmmo] Enabling Infinite Ammo for %d seconds in exchange for %d$.", iDuration, iCost); return Plugin_Handled; } //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- public void OnClientDisconnect(int client) { g_bActive[client] = false; } //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- public void Event_RoundStart(Handle hEvent, char[] name, bool dontBroadcast) { for (int client = 1; client <= MaxClients; client++) { g_bActive[client] = false; } } //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- public void Event_WeaponFire(Handle hEvent, char[] name, bool dontBroadcast) { int client = GetClientOfUserId(GetEventInt(hEvent, "userid")); if(!g_bActive[client]) return; int weapon = GetEntPropEnt(client, Prop_Data, "m_hActiveWeapon", 0); if(IsValidEntity(weapon)) { if(weapon == GetPlayerWeaponSlot(client, 0) || weapon == GetPlayerWeaponSlot(client, 1)) { if(GetEntProp(weapon, Prop_Send, "m_iState", 4, 0) == 2 && GetEntProp(weapon, Prop_Send, "m_iClip1", 4, 0)) { int toAdd = 1; char weaponClassname[128]; GetEntityClassname(weapon, weaponClassname, sizeof(weaponClassname)); if(StrEqual(weaponClassname, "weapon_glock", true) || StrEqual(weaponClassname, "weapon_famas", true)) { if(GetEntProp(weapon, Prop_Send, "m_bBurstMode")) { switch (GetEntProp(weapon, Prop_Send, "m_iClip1")) { case 1: { toAdd = 1; } case 2: { toAdd = 2; } default: { toAdd = 3; } } } } SetEntProp(weapon, Prop_Send, "m_iClip1", GetEntProp(weapon, Prop_Send, "m_iClip1", 4, 0) + toAdd, 4, 0); } } } return; } //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- public void ZR_OnClientInfected(int client, int attacker, bool motherInfect, bool respawnOverride, bool respawn) { if (!g_bActive[client]) return; SetEntPropFloat(client, Prop_Send, "m_flProgressBarStartTime", GetGameTime()-1); SetEntProp(client, Prop_Send, "m_iProgressBarDuration", 0); g_bActive[client] = false; } //---------------------------------------------------------------------------------------------------- // Purpose: //---------------------------------------------------------------------------------------------------- public Action Timer_Disable(Handle timer, int iSerial) { g_bActive[client] = false; int client; if ((client = GetClientFromSerial(iSerial)) == 0) return; SetEntPropFloat(client, Prop_Send, "m_flProgressBarStartTime", GetGameTime()-1); SetEntProp(client, Prop_Send, "m_iProgressBarDuration", 0); }