AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   menu_additem in for loop (https://forums.alliedmods.net/showthread.php?t=282885)

Napoleon_be 05-20-2016 04:49

menu_additem in for loop
 
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


HamletEagle 05-20-2016 12:37

Re: menu_additem in for loop
 
Just use num_to_str and convert "i" to a string. Anyway, do you really need this param? You could ignore it.

siriusmd99 05-21-2016 05:20

Re: menu_additem in for loop
 
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)

NiHiLaNTh 05-21-2016 05:27

Re: menu_additem in for loop
 
or you can use i + 1 + '0' too.

Napoleon_be 05-22-2016 15:59

Re: menu_additem in for loop
 
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



siriusmd99 05-22-2016 16:28

Re: menu_additem in for loop
 
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]) 


Napoleon_be 05-22-2016 16:59

Re: menu_additem in for loop
 
lol, didn't even think about that but it works perfectly, thanks man. Didn't know that stock would come out that handy.


All times are GMT -4. The time now is 18:39.

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