Raised This Month: $ Target: $400
 0% 

[HELP] Menu on new round - works only once


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 06-02-2014 , 10:45   [HELP] Menu on new round - works only once
Reply With Quote #1

Plugin requested here - https://forums.alliedmods.net/showthread.php?t=241336
Hey all! Again, I've wondering about this for hours, and no solution appeared in my head. I couldn't get that strange problem and what is it cause by, so I hope you will know. Here what's the matter. In this code, everything is OK but only for the first round. The strange is, that in other rounds the menu still appears, but no functions from it. And I think - if the handler is wrong, it should not work event the first time. But it works for the first round - and then, nothing. Here is the code, I think it could be cause by the loop trough players in the new round event. Any ideas?
PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <fun>

#define PLUGIN "Weapons Menu"
#define VERSION "1.0"
#define AUTHOR "Flicker"

new iMaxPlayers

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
iMaxPlayers get_maxplayers()
    
register_event("HLTV""NewRound""a""1=0""2=0")
}

enum _:Data
{
    
_name[32],
    
_csw[32],
    
_wname[32],
    
_ammo[32]
}

new const 
Weapons[][Data]=
{
    {
""},
    {
"M4A1"CSW_M4A1"weapon_m4a1"90},
    {
"AK47"CSW_AK47"weapon_ak47"90}
}

public 
NewRound()
{
    new 
Item[64]
    for(new 
id 1id <=iMaxPlayersid++)
    {
        new 
menu menu_create("Free VIP Guns""MenuHandler")
        for(new 
1sizeof Weaponsi++)
        {
            
formatex(Itemcharsmax(Item), "Get %s + Deagle"Weapons[i][_name])
            
menu_additem(menuItem""0)
        }
        
menu_display(idmenu0)
    }
}


public 
MenuHandler(idmenuitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(id)
        return
    }
    
    if(!
is_user_alive(id))
    {
        
client_print(idprint_chat"You should be alive to get weapons.")
        return
    }
    
    new 
key item 1
    
    strip_user_weapons
(id)
    
give_item(id"weapon_knife")
    
give_item(idWeapons[key][_wname])
    
cs_set_user_bpammo(idWeapons[key][_csw], Weapons[key][_ammo])
    
give_item(id"weapon_deagle")
    
cs_set_user_bpammo(idCSW_DEAGLE35)
    

Whatever I choose - wokrs first round. And then, whatever I choose - nothing happens, like in the next round the handler is excluded somehow, don't know...
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
DavidJr
Senior Member
Join Date: Apr 2012
Old 06-02-2014 , 10:59   Re: [HELP] Menu on new round - works only once
Reply With Quote #2

I ever experienced the same problem with you in my vote kick plugin. Try to remove this:

PHP Code:
if(item == MENU_EXIT
    { 
        
menu_destroy(id
        return 
    } 
__________________
What are you looking for here?
DavidJr is offline
NikKOo31
Senior Member
Join Date: May 2013
Location: Home
Old 06-02-2014 , 11:01   Re: [HELP] Menu on new round - works only once
Reply With Quote #3

You should use get_players or spawn

PS: Hey ^_^
NikKOo31 is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 06-02-2014 , 11:04   Re: [HELP] Menu on new round - works only once
Reply With Quote #4

Allright, it worked. Thanks! But, I've never had problem with this one, I even know, that it needs to be there, because sometimes the menues fu*k up and choose random item, if this check is not there. Strange... Can someone explain something more about this problem?
EDIT: To response on nicko's post. Allright, after I read up all the sh*t about these loops, I've decided, that I will folow exolent's method. Because in one thread, he explained something like this is the best way, but I couldn find it right now. So, is this really the best way and is there any better way to loop trough all connnected players on the moment?
__________________

Last edited by Flick3rR; 06-02-2014 at 11:09.
Flick3rR is offline
Send a message via Skype™ to Flick3rR
DavidJr
Senior Member
Join Date: Apr 2012
Old 06-02-2014 , 11:09   Re: [HELP] Menu on new round - works only once
Reply With Quote #5

See, menu index is the same to all players, so when one player destroy it, the menu will be destroyed. Other players can't choose because it already destroyed

PHP Code:
new Item[64
    for(new 
id 1id <=iMaxPlayersid++) 
    { 
        new 
menu menu_create("Free VIP Guns""MenuHandler"
        for(new 
1sizeof Weaponsi++) 
        { 
            
formatex(Itemcharsmax(Item), "Get %s + Deagle"Weapons[i][_name]) 
            
menu_additem(menuItem""0
        } 
        
menu_display(idmenu0
    } 
__________________
What are you looking for here?
DavidJr is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 06-02-2014 , 11:12   Re: [HELP] Menu on new round - works only once
Reply With Quote #6

Isn't the menu separate for each of the players (for i = 1, to maxplayers). Also, I tried this at my own, all alone and noone in the server. Do you think this is the really problem?
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
DavidJr
Senior Member
Join Date: Apr 2012
Old 06-02-2014 , 11:16   Re: [HELP] Menu on new round - works only once
Reply With Quote #7

No, because your variable

PHP Code:
new menu 
isn't array.

You can make it like this I guess:

PHP Code:
for(new id 1id <=iMaxPlayersid++) 
    { 
        new 
menu[iMaxPlayers]
        for(new 
1sizeof Weaponsi++) 
        { 
            
iMenu[id] = menu_create("Free VIP Guns""MenuHandler"
            
formatex(Itemcharsmax(Item), "Get %s + Deagle"Weapons[i][_name]) 
            
menu_additem(menuItem""0
            
menu_display(idmenu[id], 0)
        } 
         
    } 
Yes that's the problem, I tested it in listenserver without anyone, works fine. When I tested it in HLDS with other players, the problem is same as yours.
__________________
What are you looking for here?

Last edited by DavidJr; 06-02-2014 at 11:18.
DavidJr is offline
.Dare Devil.
Veteran Member
Join Date: Sep 2010
Old 06-02-2014 , 12:53   Re: [HELP] Menu on new round - works only once
Reply With Quote #8

Quote:
Originally Posted by DavidJr View Post
No, because your variable

PHP Code:
new menu 
isn't array.

You can make it like this I guess:

PHP Code:
for(new id 1id <=iMaxPlayersid++) 
    { 
        new 
menu[iMaxPlayers]
        for(new 
1sizeof Weaponsi++) 
        { 
            
iMenu[id] = menu_create("Free VIP Guns""MenuHandler"
            
formatex(Itemcharsmax(Item), "Get %s + Deagle"Weapons[i][_name]) 
            
menu_additem(menuItem""0
            
menu_display(idmenu[id], 0)
        } 
         
    } 
Yes that's the problem, I tested it in listenserver without anyone, works fine. When I tested it in HLDS with other players, the problem is same as yours.
wtf are you talking about?
There's no needs for array.


To OP:
PHP Code:
public MenuHandler(idmenuitem

    if(
item == MENU_EXIT
    { 
        
menu_destroy(id
Should it be:
PHP Code:
public MenuHandler(idmenuitem

    if(
item == MENU_EXIT
    { 
        
menu_destroy(menu
?

Magic right?

Last edited by .Dare Devil.; 06-02-2014 at 12:53.
.Dare Devil. is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 06-02-2014 , 13:01   Re: [HELP] Menu on new round - works only once
Reply With Quote #9

Wut, wut, dafuq wut. Didn't see that, I'm such a dumbf*ck... God, could anyone delete this thread? Thanks, Dare Devil, for that note, I was never gonna get it.
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
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 09:40.


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