AlliedModders

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

victorngl 12-19-2011 18:07

Store Weapon Help
 
I need help with the menu.
I need him to save the previous weapons
if someone could help me.




PHP Code:

public first(id)  
{  
    new 
menu menu_create("\yPrimary Weapons:""first_handle")  
    
menu_additem(menu"\wNew weapons""1"0)  
    
menu_additem(menu"\wLast weapons""2"0)  
      
    
menu_setprop(menuMPROP_EXITMEXIT_ALL)  

    
menu_display(idmenu0)  
      
}  
public 
first_handle(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:{  
                
second(id
        }  
        case 
2:{  
                         !!!!!!!!!!!!!!!!!!                 !!!!!!!!!!!!!!!!! 
              !!!!!!!!!!!!!!!!  
That STORED WEAPON ://///// !!!!!!!!!!!! 
        
}  
    }      
    
menu_destroy(menu)  
    return 
PLUGIN_HANDLED  

public 
second(id)  
{  
    new 
menu menu_create("\yPrimary Weapons:""second_handle")  
    
menu_additem(menu"\wAK47""1"0)  
    
menu_additem(menu"\wM4A1""2"0)  
      
    
menu_setprop(menuMPROP_EXITMEXIT_ALL)  

    
menu_display(idmenu0)  
      
}  
public 
second_handle(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(AK47-EXAMPLE)  
        }  
        case 
2:{  
                
give item(M4a1-EXAMPLE)  
        }  
    }      
    
menu_destroy(menu)  
    return 
PLUGIN_HANDLED  



fysiks 12-19-2011 19:22

Re: Store Weapon Help
 
Use a global variable (an array, one cell for each player) to store the option that they chose. Then, the next time you need to know what they chose last time you have it in that variable. This method will work for single weapons.

If you only need two weapons then you can use two arrays. If you use more then something different would probably be better.

victorngl 12-19-2011 20:26

Re: Store Weapon Help
 
I am beginner.
if you can send me some example.
please

fysiks 12-19-2011 23:12

Re: Store Weapon Help
 
PHP Code:

new iLastChoice[33]

// handler function
    // switch
        
case 1:
        {
            
iLastWeapon[id] = 1
        
}
        case 
2:
        {
            
iLastWeapon[id] = 2
        
}
        
//etc

// then use iLastChoice[id] to know what the player's last choice was 


victorngl 12-19-2011 23:32

Re: Store Weapon Help
 
did not work

I did correctly?



PHP Code:


new g_StoredWeapon[33];  
public 
first(id

    new 
menu menu_create("\yPrimary Weapons:""first_handle"
    
menu_additem(menu"\wNew weapons""1"0
    
menu_additem(menu"\wLast weapons""2"0
    
    
menu_setprop(menuMPROP_EXITMEXIT_ALL
    
    
menu_display(idmenu0
    

public 
first_handle(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:{ 
            
second(id)
        } 
        case 
2:{ 
            
g_StoredWeapon[id]
        } 
    }     
    
menu_destroy(menu
    return 
PLUGIN_HANDLED 
}
public 
second(id

    new 
menu menu_create("\yPrimary Weapons:""second_handle"
    
menu_additem(menu"\wAK47""1"0
    
menu_additem(menu"\wM4A1""2"0
    
    
menu_setprop(menuMPROP_EXITMEXIT_ALL
    
    
menu_display(idmenu0
    

public 
second_handle(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(AK47-EXAMPLE
            
g_StoredWeapon[id] = 1
        } 
        case 
2:{ 
            
give item(M4a1-EXAMPLE
            
g_StoredWeapon[id] = 2
        } 
    }     
    
menu_destroy(menu
    return 
PLUGIN_HANDLED 



fysiks 12-20-2011 00:38

Re: Store Weapon Help
 
  1. Show the full code with everything working.
  2. Show the full code with the new code.
  3. You can't just put iLastChoice[id] in the middle of nowhere and expect it to do anything.
  4. Explain exactly what you want to happen.

victorngl 12-20-2011 00:47

Re: Store Weapon Help
 
Ok......

Full code

/* Plugin generated by AMXX-Studio */

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <fun>

#define PLUGIN "Prymary Guns for SP"
#define VERSION "1.0"
#define AUTHOR "Red #"


public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_clcmd"say /guns" "first" )
    
}

public 
first(id)  
{  
    new 
menu menu_create("\yPrimary Weapons:""first_handle")  
    
menu_additem(menu"\wNew weapons""1"0)  
    
menu_additem(menu"\wLast weapons""2"0)  
      
    
menu_setprop(menuMPROP_EXITMEXIT_ALL)  

    
menu_display(idmenu0)  
      
}  
public 
first_handle(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:{  
                
second(id
        }  
        case 
2:{  
               
           
SAVE WEAPON
        
}  
    }      
    
menu_destroy(menu)  
    return 
PLUGIN_HANDLED  

public 
second(id)  
{  
    new 
menu menu_create("\yPrimary Weapons:""second_handle")  
    
menu_additem(menu"\wAK47""1"0)  
    
menu_additem(menu"\wM4A1""2"0)  
      
    
menu_setprop(menuMPROP_EXITMEXIT_ALL)  

    
menu_display(idmenu0)  
      
}  
public 
second_handle(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_ak47")   
        }  
        case 
2:{  
                
give_item(id"weapon_m4a1")  
        }  
    }      
    
menu_destroy(menu)  
    return 
PLUGIN_HANDLED  


I need the player to choose the weapons for the primary menu
then he wants the same option, select "Last weapons" and earn the same gun that he got earlier

I do not quite understand your explanation.
be able to help me again, I'll be very grateful

sorry my bad english


All times are GMT -4. The time now is 11:46.

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