loop for certain skins
#1

hello again peoples
I dont know alot about loops so i hope someone can help me. I want to make it when the player spawns it sets their skin to a random one. This iv done, what Im now trying to do is make it if the skin is a certain Id then it re-randomizes it and sets the skin agian, again if its a certain one re randomize.. The skin ids that I dont want to allow are:
pawn Код:
if(RandomSkin == 61 || 70 || 71 || 80 || 81 || 102
            || 103 || 104 || 105 || 106 || 107 || 108 || 109
            || 110 || 111 || 112 || 113 || 114 || 115 || 116
            || 117 || 118 || 119 || 120 || 149 || 167 || 173
            || 174 || 175 || 264 || 265 || 266 || 267 || 269
            || 270 || 271 || 274 || 275 || 276 || 277 || 278
            || 279 || 280 || 281 || 282 || 283 || 284 || 285
            || 286 || 287 || 288);
Reply
#2

pawn Код:
checkagain:
    new RandomSkin = random(299); //Is it 299, just change it...
    if(RandomSkin == 61 || 70 || 71 || 80 || 81 || 102
            || 103 || 104 || 105 || 106 || 107 || 108 || 109
            || 110 || 111 || 112 || 113 || 114 || 115 || 116
            || 117 || 118 || 119 || 120 || 149 || 167 || 173
            || 174 || 175 || 264 || 265 || 266 || 267 || 269
            || 270 || 271 || 274 || 275 || 276 || 277 || 278
            || 279 || 280 || 281 || 282 || 283 || 284 || 285
            || 286 || 287 || 288) goto checkagain;
    else
    {
        //Whatever...none of the skins above.
    }
Reply
#3

Jeffry, first really not recommended using goto if its possible with a for/while loop

second

if(RandomSkin == 61 || 70 || 71 || 80 || 81 || 102
|| 103 || 104 || 105 || 106 || 107 || 108 || 109
|| 110 || 111 || 112 || 113 || 114 || 115 || 116
|| 117 || 118 || 119 || 120 || 149 || 167 || 173
|| 174 || 175 || 264 || 265 || 266 || 267 || 269
|| 270 || 271 || 274 || 275 || 276 || 277 || 278
|| 279 || 280 || 281 || 282 || 283 || 284 || 285
|| 286 || 287 || 28

i think this is wrong, should be RandomSkin == 61 ||RandomSkin == 70||RandomSkin == 71... etc
Reply
#4

Thanks I didnt even know you could do that, I mean I hadnt thought about it. Thanks heaps man!
Reply
#5

Quote:
Originally Posted by namespace
Посмотреть сообщение
Jeffry, first really not recommended using goto if its possible with a for/while loop
Using a loop here would not make any sense, sorry.


Regarding the way of the ||:
I compiled it, it compiled fine. I tested it, it works fine.

PS: Didn't know either that you could write them like this, learned something today. ^^
Reply
#6

sorry my bad yeah i picked that up before, also jeffry it didnt work, does some weird stuff to my server haha..
I was hoping to accomplish this with a for loop.?
actually i did something inccorect and fixed it and seems to be fine now.. :P
Reply
#7

pawn Код:
new selected = -1;
do
{
    new RandomSkin = random(299);
    switch(RandomSkin) {
        case 61, 70, 71, 80, 81, 102 .. 120, 149, 167, 173 .. 175, 264 .. 267, 269 .. 271, 274 .. 288:
        {
        }
        default:
        {
            selected = RandomSkin;
        }
    }
}
while(-1 == selected);
@edit: fixd scope
Reply
#8

cool thanks Misiur,
Reply
#9

Sorry, just saw the mistake I've made in my testing code.
Misiur's one looks perfect.
Reply
#10

I think this is first time ever I used do..while with a purpose
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)