loop for certain skins -
oblexive - 26.07.2012
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);
Re: loop for certain skins -
Jeffry - 26.07.2012
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.
}
Re: loop for certain skins -
namespace - 26.07.2012
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
Re: loop for certain skins -
oblexive - 26.07.2012
Thanks I didnt even know you could do that, I mean I hadnt thought about it. Thanks heaps man!
Re: loop for certain skins -
Jeffry - 26.07.2012
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. ^^
Re: loop for certain skins -
oblexive - 26.07.2012
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
Re: loop for certain skins -
Misiur - 26.07.2012
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
Re: loop for certain skins -
oblexive - 26.07.2012
cool thanks Misiur,
Re: loop for certain skins -
Jeffry - 26.07.2012
Sorry, just saw the mistake I've made in my testing code.

Misiur's one looks perfect.
Re: loop for certain skins -
Misiur - 26.07.2012
I think this is first time ever I used do..while with a purpose