PHP Code:
#include <sdktools>
new Handle:g_hInfAmmoTimers[MAXPLAYERS+1];
new Handle:cvar_enabled;
public OnPluginStart()
{
LoadTranslations("common.phrases");
RegAdminCmd("sm_infammo", cmd_infammo, ADMFLAG_CHEATS, "Usage: sm_infammo <#userid|name|@all> <1|0>");
cvar_enabled = CreateConVar("sm_infammo_enable", "0", "Enabke/Disable infinite ammo to all", FCVAR_PLUGIN, true, 0.0, true, 1.0);
HookConVarChange(cvar_enabled, cvar_changed);
cvar_changed(INVALID_HANDLE, NULL_STRING, NULL_STRING);
}
public cvar_changed(Handle:cvar, const String:oldValue[], const String:newValue[])
{
for(new i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i))
{
OnClientPutInServer(i);
}
}
}
public Action:cmd_infammo(client, args)
{
if(args < 2)
{
ReplyToCommand(client, "[SM] Usage: sm_infammo <#userid|name|@all> <1|0>");
return Plugin_Handled;
}
new String:arg[MAX_NAME_LENGTH], bool:onoff;
GetCmdArg(2, arg, sizeof(arg));
onoff = StringToInt(arg) != 0;
GetCmdArg(1, arg, sizeof(arg));
new targets[MaxClients], bool:tn_is_ml;
new target_count = ProcessTargetString(arg,
client,
targets, MaxClients,
0,
arg, sizeof(arg),
tn_is_ml);
if(target_count <= COMMAND_TARGET_NONE)
{
ReplyToTargetError(client, target_count);
return Plugin_Handled;
}
tn_is_ml ? ShowActivity2(client, "[SM] ", "%s infinite ammo %t", onoff ? "Enable":"Disable", arg):ShowActivity2(client, "[SM] ", "%s infinite ammo %s", onoff ? "Enable":"Disable", arg);
tn_is_ml ? LogAction(client, -1, "%s infinite ammo %t", onoff ? "Enable":"Disable", arg):LogAction(client, -1, "%s infinite ammo %s", onoff ? "Enable":"Disable", arg);
for(new i = 0; i < target_count; i++)
{
perform_infammo(targets[i], onoff);
}
return Plugin_Handled;
}
public OnClientPutInServer(client)
{
perform_infammo(client, GetConVarBool(cvar_enabled));
}
perform_infammo(client, onoff)
{
if( !onoff && g_hInfAmmoTimers[client] != INVALID_HANDLE )
{
KillTimer(g_hInfAmmoTimers[client], true);
g_hInfAmmoTimers[client] = INVALID_HANDLE;
}
else if( onoff && g_hInfAmmoTimers[client] == INVALID_HANDLE )
{
new Handle:pack;
g_hInfAmmoTimers[client] = CreateDataTimer(0.5, refill, pack, TIMER_REPEAT);
WritePackCell(pack, client);
WritePackCell(pack, GetClientUserId(client));
}
}
public Action:refill(Handle:timer, Handle:pack)
{
ResetPack(pack);
new array_index = ReadPackCell(pack);
new userid = ReadPackCell(pack);
new client = GetClientOfUserId(userid);
if(client == 0 || !IsClientInGame(client))
{
g_hInfAmmoTimers[array_index] = INVALID_HANDLE;
return Plugin_Stop;
}
if(!IsPlayerAlive(client))
{
return Plugin_Continue;
}
static timestamp[MAXPLAYERS+1];
if(GetEntProp(client, Prop_Send, "m_bDucked"))
{
if( timestamp[client] + 10 < GetTime() )
{
//PrintToServer("No inf ammo");
return Plugin_Continue;
}
}
else
{
timestamp[client] = GetTime();
}
new weapon = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
if(weapon <= MaxClients)
{
return Plugin_Continue;
}
new PrimaryAmmoType = GetEntProp(weapon, Prop_Send, "m_iPrimaryAmmoType");
new SecondaryAmmoType = GetEntProp(weapon, Prop_Send, "m_iSecondaryAmmoType");
//PrintToServer("Type %i, %i", PrimaryAmmoType, SecondaryAmmoType)
//PrintToServer("Clip %i, %i", Clip1, Clip2);
if(PrimaryAmmoType != -1)
{
SetEntProp(client, Prop_Send, "m_iAmmo", 100, _, PrimaryAmmoType);
if( GetEntProp(weapon, Prop_Send, "m_iClip1") != 255 )
{
SetEntProp(weapon, Prop_Send, "m_iClip1", 100);
}
}
if(SecondaryAmmoType != -1)
{
SetEntProp(client, Prop_Send, "m_iAmmo", 100, _, SecondaryAmmoType);
if( GetEntProp(weapon, Prop_Send, "m_iClip2") != 255 )
{
SetEntProp(weapon, Prop_Send, "m_iClip2", 100);
}
}
return Plugin_Continue;
}