Raised This Month: $32 Target: $400
 8% 

[SOLVED] Loop display menu


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Zack771
Senior Member
Join Date: Apr 2012
Location: 192.168.1.16
Old 05-06-2014 , 07:55   [SOLVED] Loop display menu
Reply With Quote #1

Hi,

I've made a loop to display a menu to all clients alive, to give them a weapon :
PHP Code:
BuildMenu() {
   
//creating handle and adding items
    
for(new i=1;i<=MaxClients;i++) {
        if(
IsClientInGame(i) &&(i==myVar || (GetClientTeam(i)==CS_TEAM_CT && IsPlayerAlive(i)))) {
            
DisplayMenu(menu,i,MenuTime);
        }
    }

The menu is displayed to all clients, but only the first personne who Select an item in the menu have a weapon who is spawn. The other select an item but the menu just closed.

Does somebody have an idea please ?
__________________
"Embrace your dreams, and whatever happend protect your honor"
Zack Fair

Last edited by Zack771; 05-07-2014 at 15:24. Reason: Solved subject.
Zack771 is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 05-06-2014 , 08:16   Re: Loop display menu
Reply With Quote #2

I guess it's because:
  1. you create one menu (so on instance of menu handler function for all players)
  2. this menu you show to all players (the same instance of menu handler for all players)
  3. when one player select an item in menu
    1. menu handler function is called and you do some action
    2. menu handler is closed
  4. when another player select an item in menu
    1. instance of menu handler is already closed
    2. so no action could be taken...

So I guess the only solution is to make menu for each player.
KissLick is offline
Zack771
Senior Member
Join Date: Apr 2012
Location: 192.168.1.16
Old 05-06-2014 , 10:38   Re: Loop display menu
Reply With Quote #3

Ok so my loop need to be like that :
PHP Code:
BuildMenu() {
    for(new 
i=1;i<=MaxClients;i++) {
        if(
IsClientInGame(i) &&(i==myVar || (GetClientTeam(i)==CS_TEAM_CT && IsPlayerAlive(i)))) {
            
//create handle and adding item
            
DisplayMenu(menu,i,MenuTime);
        }
    } 
?
__________________
"Embrace your dreams, and whatever happend protect your honor"
Zack Fair

Last edited by Zack771; 05-06-2014 at 10:38.
Zack771 is offline
Doodil
Senior Member
Join Date: Mar 2012
Old 05-06-2014 , 10:42   Re: Loop display menu
Reply With Quote #4

no, you need to create 1 menu variable for each player, copy the code where you create the menu variable into your function and you should be fine.
Doodil is offline
Zack771
Senior Member
Join Date: Apr 2012
Location: 192.168.1.16
Old 05-06-2014 , 11:03   Re: Loop display menu
Reply With Quote #5

Quote:
Originally Posted by Doodil View Post
no, you need to create 1 menu variable for each player, copy the code where you create the menu variable into your function and you should be fine.
But isn't it what i'm actually doing here ?
For each new player (if he pass the test), i create a new Handle:menu = CreateMenu(etc...) then set menu, add item and display it to the player.

Or maybe i've not understand what you want to mean ?
__________________
"Embrace your dreams, and whatever happend protect your honor"
Zack Fair
Zack771 is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 05-06-2014 , 13:26   Re: Loop display menu
Reply With Quote #6

I think this should be OK

PHP Code:
BuildMenu() {
    for(new 
i=1;i<=MaxClients;i++) {
        if(
IsClientInGame(i) &&(i==myVar || (GetClientTeam(i)==CS_TEAM_CT && IsPlayerAlive(i)))) {
            
// create handle and adding item, so ->
            // new Handle:menu = CreateMenu(Menu_Handler)
            // add items to menu
            
DisplayMenu(menu,i,MenuTime);
        }
    }

KissLick is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 05-06-2014 , 13:47   Re: Loop display menu
Reply With Quote #7

It'd help if you showed us the menu code.

Incidentally, don't call CloseHandle in the handler or else you'll get the exact problem you're describing.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 05-06-2014 at 13:49.
Powerlord is offline
Zack771
Senior Member
Join Date: Apr 2012
Location: 192.168.1.16
Old 05-06-2014 , 15:22   Re: Loop display menu
Reply With Quote #8

Quote:
Originally Posted by KissLick View Post
I think this should be OK

PHP Code:
BuildMenu() {
    for(new 
i=1;i<=MaxClients;i++) {
        if(
IsClientInGame(i) &&(i==myVar || (GetClientTeam(i)==CS_TEAM_CT && IsPlayerAlive(i)))) {
            
// create handle and adding item, so ->
            // new Handle:menu = CreateMenu(Menu_Handler)
            // add items to menu
            
DisplayMenu(menu,i,MenuTime);
        }
    }

Ok, i try this.

Quote:
Originally Posted by Powerlord View Post
It'd help if you showed us the menu code.

Incidentally, don't call CloseHandle in the handler or else you'll get the exact problem you're describing.
I just close Handle if player close the menu :
PHP Code:
public MenuWeapon(Handle:menuMenuAction:action,param1,param2) {
    switch(
action) {
        case 
MenuAction_Select:
        {
            if(
param1>&& IsClientInGame(param1) && IsPlayerAlive(param1)) {
                
decl String:info[32];
                
GetMenuItem(menu,param2,info,sizeof(info));
                if(
StrEqual(info,"m4")) {
                    
GivePlayerItem(param1,"weapon_m4a1");
                } else if(
StrEqual(info,"ak")) {
                    
GivePlayerItem(param1,"weapon_ak47");
                } else if(
StrEqual(info,"awp")) {
                    
GivePlayerItem(param1,"weapon_awp");
                } else if(
StrEqual(info,"famas")) {
                    
GivePlayerItem(param1,"weapon_famas");
                }
            }
        }
        case 
MenuAction_End:
        {
            if(
param1>&& IsClientInGame(param1) && IsPlayerAlive(param1)) {
                
GivePlayerItem(param1,"weapon_m4a1");
            }
            if(
menu!=INVALID_HANDLE) {
                
CloseHandle(menu);
            }
        }
    }

__________________
"Embrace your dreams, and whatever happend protect your honor"
Zack Fair
Zack771 is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 05-06-2014 , 16:29   Re: Loop display menu
Reply With Quote #9

OK, here's the deal: You're displaying the same menu to more than one person and the SourceMod menu system only allows you to send the display command to one person at a time (votes are the exception).

The first time someone closes the menu (by selecting an item or cancelling the menu), MenuAction_End gets called and you close the menu handle. This means that the server will no longer process anything for that menu, which is why none of the other players can select anything.

Incidentally, this is exactly what KissLick told you was happening.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 05-06-2014 at 16:30.
Powerlord is offline
Doodil
Senior Member
Join Date: Mar 2012
Old 05-07-2014 , 02:39   Re: Loop display menu
Reply With Quote #10

Quote:
Originally Posted by Powerlord View Post
OK, here's the deal: You're displaying the same menu to more than one person and the SourceMod menu system only allows you to send the display command to one person at a time (votes are the exception).

The first time someone closes the menu (by selecting an item or cancelling the menu), MenuAction_End gets called and you close the menu handle. This means that the server will no longer process anything for that menu, which is why none of the other players can select anything.

Incidentally, this is exactly what KissLick told you was happening.
You did the same mistake I did. He says he's creating new menus, he just removed the code in the quote and replaced it with a comment saying that he does.

I guess you should post the part where you actually create the menu, maybe we can find the error then
Doodil 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 10:40.


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