Raised This Month: $12 Target: $400
 3% 

Save 2 arrays?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
KuvZz
Member
Join Date: Sep 2013
Location: Spain
Old 09-30-2014 , 08:11   Save 2 arrays?
Reply With Quote #1

Hi guys. I have this and works
PHP Code:
//#includes...
new g_Weapon[33]

enum
{
    
NO_WEAPON 0,
    
AK,
    
M4
}

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
RegisterHam(Ham_Spawn"player""fwd_Spawn"1)
    
    
register_clcmd("say /test""test")
}

public 
client_putinserver(id)
{
    
g_Weapon[id] = NO_WEAPON
}

public 
fwd_Spawn(id)
{
    if (
g_Weapon[id] == NO_WEAPON) return;
    
    if (
g_Weapon[id] == AK)
    {
        
give_item(id"weapon_ak47")
    }
    else if (
g_Weapon[id] == M4)
    {
        
give_item(id"weapon_m4a1")
    }
}

public 
test(id)
{
    new 
menu menu_create("Choose a weapon""items")
    
menu_additem(menu"AK47""0")
    
menu_additem(menu"M4A1""1")
    
    
menu_display(idmenu0)
    return 
PLUGIN_HANDLED
}

public 
items(idmenuitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(menu)
        return 
PLUGIN_HANDLED
    
}
    
    switch (
item)
    {
        case 
0:
        {
            
g_Weapon[id] = AK //Next round you'll get an AK47
            
menu_destroy(menu)
            return 
PLUGIN_HANDLED
        
}
        case 
1:
        {
            
g_Weapon[id] = M4A1 //Next round you'll get a M4A1
            
menu_destroy(menu)
            return 
PLUGIN_HANDLED
        
}
    }
    return 
PLUGIN_HANDLED

but I only can choose one of them, what I should do to choose 2, 3 or more arrays?
Ty for help^^
__________________

Last edited by KuvZz; 09-30-2014 at 14:27.
KuvZz is offline
bat
Veteran Member
Join Date: Jul 2012
Old 09-30-2014 , 12:51   Re: Save 2 arrays?
Reply With Quote #2

So, you ask after choose some from menu, menu not will close?
__________________
bat is offline
Send a message via Skype™ to bat
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-30-2014 , 13:24   Re: Save 2 arrays?
Reply With Quote #3

Describe better what you are wanting to do because you currently aren't making much sense.
__________________
fysiks is offline
KuvZz
Member
Join Date: Sep 2013
Location: Spain
Old 09-30-2014 , 14:20   Re: Save 2 arrays?
Reply With Quote #4

For example, in that menu select AK47 and M4A1 to get them (both) in the next round.
Actually, if I select AK47 and then M4A1, I only will get M4A1 (the last option I choose)

Sorry for my English xD
__________________

Last edited by KuvZz; 09-30-2014 at 14:22.
KuvZz is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-30-2014 , 14:26   Re: Save 2 arrays?
Reply With Quote #5

An easy method, but not very elegant, would be to have one array for each weapon. Is it even possible to have multiple primary weapons?
__________________
fysiks is offline
KuvZz
Member
Join Date: Sep 2013
Location: Spain
Old 09-30-2014 , 14:36   Re: Save 2 arrays?
Reply With Quote #6

Quote:
Is it even possible to have multiple primary weapons?
Yep.

Mmh, I'll try that.
__________________
KuvZz is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 09-30-2014 , 17:25   Re: Save 2 arrays?
Reply With Quote #7

Another method is using bit fields, which could reduce memory usage by 33(every player representing one bit) times, or 'number of weapons'(every player having his own bit field of weapons, instead of an array) times. Search for bit fields, bit-wise operators, etc. on the forum/Google to learn more about it, there are few great tutorials on the subject on AlliedModders.
klippy is offline
KuvZz
Member
Join Date: Sep 2013
Location: Spain
Old 10-01-2014 , 04:03   Re: Save 2 arrays?
Reply With Quote #8

Quote:
Originally Posted by KliPPy View Post
Another method is using bit fields, which could reduce memory usage by 33(every player representing one bit) times, or 'number of weapons'(every player having his own bit field of weapons, instead of an array) times. Search for bit fields, bit-wise operators, etc. on the forum/Google to learn more about it, there are few great tutorials on the subject on AlliedModders.
Yeah, thanks
Honestly, I prefer tutorials instead of get the code xD
__________________
KuvZz is offline
Reply



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 16:08.


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