AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Save 2 arrays? (https://forums.alliedmods.net/showthread.php?t=249100)

KuvZz 09-30-2014 08:11

Save 2 arrays?
 
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^^

bat 09-30-2014 12:51

Re: Save 2 arrays?
 
So, you ask after choose some from menu, menu not will close?

fysiks 09-30-2014 13:24

Re: Save 2 arrays?
 
Describe better what you are wanting to do because you currently aren't making much sense.

KuvZz 09-30-2014 14:20

Re: Save 2 arrays?
 
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

fysiks 09-30-2014 14:26

Re: Save 2 arrays?
 
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?

KuvZz 09-30-2014 14:36

Re: Save 2 arrays?
 
Quote:

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

Mmh, I'll try that.

klippy 09-30-2014 17:25

Re: Save 2 arrays?
 
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.

KuvZz 10-01-2014 04:03

Re: Save 2 arrays?
 
Quote:

Originally Posted by KliPPy (Post 2205461)
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 :D
Honestly, I prefer tutorials instead of get the code xD


All times are GMT -4. The time now is 17:35.

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