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

[Solved] How to save a player choice?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ImXinR
Member
Join Date: Dec 2010
Old 06-26-2011 , 03:32   [Solved] How to save a player choice?
Reply With Quote #1

Just like the topic , How do I save a player's Menu Selection choice ? If the player choose option 1 , Then the next round , The thing happening in Option 1 will not keep repeating and will remember the choice.
__________________
Sometimes , Life Sucks .. Don't You Agree? But ,
Listening To Music Make Us Feel Better

Last edited by ImXinR; 06-28-2011 at 03:35.
ImXinR is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-26-2011 , 04:03   Re: How to save a player choice?
Reply With Quote #2

Use a global array, g_myarray[33]. Then you need to reset it on client_connect().

Set it using

g_myarray[id] = <integer representing players selection here>
__________________
fysiks is offline
ImXinR
Member
Join Date: Dec 2010
Old 06-26-2011 , 04:27   Re: How to save a player choice?
Reply With Quote #3

Like > ?
PHP Code:
new g_myarray[33
PHP Code:
case :
{
// Stuff ~~
g_myarray[id] = 1
}
case 
:
{
// Stuff ~~
g_myarray[id] = 2
}
case 
:
{
// Stuff ~~
g_myarray[id] = 3

PHP Code:
public client_connect(id)
{
    
g_myarray[id] = 1

__________________
Sometimes , Life Sucks .. Don't You Agree? But ,
Listening To Music Make Us Feel Better
ImXinR is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-26-2011 , 15:27   Re: How to save a player choice?
Reply With Quote #4

Yeah, but, in client_connect I would set it to 0 to show that the player has not a made a selection yet unless you want 1 to be the default for everybody and they can change it with the menu.
__________________
fysiks is offline
FoxueR
Senior Member
Join Date: Jun 2011
Old 06-26-2011 , 22:22   Re: How to save a player choice?
Reply With Quote #5

Menu items start at 0, so it's probably better to initialize the choice to -1 or increment the menu items before storing them.

Also, notice there's a consistency in your code:

PHP Code:
switch ( item )
{
    case 
:
    {
        
g_myarray[id] = 1
    
}
    case 
:
    {
        
g_myarray[id] = 2
    
}
    case 
:
    {
        
g_myarray[id] = 3
    
}

Notice how, on case 2, you set g_myarray[id] to 2, etc. In this case, your code can be generalized to:

PHP Code:
g_myarray[id] = item 
You can, of course, add extra checks like:
PHP Code:
if ( item && item )
{
    
g_myarray[id] = item

__________________
¯\_(ツ)_/¯
FoxueR is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-27-2011 , 02:37   Re: How to save a player choice?
Reply With Quote #6

Quote:
Originally Posted by FoxueR View Post
Menu items start at 0, so it's probably better to initialize the choice to -1 or increment the menu items before storing them.
That is entirely upto the coder. You don't have to use the key (item) variable as the identifier. If option 0 is coded as "having not selected anything yet" then it will work just fine.
__________________
fysiks is offline
ImXinR
Member
Join Date: Dec 2010
Old 06-27-2011 , 03:19   Re: How to save a player choice?
Reply With Quote #7

Orh .. But I typed like how I did in the code above but doesn't work
__________________
Sometimes , Life Sucks .. Don't You Agree? But ,
Listening To Music Make Us Feel Better
ImXinR is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-27-2011 , 04:29   Re: How to save a player choice?
Reply With Quote #8

Quote:
Originally Posted by ImXinR View Post
Orh .. But I typed like how I did in the code above but doesn't work
Show the WHOLE code. If it's longer than a hundred lines then post it as an attachment.
__________________
fysiks is offline
ImXinR
Member
Join Date: Dec 2010
Old 06-27-2011 , 06:15   Re: How to save a player choice?
Reply With Quote #9

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <colorchat>
#include <cstrike>
#include <fun>
#include <hamsandwich>

#define PLUGIN "TestMenu"
#define VERSION "1.0"
#define AUTHOR "Unknown"

new menu_activate [33]
new 
g_iPlayerSetting[33]
new 
g_myarray[33]

public 
plugin_init()
{
      
register_plugin(PLUGINVERSIONAUTHOR)
    
      
register_clcmd"say /menu","Pre_AwesomeMenu");
}
public 
Pre_AwesomeMenu (id)

    
menu_activate[id] = 1
    ColorChat
(idNORMAL,"You have renabled your menu for the next round.")
    return 
PLUGIN_HANDLED
}
public 
AwesomeMenu(id)
{
    new 
menu menu_create("\rChoose Your Class :""menu_handler");

    
menu_additem(menu"\yAvoider""1"0);
    
menu_additem(menu"\yRunner""2"0);
    
menu_additem(menu"\yGrenader""3"0);

    
menu_setprop(menuMPROP_EXITMEXIT_ALL);
        
    
menu_display(idmenu0);
}
public 
menu_handler(idmenuitem)
{
    
menu_activate[id] = 0
    
if( item == MENU_EXIT )
    {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }
    
g_iPlayerSetting[id] = -1
    
new data[6], szName[64];
    new 
accesscallback;
    
    
    
menu_item_getinfo(menuitemaccessdata,charsmax(data), szName,charsmax(szName), callback);
    
    new 
key str_to_num(data);
    
    if ( 
cs_get_user_team(id) == CS_TEAM_T 
        switch(
key)
    {
        case 
1:
        {
            
strip_user_weapons(id
            
give_item(id"weapon_flashbang")
            
give_item(id"weapon_flashbang")
            
g_myarray[id] = 1
            menu_destroy
(menu);
            return 
PLUGIN_HANDLED;
        }
        case 
2:
        { 
            
strip_user_weapons(id
            new 
wep give_item(id"weapon_scout");
            
cs_set_weapon_ammo(wep0); 
            
get_user_health(id)
            
set_user_health(id 200)
            
g_myarray[id] = 2    
        
}
        case 
3
        {
            
strip_user_weapons(id)
            
give_item(id"weapon_flashbang")
            
give_item(id"weapon_hegrenade")                    
            
g_myarray[id] = 3    
        
}
    }
    
    
menu_destroy(menu);
    return 
PLUGIN_HANDLED;
}
public 
FwdPlayerSpawn(id)
{
    if(
menu_activate[id] == 1)
    {
        
set_task(0.4,"AwesomeMenu",id)
    }
    return 
PLUGIN_CONTINUE
}
public 
client_disconnect(id)
{
    
menu_activate[id] = 0
}
public 
client_connect(id)
{
    
menu_activate[id] = 1
    g_myarray
[id] = 1    

__________________
Sometimes , Life Sucks .. Don't You Agree? But ,
Listening To Music Make Us Feel Better
ImXinR is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-27-2011 , 07:35   Re: How to save a player choice?
Reply With Quote #10

1. FwdPlayerSpawn() is never executed. You need to register the spawn with ham.
2. Don't use a set_task for showing the menu. Just call the function.
3. You don't need client_disconnect since you reset the values in client_connect().
__________________
fysiks 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 20:56.


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