AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Saving text of item in the menu (https://forums.alliedmods.net/showthread.php?t=153155)

bibu 03-19-2011 14:34

Saving text of item in the menu
 
I've made a menu with the new menu system. I want to make a money menu, where you first select the amount of money, example:

Choosable money:

1. 250
2. 500
3. 800
4. 1000
5. 4000
6. 7000
7. 10000
8. 13000
9. 16000


And after the money got pressed, I am showing a menu where the selected players are, how can I save the amount of money then?

fysiks 03-19-2011 17:45

Re: Saving text of item in the menu
 
Use a gobal variable . . .

bibu 03-19-2011 19:41

Re: Saving text of item in the menu
 
Can you show me how? :oops:

fysiks 03-19-2011 23:36

Re: Saving text of item in the menu
 
Quote:

Originally Posted by bibu (Post 1436126)
Can you show me how? :oops:

. . . .

Code:


new global_variable[33]

// ...
// menu handler
global_variable[id] = str_to_num(data)
// ...
// Where ever you need to retrieve the value
global_variable[id] // contains the number saved previously


bibu 03-20-2011 07:20

Re: Saving text of item in the menu
 
PHP Code:

public menu_handler_money_menu(idmenuitem)
{
    if(
item == MENU_EXIT)
    {
        
menu_destroy(menu)
        return 
PLUGIN_HANDLED
    
}

    new 
data[6], iName[64]
    new 
accesscallback

    menu_item_getinfo
(menuitemaccessdata5iName63callback)

    new 
key str_to_num(data)

    switch(
key)
{
    case 
123456789:
    {
        
g_money[id] = str_to_num(data)
    }
}
    
menu_destroy(menu)
    
MoneyplayerMenu(id)
    return 
PLUGIN_HANDLED


After choosing the player with this:

PHP Code:

cs_set_user_money(targetidg_money[id]) 

It gives weird amount of money.

ConnorMcLeod 03-20-2011 07:36

Re: Saving text of item in the menu
 
Code:
    new key = str_to_num(data)     switch(key) {     case 1, 2, 3, 4, 5, 6, 7, 8, 9:     {         g_money[id] = str_to_num(data)     } }

How do you think that str_to_num(data) can one time return 1 to 9 and the other time return some money amount ???

data contains money amount if i'm right, so forget the new menu tutorial and use item value instead of the "key = str_to_num" system, instead of checking item == MENU_EXIT at first, just check if item is <0, then you can retrieve money amount safely.

bibu 03-20-2011 07:48

Re: Saving text of item in the menu
 
I don't really know much or understand the old menu system. Can you show me how to hold the amount of the money then?

ConnorMcLeod 03-20-2011 08:00

Re: Saving text of item in the menu
 
I don't say you to use old menu, i say to use new menu but forget the way key is retrieved (tutorial is really good and helpfull but that part should never have been put in it i guess).

So just pass money amount in item info like you do, but don't try to get the key with that data because obviously data doesn't contain key but money.
So use item instead of key.

key : 1 to 9 (or more)
item : 0 to 8 (or more)

MENU_EXIT, MENU_NEXT and MENU_BACK (if names are correct) are all negative values.

If you don't understand what was said in that post and in previous posts, than you should stick with more basic plugins.

bibu 03-20-2011 09:04

Re: Saving text of item in the menu
 
Oh ok. Do you mean something like this:

PHP Code:

g_money[id] = str_to_num(data)

-->
g_money[id] = str_to_num(item

Then check if item is MENU_EXIT, MENU_NEXT and MENU_BACK. I tried to find some plugins which use something like this, but I couldn't find something.

fysiks 03-20-2011 14:55

Re: Saving text of item in the menu
 
Quote:

Originally Posted by bibu (Post 1436413)
Oh ok. Do you mean something like this:

PHP Code:

g_money[id] = str_to_num(data)

-->
g_money[id] = str_to_num(item

Then check if item is MENU_EXIT, MENU_NEXT and MENU_BACK. I tried to find some plugins which use something like this, but I couldn't find something.

Just use

PHP Code:

g_money[id] = str_to_num(iName)  // iName is not an integer!  Don't use "i" prefix or use "sz" or something not misleading. 



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

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