Here's a version I use for one of my servers that adds a few checks (needed checks)
I should make it known that none of this is from the auther's code, this was made some months ago.
Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdkhooks>
#define PLUGIN_VERSION "1.0.0.3"
//infandor
new bool:roundend=false;
new String:strDate[5];
new ActiveWeapon;
public Plugin:myinfo = {
name = "Infinite Ammo",
author = "Cooltad",
description = "gives all players infinite ammo.",
version = PLUGIN_VERSION,
url = "www.thetoptiers.com"
};
public OnPluginStart()
{
for (new client=1;client<=MaxClients;client++)
{
if (IsClientInGame(client))
{
SDKHook(client, SDKHook_PreThink, OnPreThink);
}
}
HookEvent("teamplay_round_win", Event_RoundEnd, EventHookMode_PostNoCopy);
HookEvent("teamplay_round_active", Event_RoundStart, EventHookMode_PostNoCopy);
}
public OnClientPostAdminCheck(client)
{
SDKHook(client, SDKHook_PreThink, OnPreThink);
}
public OnPreThink(client)
{
if (!roundend)
{
for(client=0;client<=MaxClients;client++)
{
if(IsValidEntity(client))
{
ActiveWeapon=GetEntDataEnt2(client,FindSendPropOffs("CTFPlayer", "m_hActiveWeapon"));
if(IsValidEntity(ActiveWeapon))
{
SetEntData(ActiveWeapon,FindSendPropOffs("CBaseCombatWeapon", "m_iClip1"),5,4);
SetEntData(client,FindSendPropOffs("CTFPlayer", "m_iAmmo")+4,5,4);
SetEntData(client,FindSendPropOffs("CTFPlayer", "m_iAmmo")+8,5,4);
}
}
}
}
}
public Event_RoundEnd(Handle:event,const String:name[],bool:dontBroadcast)
{
roundend=true;
}
public Event_RoundStart(Handle:event,const String:name[],bool:dontBroadcast)
{
roundend=false;
}
The author's code would eventually crash a server, this one doesn't.
If you're wondering why, it's because 1=client, 0=weapon, he assigns i=1, which is incorrect.
I should also say this code is originally made for infinite clip, not just ammo. But I removed the clip part and left the ammo part.
__________________