Raised This Month: $ Target: $400
 0% 

Weapon change


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
misterx
Member
Join Date: Jan 2011
Old 05-08-2011 , 05:20   Weapon change
Reply With Quote #1

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.
misterx is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-08-2011 , 07:37   Re: Weapon change
Reply With Quote #2

Make a check with weapon CSW_ id against user_has_weapon()
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
misterx
Member
Join Date: Jan 2011
Old 05-08-2011 , 07:52   Re: Weapon change
Reply With Quote #3

I don't understand.
misterx is offline
SonicSonedit
Veteran Member
Join Date: Nov 2008
Location: Silent Hill
Old 05-08-2011 , 10:17   Re: Weapon change
Reply With Quote #4

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).
__________________


Last edited by SonicSonedit; 05-08-2011 at 10:20.
SonicSonedit is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-08-2011 , 12:08   Re: Weapon change
Reply With Quote #5

No, do this :

if( user_has_weapon(id, buying_weapon_id) ) return

Before you make him buy it or drop it.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
misterx
Member
Join Date: Jan 2011
Old 05-08-2011 , 12:25   Re: Weapon change
Reply With Quote #6

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?
misterx is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-08-2011 , 13:58   Re: Weapon change
Reply With Quote #7

Quote:
Originally Posted by misterx View Post
it seems like a AMXX bug
LoL
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
misterx
Member
Join Date: Jan 2011
Old 05-08-2011 , 15:11   Re: Weapon change
Reply With Quote #8

Well, isn't it? I mean, I call cs_drop_slot() first and after that I give the user its weapon.
misterx is offline
SonicSonedit
Veteran Member
Join Date: Nov 2008
Location: Silent Hill
Old 05-08-2011 , 15:44   Re: Weapon change
Reply With Quote #9

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.
__________________

SonicSonedit is offline
misterx
Member
Join Date: Jan 2011
Old 05-08-2011 , 16:06   Re: Weapon change
Reply With Quote #10

It is my plugin. Is there no way to do it without writing any more functions?
misterx 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 04:26.


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