AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   The menu doesn't update for every player (https://forums.alliedmods.net/showthread.php?t=292359)

snezzsp 01-04-2017 07:51

The menu doesn't update for every player
 
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)
    }



OciXCrom 01-04-2017 08:30

Re: The menu doesn't update for every player
 
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.

snezzsp 01-04-2017 09:48

Re: The menu doesn't update for every player
 
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

Black Rose 01-04-2017 16:45

Re: The menu doesn't update for every player
 
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

JoKeR LauGh 01-05-2017 02:45

Re: The menu doesn't update for every player
 
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...

HamletEagle 01-05-2017 04:12

Re: The menu doesn't update for every player
 
Searching is very helpful, try it.

klippy 01-05-2017 04:15

Re: The menu doesn't update for every player
 
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.


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

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