AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help with Code .. (https://forums.alliedmods.net/showthread.php?t=136190)

EpicFail. 08-23-2010 19:32

Help with Code ..
 
How i can fix this ?

here my code:
PHP Code:

menu_additemhmenu"1""%s25 Health \r- %s\W%d\Y$"is_user_aliveid ) ? "\w" "\d", ( iMoney >= HEALTH25_COST ) ? "\w" "\d"HEALTH25_COST ); 

Here the Error:
PHP Code:

ErrorArgument type mismatch (argument 4on line 441 

Some one help please

fysiks 08-23-2010 20:00

Re: Help with Code ..
 
You can't format with menu_additem(). Youhave to format with format() then put that into menu_additem().

rubee 08-23-2010 20:09

Re: Help with Code ..
 
try this

Code:
new option[30] formatex(option, charsmax(option), "%s25 Health \r- %s\w%d\y$", is_user_alive( id ) ? "\w" : "\d", ( iMoney >= HEALTH25_COST ) ? "\w" : "\d", HEALTH25_COST ); menu_additem(hmenu, option, "1", 0)

Kreation 08-24-2010 01:18

Re: Help with Code ..
 
Quote:

Originally Posted by rubee (Post 1280173)
try this

Code:
new option[30] formatex(option, charsmax(option), "%s25 Health \r- %s\w%d\y$", is_user_alive( id ) ? "\w" : "\d", ( iMoney >= HEALTH25_COST ) ? "\w" : "\d", HEALTH25_COST ); menu_additem(hmenu, option, "1", 0)

Next time, let him try it first. Otherwise he doesnt learn anything.

EpicFail. 08-24-2010 20:12

Re: Help with Code ..
 
Quote:

Originally Posted by rubee (Post 1280173)
try this

Code:
new option[30] formatex(option, charsmax(option), "%s25 Health \r- %s\w%d\y$", is_user_alive( id ) ? "\w" : "\d", ( iMoney >= HEALTH25_COST ) ? "\w" : "\d", HEALTH25_COST );
menu_additem(hmenu, option, "1", 0)



Hm.. this work but !
if i buy one item of menu with 7 Numbers
i cant buy nothing again from this ..
how i can fix it ?

Sorry for bad English

fysiks 08-24-2010 20:14

Re: Help with Code ..
 
Quote:

Originally Posted by EpicFail. (Post 1280972)
Hm.. this work but !
if i buy one item of menu with 7 Numbers
i cant buy nothing again from this ..
how i can fix it ?

Sorry for bad English

Re-show the menu in the handling function. Directly before return PLUGIN_HANDLED but after menu_destroy (if the menu is not global).

EpicFail. 08-24-2010 20:16

Re: Help with Code ..
 
Quote:

Originally Posted by fysiks (Post 1280973)
Re-show the menu in the handling function. Directly before return PLUGIN_HANDLED but after menu_destroy (if the menu is not global).


Hm ..
Like this ? Code:
PHP Code:

new menuname[64]
    
formatexmenuname63"\r[\wjG`\r] \wHns Shop^nHealth Menu^nYour Cash: %d\y$"cs_get_user_moneyid ) );
    new 
hmenu menu_createmenuname"health_handler" );
    
    new 
iMoney cs_get_user_moneyid )
    
    new 
Health25[30]
    
formatexHealth25charsmax(Health25), "25 Health \r- %s\W%d\Y$", ( iMoney >= HEALTH25_COST ) ? "\w" "\d"HEALTH25_COST );
    
menu_additem(hmenuHealth25"1"0);
     
    new 
Health50[30]
    
formatex(Health50charsmax(Health50), "50 Health \r- %s\W%d\Y$", ( iMoney >= HEALTH50_COST ) ? "\w" "\d"HEALTH50_COST );
         
menu_additem(hmenuHealth50"2"0);
    
    
menu_setprophmenuMPROP_EXITMEXIT_ALL );
    
menu_setprophmenuMPROP_EXITNAME"\wBack" );
    
    
menu_displayidhmenu);
    
    return 
PLUGIN_CONTINUE


fysiks 08-24-2010 20:19

Re: Help with Code ..
 
Quote:

Originally Posted by EpicFail. (Post 1280975)
Hm ..
Like this ? Code:
PHP Code:

new menuname[64]
    
