AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Solved] How to save a player choice? (https://forums.alliedmods.net/showthread.php?t=160197)

ImXinR 06-26-2011 03:32

[Solved] How to save a player choice?
 
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.

fysiks 06-26-2011 04:03

Re: How to save a player choice?
 
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>

ImXinR 06-26-2011 04:27

Re: How to save a player choice?
 
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



fysiks 06-26-2011 15:27

Re: How to save a player choice?
 
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.

FoxueR 06-26-2011 22:22

Re: How to save a player choice?
 
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



fysiks 06-27-2011 02:37

Re: How to save a player choice?
 
Quote:

Originally Posted by FoxueR (Post 1497481)
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.

ImXinR 06-27-2011 03:19

Re: How to save a player choice?
 
Orh .. But I typed like how I did in the code above but doesn't work :(

fysiks 06-27-2011 04:29

Re: How to save a player choice?
 
Quote:

Originally Posted by ImXinR (Post 1497584)
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.

ImXinR 06-27-2011 06:15

Re: How to save a player choice?
 
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    



fysiks 06-27-2011 07:35

Re: How to save a player choice?
 
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().


All times are GMT -4. The time now is 18:32.

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