Raised This Month: $47 Target: $400
 11% 

The menu doesn't update for every player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
snezzsp
Junior Member
Join Date: Apr 2015
Location: Madrid, Spain
Old 01-04-2017 , 07:51   The menu doesn't update for every player
Reply With Quote #1

Hi I just created a menu with all the players connected and the points each one has got. I created some code so when you have the menu opened, it updates the points each player has, but when more than 1 player opens the menu, it doesn't work for every one.

PHP Code:
new g_Points[33];
new 
name[33][32];
new 
g_maxplayers;
new 
menu;
new 
i;
new 
flag 0;

public 
plugin_init(){
    
    
register_clcmd("say /menu""playerss")
    
g_maxplayers get_maxplayers();
}

public 
playerss(id)
{
    
flag 1;
    
menu menu_create("PLAYERS :""hd_menu");
    for(
i=1<= g_maxplayersi++)
    {
        if(
is_user_connected(i)){
            
get_user_name(iname[i], 31);
            new 
message[100];
            
format(messagecharsmax(mensaje), "%s %d"name[i], g_Points[i]);
            
menu_additem(menumessage);
        }
        
    }
    
menu_setprop(menu,MPROP_EXITNAME,"Salir")
    
menu_setprop(menuMPROP_EXITMEXIT_ALL
    
menu_display(idmenu0)
    
set_task(2.0"menucreator"id);
}

public 
hd_menu(idmenuitem)
{
    if (
item == MENU_EXIT)
    {
        
flag 0;
        
menu_destroy(menu)
        return 
PLUGIN_HANDLED
    
}
    
    new 
iData[6];
    new 
iAccess;
    new 
iCallback;
    new 
iName[64];
    
menu_item_getinfo(menuitemiAccessiData5iName63iCallback);
    
flag 0;
    
client_print(id,print_chat,"You selected %s"iName);
    return 
PLUGIN_CONTINUE
}

//This makes the menu update
public menucreator(id){
    if(
flag==1){
        
menu_destroy(menu)
        
set_task(2.0"playerss"id)
    }

snezzsp is offline
Send a message via ICQ to snezzsp Send a message via Skype™ to snezzsp
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-04-2017 , 08:30   Re: The menu doesn't update for every player
Reply With Quote #2

What is that?! Please look at a tutorial which shows how to make a menu, because your code doesn't make any sense at all. First of all you're creating the menu with a global variable, so every player will recreate it when opened.
__________________


Dear admins. If somehow you managed to read this, plz fix.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
snezzsp
Junior Member
Join Date: Apr 2015
Location: Madrid, Spain
Old 01-04-2017 , 09:48   Re: The menu doesn't update for every player
Reply With Quote #3

I created a global variable to call menu in the function "menucreator", to make it update. And please stop being so rude I'm trying to learn l3l
snezzsp is offline
Send a message via ICQ to snezzsp Send a message via Skype™ to snezzsp
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Upplands Väsby, Sweden
Old 01-04-2017 , 16:45   Re: The menu doesn't update for every player
Reply With Quote #4

Of course you should be able to learn without being talked down to. I see what you wanted to create with the code. And you're not so far away from it being complete.

The thing with updating player menus is that they can change at any time. And you don't want to press the wrong player by mistake.
I would use an old menu in this case. Otherwise you can't update it without setting the page to the first again.
The whole point of the new menu style is that you create it once and get a feedback when completed. That's not what you are after. You're trying to create a more dynamic menu.
You need to consider players leaving, and others taking their place with a new UID.
A perfect menu would take all of these things into account.

I made an example that you can test alone. It will simulate players and them leaving.
I made comments throughout so you'd be able to understand what's going on.
When you're done testing, replace all the functions that end with _debug with the original ones.

Unfortunately these things might appear complicated to a beginner so I don't think I would've been able to nudge you in the right direction. That's why I created the whole thing instead.
If you have questions, please ask.

main plugin

debug.inc
__________________

Last edited by Black Rose; 01-04-2017 at 16:56.
Black Rose is offline
JoKeR LauGh
Veteran Member
Join Date: May 2011
Location: Malaysia
Old 01-05-2017 , 02:45   Re: The menu doesn't update for every player
Reply With Quote #5

Dear sir, I have a question. Maybe a bit off-topic.. makes me curious on this
PHP Code:
 register_menucmd(register_menuid("RandomMenu"), 1023"MenuHandler"); // Old menu style, has to be registred 
is it ( 2^10 ) - 1 and why? Same goes to something like
PHP Code:
g_iArray[33
why does the array need to store '33' index for client if there is only max of 32 clients in a server? or is it ( 0-32 ) which '0' is also included as starting index? I am sorry for asking this but sometimes this simple question might help others which encounter the same question as mine. Thank you, sir. Again, my apology for the off-topic question...
__________________
Quote:
Originally Posted by addons_zz View Post
Also, just to not read `the article`, read all you find. Read and read, for ever and ever. Never stop reading.
Why? Because there is not one single universal truth which holds the meaning for everything.
JoKeR LauGh is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 01-05-2017 , 04:12   Re: The menu doesn't update for every player
Reply With Quote #6

Searching is very helpful, try it.
__________________
HamletEagle is offline
klippy
AlliedModders Donor
Previously known as:
KliPPy
Join Date: May 2013
Location: Serbia
Old 01-05-2017 , 04:15   Re: The menu doesn't update for every player
Reply With Quote #7

It's 1023 in this case because that's how menu works. You provide a bitsum for keys that you want to be available in your menu (0-9). Take a look here: http://amxmodx.org/api/amxconst#menu-keys
So, if you want your menu to have only keys 1 and 3, you would pass (MENU_KEY_1 | MENU_KEY_3) to register_menucmd(). 1023 is the sum of all 10, meaning all keys are available.

In "client" arrays you want 33 because in a 33 long array indices go from 0 to 32, and players use indices 1 to 32. You could set length to 32 but then you would have to substract 1 from client index every time you want to access that array, or otherwise you would go out of bounds. 4 bytes of memory spent is nothing compared to that useless calculation. This question has also been answered multiple times on this forum.

As for other arrays, unless it's a limit in the game (like name's max length which is 32), it's just that people like working with such numbers.

Last edited by klippy; 01-05-2017 at 04:16.
klippy 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:08.


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