Raised This Month: $ Target: $400
 0% 

menu_additem in for loop


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 05-20-2016 , 04:49   menu_additem in for loop
Reply With Quote #1

Hi,

I'm kinda stuck at a for loop.

PHP Code:
new const szCommands[][] = {
    
"1",
    
"2",
    
"3",
    
"4",
    
"5"

PHP Code:
for(new isizeof(szValues); i++) {
        
formatex(szDatacharsmax(szData), "%s - \r[%i$]"szValues[i], iPrices[i])
        
menu_additem(menuszDataszCommands[i])
    }
menu_display(idmenu
the szCommands[i] part in menu_additem should be done better, i just don't know how could someone help me a hand




Problem number 2:
i currently have this as my code and i know it could be done way much better, could someone help me out doing this with a loop?
PHP Code:
        case 0RollTheDice(id2510)
        case 
1RollTheDice(id5025)
        case 
2RollTheDice(id12550)
        case 
3RollTheDice(id250100)
        case 
4RollTheDice(id600200
__________________

Last edited by Napoleon_be; 05-20-2016 at 05:21.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 05-20-2016 , 12:37   Re: menu_additem in for loop
Reply With Quote #2

Just use num_to_str and convert "i" to a string. Anyway, do you really need this param? You could ignore it.
__________________

Last edited by HamletEagle; 05-20-2016 at 12:41.
HamletEagle is offline
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 05-21-2016 , 05:20   Re: menu_additem in for loop
Reply With Quote #3

Yea, but he starts "i" with 0 because he must match array cells because they start from 0.
then he will use num_to_str(i+1)

Last edited by siriusmd99; 05-21-2016 at 05:21.
siriusmd99 is offline
NiHiLaNTh
Way Past Expiration
Join Date: May 2009
Location: Latvia
Old 05-21-2016 , 05:27   Re: menu_additem in for loop
Reply With Quote #4

or you can use i + 1 + '0' too.
__________________

NiHiLaNTh is offline
Send a message via Skype™ to NiHiLaNTh
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 05-22-2016 , 15:59   Re: menu_additem in for loop
Reply With Quote #5

I'll just ignore the param, didn't know i could, thanks, what about problem number 2? This could be done in a loop aswell but i just can't seem to figure out how..

PHP Code:
        case 0RollTheDice(id2510)
        case 
1RollTheDice(id5025)
        case 
2RollTheDice(id12550)
        case 
3RollTheDice(id250100)
        case 
4RollTheDice(id600200
I tried this, but it doesn't work.
PHP Code:
case 0..4: {
            for(new 
isizeof(iCosts); i++) {
                
RollTheDice(idiCosts[i], iPrices[i])
            }




PHP Code:
new iCosts[] = {
    
25,
    
50,
    
125,
    
250,
    
600
}

new 
iPrices[] ={
    
10,
    
25,
    
50,
    
100,
    
200

__________________

Last edited by Napoleon_be; 05-22-2016 at 16:06.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 05-22-2016 , 16:28   Re: menu_additem in for loop
Reply With Quote #6

No, case is called once, ohh. I better show you how simple it is :

don't use switch...
just use directly:

PHP Code:
RollTheDice(idiCosts[item], iPrices[item]) 
siriusmd99 is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 05-22-2016 , 16:59   Re: menu_additem in for loop
Reply With Quote #7

lol, didn't even think about that but it works perfectly, thanks man. Didn't know that stock would come out that handy.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
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 18:40.


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