PHP Code:
#include <sourcemod>
#include <sdkhooks>
#include <sdktools>
bool g_IsPluginLoadedLate;
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
g_IsPluginLoadedLate = late;
}
public void OnPluginStart()
{
if (g_IsPluginLoadedLate)
{
for (int i = 1; i <= MaxClients; i++)
{
if (IsClientInGame(i))
{
OnClientPutInServer(i);
}
}
}
}
public void OnEntityCreated(int entity, const char[] classname)
{
if (StrEqual(classname, "weapon_mp7", true))
{
SDKHook(entity, SDKHook_SpawnPost, SDK_OnWeaponSpawn_Post);
}
}
public void SDK_OnWeaponSpawn_Post(int weapon)
{
if (!IsValidEntity(weapon))
{
return;
}
RequestFrame(Frame_SetWeaponAmmo, EntIndexToEntRef(weapon));
}
public void Frame_SetWeaponAmmo(int reference)
{
int weapon = EntRefToEntIndex(reference);
if (weapon == INVALID_ENT_REFERENCE)
{
return;
}
switch (GetItemDefinitionIndex(weapon))
{
case 33: // mp7
{
if (HasOwner(weapon))
{
SetEntProp(weapon, Prop_Send, "m_iClip2", 0);
}
}
}
}
public void OnClientPutInServer(int client)
{
SDKHook(client, SDKHook_WeaponEquipPost, SDK_OnWeaponEquip_Post);
}
public void SDK_OnWeaponEquip_Post(int client, int weapon)
{
if (!IsValidEntity(weapon))
{
return;
}
switch (GetItemDefinitionIndex(weapon))
{
case 33: // mp7
{
if (!HasPrevOwner(weapon))
{
SetEntProp(weapon, Prop_Send, "m_iClip2", 0);
}
}
}
}
int GetItemDefinitionIndex(int item)
{
return GetEntProp(item, Prop_Send, "m_iItemDefinitionIndex");
}
bool HasOwner(int entity)
{
return GetEntPropEnt(entity, Prop_Data, "m_hOwnerEntity") != -1;
}
bool HasPrevOwner(int entity)
{
return GetEntPropEnt(entity, Prop_Send, "m_hPrevOwner") != -1;
}
You can add more weapons.
__________________