Raised This Month: $ Target: $400
 0% 

Solved Menus, adding one choice per player


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
condolent
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
Old 06-10-2017 , 19:03   Menus, adding one choice per player
Reply With Quote #1

Hello,

How can I add a item to the menu for each player online?
I tried this:
PHP Code:
for(new 1<= MaxClientsi++) {
    
char name[MAX_NAME_LENGTH];
    
GetClientName(inamesizeof(name));
    
    if(
IsClientInGame(i)) {
        
// Add to menu
        
userListMenu.AddItem(userCHOICEname);
    }

but that doesn't work and makes the menu not show up..
__________________

Last edited by condolent; 06-12-2017 at 16:14.
condolent is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 06-10-2017 , 19:32   Re: Menus, adding one choice per player
Reply With Quote #2

Gonna need to see more code than that, show the entire menu displaying code, the stuff you posted seems fine

EDIT: yea nvm I'm big dumb

Last edited by hmmmmm; 06-11-2017 at 20:19.
hmmmmm is offline
Deathknife
Senior Member
Join Date: Aug 2014
Old 06-10-2017 , 20:41   Re: Menus, adding one choice per player
Reply With Quote #3

Only get client's name after checking that he's in game. You are trying to get a name of non existing player and causes an error, which is why your menu doesn't show up.
__________________
Deathknife is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 06-11-2017 , 02:20   Re: Menus, adding one choice per player
Reply With Quote #4

Deathknife is right and you should be able to see the error in your server console every time you try to run that code. However, you should use either AddTargetsToMenu or AddTargetsToMenu2 instead anyway if you're only displaying names.
Fyren is offline
condolent
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
Old 06-11-2017 , 06:58   Re: Menus, adding one choice per player
Reply With Quote #5

Quote:
Originally Posted by Fyren View Post
Deathknife is right and you should be able to see the error in your server console every time you try to run that code. However, you should use either AddTargetsToMenu or AddTargetsToMenu2 instead anyway if you're only displaying names.
How would I go about using AddTargetsToMenu?

This is what I came up with:
PHP Code:
public Action sm_checkrespawn(int clientint args) {
    
    
Menu userListMenu = new Menu(userListHandlerMENU_ACTIONS_ALL);
    
userListMenu.SetTitle("Check respawns left");
    for(new 
1<= MaxClientsi++) {
        
char name[MAX_NAME_LENGTH];
        
        if(
IsClientInGame(i)) {
            
GetClientName(inamesizeof(name));
            
//userListMenu.AddItem(userCHOICE, name);
            
userListMenu.AddTargetsToMenu(userListHandleritruefalse);
        }
    }
    
userListMenu.Display(client20);
    
    return 
Plugin_Handled;

But that didn't really seem to work. It's telling me "Cannot find method or property Menu.AddTargetsToMenu"
__________________
condolent is offline
Deathknife
Senior Member
Join Date: Aug 2014
Old 06-11-2017 , 18:04   Re: Menus, adding one choice per player
Reply With Quote #6

Quote:
Originally Posted by condolent View Post
How would I go about using AddTargetsToMenu?

This is what I came up with:
PHP Code:
public Action sm_checkrespawn(int clientint args) {
    
    
Menu userListMenu = new Menu(userListHandlerMENU_ACTIONS_ALL);
    
userListMenu.SetTitle("Check respawns left");
    for(new 
1<= MaxClientsi++) {
        
char name[MAX_NAME_LENGTH];
        
        if(
IsClientInGame(i)) {
            
GetClientName(inamesizeof(name));
            
//userListMenu.AddItem(userCHOICE, name);
            
userListMenu.AddTargetsToMenu(userListHandleritruefalse);
        }
    }
    
userListMenu.Display(client20);
    
    return 
Plugin_Handled;

But that didn't really seem to work. It's telling me "Cannot find method or property Menu.AddTargetsToMenu"
AddTargetsToMenu isn't a Menu function. It does not belong to any method map. To use it you would do:
PHP Code:
AddTargetsToMenu(userListMenuitruefalse); 
Take a look at: https://sm.alliedmods.net/new-api/ad...dTargetsToMenu

Also, if you are using AddTargetsToMenu you do not loop through players. It will add every player (respecting immunity) to the menu already.
__________________
Deathknife is offline
condolent
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
Old 06-12-2017 , 02:55   Re: Menus, adding one choice per player
Reply With Quote #7

Okay so this is what it looks like in the end:
PHP Code:
public Action sm_checkrespawn(int clientint args) {
    
    
Menu usrMenu = new Menu(userMenuHandlerMENU_ACTIONS_ALL);
    
usrMenu.SetTitle("Check respawns");
    
    
AddTargetsToMenu(usrMenu0truefalse);
    
    
usrMenu.Display(client20);
    
    return 
Plugin_Handled;
    

So I don't need to get every player with the loop and with 0 in the AddTargetsToMenu, I should be getting every single player while ignoring immunity. Not tested but in theory this should work just fine!

How would I get which user was selected in MenuAction_Select? Specifically need the selected user's userID to perform a value-check in an array.
__________________

Last edited by condolent; 06-12-2017 at 02:58.
condolent is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 06-12-2017 , 04:01   Re: Menus, adding one choice per player
Reply With Quote #8

https://sm.alliedmods.net/new-api/ad...dTargetsToMenu

"Each item contains the userid as a string for its info"

So you can just do GetMenuItem and should give you the user id
hmmmmm is offline
condolent
AlliedModders Donor
Join Date: Jan 2016
Location: gc_sLocation;
Old 06-12-2017 , 04:25   Re: Menus, adding one choice per player
Reply With Quote #9

Quote:
Originally Posted by hmmmmm View Post
https://sm.alliedmods.net/new-api/ad...dTargetsToMenu

"Each item contains the userid as a string for its info"

So you can just do GetMenuItem and should give you the user id
Isn't GetMenuItem a boolean?
__________________
condolent is offline
fiction
Member
Join Date: May 2017
Old 06-12-2017 , 04:44   Re: Menus, adding one choice per player
Reply With Quote #10

Quote:
Originally Posted by condolent View Post
Isn't GetMenuItem a boolean?
The 2nd argument will contain the client's userid and the 5th will contain the name/display string.
PHP Code:
bool GetItem(int positionchar[] infoBufint infoBufLenint &stylechar[] dispBufint dispBufLen)

[...]

char sInfo[64];
if(
menu.GetItem(param2sInfosizeof(sInfo)))
{
    
GetClientOfUserId(StringToInt(sInfo));


Last edited by fiction; 06-12-2017 at 04:51.
fiction is offline
Reply



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 07:08.


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