So this is for sourcemod as i dont really do much with amxx anymore..
Code:
/*Weapon Variables*/
new Handle:g_WeaponArray[2] = INVALID_HANDLE;
//When a player leaves clear the saved weapons.
public OnClientDisconnect(iClient)
{
ClearClientWeapons(iClient);
}
//Ovb strips the weapons... for bones or a mod where you want the knife out use it like this. StripUserWeapons(iClient, true); Otherwise use false
stock StripUserWeapons(iClient, bool:bResetKnife)
{
if(IsClientInGame(iClient) && IsPlayerAlive(iClient))
{
new iPrimaryWeapon = GetPlayerWeaponSlot(iClient, 0);
new iSecondaryWeapon = GetPlayerWeaponSlot(iClient, 1);
if(iPrimaryWeapon != -1)
RemovePlayerItem(iClient, iPrimaryWeapon);
if(iSecondaryWeapon != -1)
RemovePlayerItem(iClient, iSecondaryWeapon);
if(bResetKnife)
{
new iKnifeSlot = GetPlayerWeaponSlot(iClient, 2);
if(iKnifeSlot != -1)
RemovePlayerItem(iClient, iKnifeSlot);
GivePlayerItem(iClient, "weapon_knife");
}
}
}
//Call this to save a players current primary and secondary
stock SaveClientWeapons(const iClient)
{
new weapon;
decl String:weaponclassname[MAX_WEAPON_STRING];
new j = 0;
for (new i = 0, offset = Client_GetWeaponsOffset(iClient); i < MAX_WEAPONS; i++, offset += 4)
{
weapon = GetEntDataEnt2(iClient, offset);
if (!Weapon_IsValid(weapon))
{
break;
}
GetEdictClassname(weapon, weaponclassname, MAX_WEAPON_STRING);
if ((!StrEqual(weaponclassname, "weapon_knife")) && (!StrEqual(weaponclassname, "weapon_c4")))
{
strcopy(ClientWeapons[iClient][j], MAX_WEAPON_STRING, weaponclassname);
j++;
if (j == MAX_CLIENT_WEAPONS)
{
return;
}
}
}
GetEntPropVector(iClient, Prop_Data, "m_vecOrigin", g_flOrigin[iClient]);
ClientWeapons[iClient][j][0] = '\0';
}
//Call this to give the weapons back to the player
stock RestoreClientWeapons(const iClient)
{
StripUserWeapons(iClient, false);
for (new i = 0; i < MAX_CLIENT_WEAPONS; i++)
{
if (ClientWeapons[iClient][i][0] == '\0')
{
return;
}
Client_GiveWeapon(iClient, ClientWeapons[iClient][i], false);
}
}
//Clears the variable
stock ClearClientWeapons(const iClient)
{
for (new i = 0; i < MAX_CLIENT_WEAPONS; i++)
{
ClientWeapons[iClient][i][0] = '\0';
}
}
//Reads the variable up top and creates the weapons on the ground where the player died. Physics work most of the time.
stock CreateDroppedWeapons(const iClient)
{
decl iEnt;
for (new i = 0; i < MAX_CLIENT_WEAPONS; i++)
{
if((iEnt = CreateEntityByName(ClientWeapons[iClient][i])) != -1)
{
DispatchSpawn(iEnt);
CS_SetDroppedWeaponAmmo(iEnt, GetMaxWeaponAmmo(ClientWeapons[iClient][i]));
TeleportEntity(iEnt, g_flOrigin[iClient], NULL_VECTOR, NULL_VECTOR);
}
}
ClearClientWeapons(iClient);
}