AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Weapon change (https://forums.alliedmods.net/showthread.php?t=156534)

misterx 05-08-2011 05:20

Weapon change
 
Hi,

I'm building a custom VIP weapon menu. It works fine, but if player selects the weapons he already has, it drops it. It works like this:
when a player selects a primary weapon, I run this function:
PHP Code:

cs_drop_slot(id1);

public 
cs_drop_slot(idweapon_id) {
    new 
weapons[32], weapons_num;
    
get_user_weapons(idweaponsweapons_num);
    for (new 
i=0i<=weapons_numi++) {
        if (
cs_weapon_level(weapons[i]) == weapon_id) {
            
client_cmd(id"drop ^"%s^""cs_weapon_id_to_name(weapons[i]));
        }
    }


cs_weapon_level converts weapon id to its slot, cs_weapon_id_to_name converts weapon id to its name (for example "weapon_awp").
But if I give user the same weapon it allready has, it will be droped. If someone needs the full code, I'll PM it, I really don't want to make this public.

ConnorMcLeod 05-08-2011 07:37

Re: Weapon change
 
Make a check with weapon CSW_ id against user_has_weapon()

misterx 05-08-2011 07:52

Re: Weapon change
 
I don't understand.

SonicSonedit 05-08-2011 10:17

Re: Weapon change
 
misterx
Just check if user has this weapon already.
PHP Code:

   get_user_weapons(idweaponsweapons_num);
   for (new 
i=0i<=weapons_numi++) 
   {
      if (
weapons[i]==buying_weapon_id)
      {
         
client_print(idprint_center"You already have this weapon.")
         return;
      }
   } 

buying_weapon_id is supposed to store weapondID that player is about to buy (check CSW_ list in amxconst.inc for weapons ID).

ConnorMcLeod 05-08-2011 12:08

Re: Weapon change
 
No, do this :

if( user_has_weapon(id, buying_weapon_id) ) return

Before you make him buy it or drop it.

misterx 05-08-2011 12:25

Re: Weapon change
 
He doesn't buy anything, he has a menu:
1. M4A1
2. AK-47

Do I have to write an other function or is there an other way. Technicly, it seems like a AMXX bug, as cs_drop_slot() is called before the user is given its weapon. Mayby I'll PM the code?

ConnorMcLeod 05-08-2011 13:58

Re: Weapon change
 
Quote:

Originally Posted by misterx (Post 1465663)
it seems like a AMXX bug

LoL

misterx 05-08-2011 15:11

Re: Weapon change
 
Well, isn't it? I mean, I call cs_drop_slot() first and after that I give the user its weapon.

SonicSonedit 05-08-2011 15:44

Re: Weapon change
 
misterx
If it's not your plugin, ask author.
If you want to do it yourself so badly, analize plugin, find where weapon ID is checked and do what ConnorMcLeod said.

misterx 05-08-2011 16:06

Re: Weapon change
 
It is my plugin. Is there no way to do it without writing any more functions?


All times are GMT -4. The time now is 04:26.

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