formatexmenuname63"\r[\wjG`\r] \wHns Shop^nHealth Menu^nYour Cash: %d\y$"cs_get_user_moneyid ) );
    new 
hmenu menu_createmenuname"health_handler" );
    
    new 
iMoney cs_get_user_moneyid )
    
    new 
Health25[30]
    
formatexHealth25charsmax(Health25), "25 Health \r- %s\W%d\Y$", ( iMoney >= HEALTH25_COST ) ? "\w" "\d"HEALTH25_COST );
    
menu_additem(hmenuHealth25"1"0);
     
    new 
Health50[30]
    
formatex(Health50charsmax(Health50), "50 Health \r- %s\W%d\Y$", ( iMoney >= HEALTH50_COST ) ? "\w" "\d"HEALTH50_COST );
         
menu_additem(hmenuHealth50"2"0);
    
    
menu_setprophmenuMPROP_EXITMEXIT_ALL );
    
menu_setprophmenuMPROP_EXITNAME"\wBack" );
    
    
menu_displayidhmenu);
    
    return 
PLUGIN_CONTINUE


That is the menu function. I'm talking about "health_handler". It should look something like:

PHP Code:

public health_handler(idmenuitem)
{
    
// code to handle exit
    // code to hanlde selected options
    
    
menu_destroy(menu)
    
show_menu_function(id// This is the function that creates the menu an shows it.  The one you just posted.
    
return PLUGIN_HANDLED



EpicFail. 08-24-2010 20:23

Re: Help with Code ..
 
This maybe ?

PHP Code:

public health_handleridhmenuitem )
{
    if( 
item == MENU_EXIT )
    {
        
menu_destroyhmenu );
        
CmdMainMenuid );
        return 
PLUGIN_HANDLED;
    }
    
    new 
data[6], iName[64];
    new 
accesscallback;
    
menu_item_getinfohmenuitemaccessdata5iName63callback );
    
    new 
picked str_to_numdata );
    new 
iMoney cs_get_user_moneyid );
    
    switch( 
picked )
    {
             case 
1:
        {
            if( 
iMoney >= HEALTH25_COST )
            {
                if( 
is_user_aliveid ) )
                {
                    if( !
g_bHas25HP[id] )
                    {
                        
cs_set_user_moneyidiMoney HEALTH25_COST );
                    
                        new 
health get_user_healthid ) + 25;
                        
set_user_healthidhealth );
                        
g_bHas25HP[id] = true;
                    
                        
client_cmdid"spk items/medshot4" );
                    }
                    else
                    {
                        
ChatColor0"%s You already bought this item!"CLAN_TAG );
                        return 
PLUGIN_HANDLED;
                    }
                }
                else
                {
                    
ChatColor0"%s You must be alive to use the shop!"CLAN_TAG );
                    return 
PLUGIN_HANDLED;
                }
            }
            else
            {
                
ChatColor0"%s You don't have enough money for this!"CLAN_TAG );
                return 
PLUGIN_HANDLED;
            }
        }
        case 
2:
        {
            if( 
iMoney >= HEALTH50_COST )
            {
                if( 
is_user_aliveid ) )
                {
                    if( !
g_bHas25HP[id] )
                    {
                        
cs_set_user_moneyidiMoney HEALTH50_COST );
                    
                        new 
health get_user_healthid ) + 50;
                        
set_user_healthidhealth );
                        
g_bHas25HP[id] = true;
                    
                        
client_cmdid"spk items/medshot4" );
                    }
                    else
                    {
                        
ChatColor0"%s You already bought this item!"CLAN_TAG );
                        return 
PLUGIN_HANDLED;
                    }
                }
                else
                {
                    
ChatColor0"%s You must be alive to use the shop!"CLAN_TAG );
                    return 
PLUGIN_HANDLED;
                }
            }
            else
            {
                
ChatColor0"%s You don't have enough money for this!"CLAN_TAG );
                return 
PLUGIN_HANDLED;
            }
        }

         }        
    
    
menu_destroyhmenu );
    
CmdMainMenuid );
    return 
PLUGIN_HANDLED;



fysiks 08-24-2010 21:30

Re: Help with Code ..
 
Quote:

Originally Posted by EpicFail. (Post 1280984)
This maybe ?

Don't put it in the exit part. If you do that then you can never close the menu (unless it's a submenu). So, remove that and it should work.


All times are GMT -4. The time now is 21:50.

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