AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   playermenu help (https://forums.alliedmods.net/showthread.php?t=168632)

plowed 10-01-2011 18:46

playermenu help
 
hi there.

I start making a menu that listen all players on the server. After a player on the menu is choosen a submenu open (which is not fully included here) where the submenu show some amounts ( 5, 10, 20, 50, 100 )

My problem is: I cant hold the id (in my code the var: tempid) of the player I choose in the menu through to the submenu.

PHP Code:

#include <amxmodx>
#include <fun>
#include <zp50_ammopacks>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "plowed"

#define MAXAMOUNT 5

new g_ammoAmount[MAXAMOUNT][] = {
    
5,
    
10
    
20,
    
50
    
100
}


public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_clcmd("say /menu""donateMenu")    
}

public 
donateMenu(id) {
    new 
menu menu_create("Donate menu:","menu_handler")
    
    new 
players[32], pnumtempid
    
new szName[32], szTempid[10]
    new 
ammos[32]
    new 
desc[64]
    
get_players(playerspnum)
    
    for(new 
0pnumi++) {
        
tempid players[i]
        
ammos[tempid] = zp_ammopacks_get(tempid)
        
        
get_user_name(tempidszNamecharsmax(szName))
        
formatex(desccharsmax(desc), "\w%s      \rAmmos: \y%d"szNameammos[tempid])
        
num_to_str(tempidszTempidcharsmax(szTempid))
        
menu_additem(menudescszTempid0)
    }
    
menu_display(idmenu0)
}
    
public  
menu_handler(idmenuitem) {
    if(
item == MENU_EXIT) {
        
menu_destroy(menu)
        return 
PLUGIN_HANDLED
    
}
    
    new 
data[6], szName[64]
    new 
accesscallback
    menu_item_getinfo
(menuitemaccessdatacharsmax(data), szNamecharsmax(szName), callback)
    new 
tempid str_to_num(data)
    new 
Title[128], name[32], Auswahl[20]
    
get_user_name(tempidnamecharsmax(name))
    
formatex(Titlecharsmax(Title), "Donate ammos to %s"name)
    
    
    new 
submenu menu_create(Title"submenu_handler")
    
    for(new 
isizeof g_ammoAmount;i++) {
    
formatex(Auswahlcharsmax(Auswahl),"\y%d\w HP"g_ammoAmount[i])
    
menu_additem(submenuAuswahl"i"0)
    }
    
menu_setprop(submenuMPROP_EXITMEXIT_ALL)
    
menu_display(idsubmenu0)
    
    return 
PLUGIN_HANDLED
}

public 
submenu_handler(idsubmenuitem) {
    
    if(
item == MENU_EXIT) {
        
menu_destroy(submenu)
        return 
PLUGIN_HANDLED
    
}
    
    new 
data[6], szName[64]
    new 
accesscallback
    
    menu_item_getinfo
(submenuitemaccessdata,charsmax(data), szName,charsmax(szName), callback);
    
    new 
key str_to_num(data)
    
    switch(
key)
    {
     case 
1:
    {
    
//ex set_user_health of the player I choose..BUT I dont know how to get on that playerid I choose :S:DSX
    
}
    case 
2:
    {
        
    }
    case 
3
    {

    }
    case 
4
    {

    }
    case 
5
    {

    }
    }


some help or advices would be nice !

[PUPPETS] Scooter 10-02-2011 07:33

Re: playermenu help
 
Quote:

menu_additem(submenu, Auswahl, "i", 0)

You have to pass the ID as part of the data, which is the third parameter.

plowed 10-02-2011 13:59

Re: playermenu help
 
I think that part of data is needed to catch which menu item a player selectet :o or am I wrong?

Anyway Ive tried with a global variable that hold every menu choice for every player. And the menu just works fine :)

thanks andy :crab:

[PUPPETS] Scooter 10-02-2011 15:38

Re: playermenu help
 
As data is an array, you can pass whatever you want and split it later.
You're welcome 8)

Doc-Holiday 10-02-2011 19:25

Re: playermenu help
 
i acutally have no idea what it is you want.. but there is a section on here that explains menus pretty good. you should look into that.

plowed 10-05-2011 15:04

Re: playermenu help
 
Quote:

Originally Posted by [PUPPETS] Scooter (Post 1567313)
As data is an array, you can pass whatever you want and split it later.
You're welcome 8)

Ah now I understand sounds really useful.

But I dont get how to use this.

For example I want to pass 3 things

data[0] = id
data[1] = name
data[2] = steamid

Could you or someone else give me a quick example please? :shock:

Xellath 10-05-2011 15:30

Re: playermenu help
 
Creating a global variable that holds the index of the selected player is also a valid option.

Code:
new g_playerid[ 33 ]; // in menu_handler // instead of new tempid = str_to_num(data): g_playerid[ id ] = str_to_num( data ); // then use g_playerid[ id ] to retrieve the selected player index // get_user_name(g_playerid[ id ], name, charsmax( name ) ); // etc... // and then in submenu_handler // use the global variable to retrieve the index new key = str_to_num( data ); set_user_ammo( g_playerid[ id ], g_ammoAmount[ key ] ); // just an example, set_user_ammo does not exist as an amxx native

plowed 10-05-2011 15:33

Re: playermenu help
 
see post #3. Im Just interest how to script the other way :)

Quote:

// just an example, set_user_ammo does not exist as an amxx native
cuz the native is from zombie plague

Xellath 10-05-2011 15:47

Re: playermenu help
 
Quote:

Originally Posted by plowed (Post 1568990)
see post #3. Im Just interest how to script the other way :)

cuz the native is from zombie plague

Aha. I see. set_user_ammo is not a default native, it probably exists in a mod or include file, but not official includes.

I'm not entirely sure if data can be passed as an array in menu_additem, most likely not. You can try it out if you want to however.

EDIT: It can be passed as a long string however.

plowed 10-05-2011 16:56

Re: playermenu help
 
Ive got confused first but now I think I can use it thx. Forgot Scooter's advice tho ;)


All times are GMT -4. The time now is 19:36.

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