Quote:
Originally Posted by ilepopivanov
I am trying to do something but it's not working. I want when a player buys a weapon if the weapon is m4a1 to remove it from him and give him m4a1_silencer. I tested this and when I buy m4a1 the weapon does not get deleted and the new one (m4a1_silencer) spawns on the ground AND when I try to buy again its the same thing but now no m4a1_silencer on ground. I tried moving from the spot and nothing only works 1 time on spawn, when the next round starts its dropping again on the ground but only 1 time.. And yes izberenom4a1[client] = 1
Code:
public Action CS_OnBuyCommand(int client, const char[] weapon)
{
if(StrEqual(weapon, "m4a1"))
{
if(izberanom4[client] == 1)
{
int oruzje = GetPlayerWeaponSlot(client, 1);
RemovePlayerItem(client, oruzje);
GivePlayerItem(client, "weapon_m4a1_silencer");
}
}
}
|
Slot 1 is pistol. You need slot 0 for primary weapon.
PHP Code:
public Action CS_OnBuyCommand(int client, const char[] weapon)
{
if(StrContains(weapon, "m4a1", false) > -1)
{
if(izberanom4[client] == 1)
{
CreateTimer(0.0, TimerWeaponCheck, client);
}
}
}
public Action TimerWeaponCheck(Handle timer, int client)
{
int oruzje = GetPlayerWeaponSlot(client, 0);
if(!IsValidEntity(oruzje))
{return Plugin_Continue;}
char _classname[32];
GetEntityClassname(oruzje, _classname, 32);
if(StrEqual(_classname, "weapon_m4a1", false)
{
RemovePlayerItem(client, oruzje);
GivePlayerItem(client, "weapon_m4a1_silencer");
}
return Plugin_Continue;
}
I used phone to write it, but I still think it should work fine.