AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Menu and spawn stuff (https://forums.alliedmods.net/showthread.php?t=129271)

vL. 06-10-2010 20:36

Menu and spawn stuff
 
So I got this menu where are 4 weapons and 1 of them is default(you spawn with it if you haven't taken another one), so I need some help with the spawn thing, so it would save the settings. I've made a menu based on the tutorial what Emp' had made. I think the spawn thing has something to do with the function, so that the WeaponName would change if the user chooses the other weapon.

PHP Code:

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
RegisterHam(Ham_Spawn"player""FwdHamSpawn_Post"1);
    
    
register_clcmd("say /weapons""Weapons");
}

public 
FwdHamSpawn_Post(id)
{
    
SpawnedWeapon WeaponName // Like the function SpawnedWeapon = true / false
}

public 
Weapons(id)
{
    new 
menu menu_create("\yWeapons""menu_handler");
    
    
menu_additem(menu"M4P1""1"0); // The Default weapon
    
menu_additem(menu"AK47""2"0);
    
menu_additem(menu"AWP""3"0);
    
menu_additem(menu"Scout""4"0);
    
menu_setprop(menuMPROP_EXITMEXIT_ALL);
    
menu_display(idmenu0);
}

public 
menu_handler(idmenuitem)
{
    
// Other stuff here, no point on writing the whole code here :)



fysiks 06-10-2010 20:45

Re: Menu and spawn stuff
 
Use a global array to keep track of everybody's chosen weapon (new g_iWeaponChoice[33], index it like: g_iWeaponChoice[id]). But, when the plugin starts, set everybody's 'choice' to which ever is default.

vL. 06-10-2010 20:56

Re: Menu and spawn stuff
 
Could you please make an example or the thing? Because I'm rather new to this stuff and don't really know how to use the g_iWeaponChoice thing.

fysiks 06-10-2010 23:12

Re: Menu and spawn stuff
 
PHP Code:

new g_iWeaponChoice[33]

// plugin_init()
    
arrayset(g_iWeaponChoice133)


// Ham_Spawn
    // Can be done several ways
    
switch(g_iWeaponChoice[id])
    {
        case 
2:
        {
            
// Second weapon
        
}
        case 
3:
        {
            
// Third weapon
        
}
        default:
        {
            
// default weapon
        
}
    }

// menu handler
    // ...
    
g_iWeaponChoice[id] = key 


vL. 06-11-2010 04:41

Re: Menu and spawn stuff
 
It doesn't work like I need it to work, like when I die I do not spawn with the weapon I choose the last round.

fysiks 06-11-2010 17:06

Re: Menu and spawn stuff
 
Quote:

Originally Posted by vL. (Post 1205675)
It doesn't work like I need it to work, like when I die I do not spawn with the weapon I choose the last round.

To acheive faster results you will need to learn to post your full code. (No guaruntees on me being able to help you out on the Counter-Strike specific stuff).

vL. 06-11-2010 18:05

Re: Menu and spawn stuff
 
Ok here's the full code without the modifications you told me to make.

PHP Code:

#include <amxmodx>
#include <cstrike>
#include <fun>
#include <hamsandwich>

public plugin_init()
{
    
register_plugin"Weapons""1.0""vL." )
    
    
RegisterHam(Ham_Spawn"player""Fwd_Ham_Spawn_Post"1);
    
    
register_clcmd("say /weapons""Weapons");
}

public 
Fwd_Ham_Spawn_Post(id)
{  
    if(
is_user_connected(id) && is_user_alive(id))
    {
        
give_item(id"weapon_m4a1");
        
cs_set_user_bpammo(idCSW_M4A190);
    }
 
    return 
PLUGIN_HANDLED;
}

public 
Weapons(id)
{    
    new 
menu menu_create("\yWeapons""menu_handler");
    
    
menu_additem(menu"M4A1""1"0); // The Default weapon
    
menu_additem(menu"AK47""2"0);
    
menu_additem(menu"AWP""3"0);
    
menu_additem(menu"Scout""4"0);
    
menu_setprop(menuMPROP_EXITMEXIT_ALL);
    
menu_display(idmenu0);
}

public 
menu_handler(idmenuitem)
{
    if( 
item == MENU_EXIT )
    {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }
    
    new 
data[6], iName[64];
    new 
accesscallback;
    
    
menu_item_getinfo(menuitemaccessdata,5iName63callback);
    new 
key str_to_num(data);
    
    switch(
key)
    {
        case 
1:
        {
            
give_item(id"weapon_m4a1");
            
cs_set_user_bpammo(idCSW_M4A190);        
        }
        case 
2:
        {
            
give_item(id"weapon_ak47");
            
cs_set_user_bpammo(idCSW_AK4790);        
        }
        case 
3:
        {
            
give_item(id"weapon_awp");
            
cs_set_user_bpammo(idCSW_AWP30);        
        }
        case 
4:
        {
            
give_item(id"weapon_scout");
            
cs_set_user_bpammo(idCSW_SCOUT90);        
        }
    }
    
    
menu_destroy(menu);
    return 
PLUGIN_HANDLED;



fysiks 06-11-2010 19:10

Re: Menu and spawn stuff
 
No, show the code that doesn't work. Show what you tried. I'm not going to do it all for you.

vL. 06-11-2010 19:33

Re: Menu and spawn stuff
 
Okay, here it is.

PHP Code:

#include <amxmodx>
#include <cstrike>
#include <fun>
#include <hamsandwich>

new g_iWeaponChoice[33

public 
plugin_init()
{
    
register_plugin"Weapons""1.0""vL." )
    
    
arrayset(g_iWeaponChoice133)
    
    
RegisterHam(Ham_Spawn"player""Fwd_Ham_Spawn_Post"1);
    
    
register_clcmd("say /weapons""Weapons");
}

public 
Fwd_Ham_Spawn_Post(id)
{  
    if(
is_user_connected(id) && is_user_alive(id))
    {
        switch(
g_iWeaponChoice[id])
        {
            case 
2:
            {
                
give_item(id"weapon_ak47");
                
cs_set_user_bpammo(idCSW_AK4790); 
            }
            case 
3:
            {
                
give_item(id"weapon_awp");
                
cs_set_user_bpammo(idCSW_AWP30); 
            }
            case 
4:
            {
                
give_item(id"weapon_scout");
                
cs_set_user_bpammo(idCSW_SCOUT90); 
            }
            default:{
                
give_item(id"weapon_m4a1");
                
cs_set_user_bpammo(idCSW_M4A190); 
            }
            
        }
    }
    
    return 
PLUGIN_HANDLED;
}

public 
Weapons(id)
{    
    new 
menu menu_create("\yWeapons""menu_handler");
    
    
menu_additem(menu"M4A1""1"0); // The Default weapon
    
menu_additem(menu"AK47""2"0);
    
menu_additem(menu"AWP""3"0);
    
menu_additem(menu"Scout""4"0);
    
menu_setprop(menuMPROP_EXITMEXIT_ALL);
    
menu_display(idmenu0);
}

public 
menu_handler(idmenuitem)
{
    if( 
item == MENU_EXIT )
    {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }
    
    new 
data[6], iName[64];
    new 
accesscallback;
    
    
menu_item_getinfo(menuitemaccessdata,5iName63callback);
    new 
key str_to_num(data);
    
    
g_iWeaponChoice[id] = key  
    
    
switch(key)
    {
        case 
1:
        {
            
give_item(id"weapon_m4a1");
            
cs_set_user_bpammo(idCSW_M4A190);        
        }
        case 
2:
        {
            
give_item(id"weapon_ak47");
            
cs_set_user_bpammo(idCSW_AK4790);        
        }
        case 
3:
        {
            
give_item(id"weapon_awp");
            
cs_set_user_bpammo(idCSW_AWP30);        
        }
        case 
4:
        {
            
give_item(id"weapon_scout");
            
cs_set_user_bpammo(idCSW_SCOUT90);        
        }
        
    }    
    
menu_destroy(menu);
    return 
PLUGIN_HANDLED;



vL. 06-14-2010 01:38

Re: Menu and spawn stuff
 
Fysik any luck?


All times are GMT -4. The time now is 05:23.

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