AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP] Menu on new round - works only once (https://forums.alliedmods.net/showthread.php?t=241365)

Flick3rR 06-02-2014 10:45

[HELP] Menu on new round - works only once
 
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...

DavidJr 06-02-2014 10:59

Re: [HELP] Menu on new round - works only once
 
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 
    } 


NikKOo31 06-02-2014 11:01

Re: [HELP] Menu on new round - works only once
 
You should use get_players or spawn :D

PS: Hey ^_^

Flick3rR 06-02-2014 11:04

Re: [HELP] Menu on new round - works only once
 
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?

DavidJr 06-02-2014 11:09

Re: [HELP] Menu on new round - works only once
 
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 :3

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
    } 


Flick3rR 06-02-2014 11:12

Re: [HELP] Menu on new round - works only once
 
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?

DavidJr 06-02-2014 11:16

Re: [HELP] Menu on new round - works only once
 
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.

.Dare Devil. 06-02-2014 12:53

Re: [HELP] Menu on new round - works only once
 
Quote:

Originally Posted by DavidJr (Post 2145789)
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?

Flick3rR 06-02-2014 13:01

Re: [HELP] Menu on new round - works only once
 
Wut, wut, dafuq wut. :D :D 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.


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

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