Raised This Month: $32 Target: $400
 8% 

Remove weapon on buy


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ilepopivanov
New Member
Join Date: Jan 2019
Old 01-18-2019 , 15:27   Remove weapon on buy
Reply With Quote #1

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"); 
		}
	}
}
ilepopivanov is offline
impossible_cc
Senior Member
Join Date: Sep 2018
Location: Ukraine
Old 01-18-2019 , 17:04   Re: Remove weapon on buy
Reply With Quote #2

Quote:
Originally Posted by ilepopivanov View Post
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.0TimerWeaponCheckclient);
        }
    }
}
public 
Action TimerWeaponCheck(Handle timerint client)
{
int oruzje GetPlayerWeaponSlot(client0);
if(!
IsValidEntity(oruzje))
{return 
Plugin_Continue;}
char _classname[32];
GetEntityClassname(oruzje_classname32);
if(
StrEqual(_classname"weapon_m4a1"false)
{
RemovePlayerItem(clientoruzje);
GivePlayerItem(client"weapon_m4a1_silencer"); 
}
return 
Plugin_Continue;

I used phone to write it, but I still think it should work fine.

Last edited by impossible_cc; 01-18-2019 at 17:06.
impossible_cc is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 01:41.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode