How to make a loop ...
#1

Hey samp members!
I need help to make a kind of a loop ,which something like :
I want skins under 102 (means 102 is not with them) have a custom textdraw when player changes to one of them
and skins between 128 and 280 have diffrent textdraw ,too. How to make that staff?

another question : i made this line maybe it helps you to understand what i want...

pawn Код:
new a = 0;
    while(a <= 101 && a >= 128 && a <= 280 && a >= 289 && a <= 299)
    {
        AddPlayerClass(a, 2485.6213,-1665.0665,15, -1, 0, 0, 0, 0, 0, 0);
        a = a + 1;
So "a" classes doesn't contain skins from 101 to 128,280 to 289 and above 299 skins.

By the way,it is compiled fine,But the problem is that when i start the server,I can only choose CJ skin only,no more to select from,any idea?
Reply
#2

Just think about it. Do you think that "a" could be lower than 101 and still higher than 128?

PHP код:
for(new a;a<102;a++) AddPlayerClass(a2485.6213,-1665.0665,15, -1000000);
for(new 
a=128;a<281;a++) AddPlayerClass(a2485.6213,-1665.0665,15, -1000000);
for(new 
a=289;a<300;a++) AddPlayerClass(a2485.6213,-1665.0665,15, -1000000); 
Reply
#3

your variable cannot meet the conditions you put together in while

try

PHP код:
for (new 0<= 311a++)
{
    if ( 
<= 101 || ( a>= 128 && <= 280) || ( >= 289 && <= 299) )
    {
        
AddPlayerClass(a2485.6213,-1665.0665,15, -1000000);
    }
    else
    {
        
// others
    
}

Reply
#4

Both of you are same,second fix is better understandable but thanks very much for both for making my script less codes,now,what about the CJ only in class selection problem?
Reply
#5

Quote:
Originally Posted by alexus
Посмотреть сообщение
your variable cannot meet the conditions you put together in while

try

PHP код:
for (new 0<= 311a++)
{
    if ( 
<= 101 || ( a>= 128 && <= 280) || ( >= 289 && <= 299) )
    {
        
AddPlayerClass(a2485.6213,-1665.0665,15, -1000000);
    }
    else
    {
        
// others
    
}

Or simplify that:
Код:
for (new a = 0; a <= 312; a++) switch(a)
{
	case 0..101, 128..280, 289..299:
		AddPlayerClass(a, 2485.6213,-1665.0665,15, -1, 0, 0, 0, 0, 0, 0); 
	default:
		//Others
}
If you want to do custom textdraws you have to do that under OnPlayerRequestClass, but to know which class is which you need to save the id's in an array. For example:
Код:
//Put this somewhere at the top of your script, with other variables maybe.
new SkinClass[312];

//Put this under whatever Init you are using, Gamemode or Filterscript.
for (new a = 0; a <= 312; a++) switch(a)
{
	case 0..101, 128..280, 289..299:
		SkinClass[a] = AddPlayerClass(a, 2485.6213,-1665.0665,15, -1, 0, 0, 0, 0, 0, 0); 
	default:
		//Others
}

//Put this under OnPlayerRequestClass.
for (new a = 0; a <= 312; a++) if(classid == SkinClass[a])
{
	//Textdraw stuff here.
	break;
}
Reply
#6

Guys look,that is the problem,and i started to understand how to code pawn finally ,that helped me to figure the problem to explain it : first this is the code which i made -note: the- x,y,z are a fake coordinites,don't belive them-

pawn Код:
for (new a = 0; a <= 311; a++)  switch(a)
   {
           case 0..279, 289..299:
                   AddPlayerClass(a, 2485.6213,-1665.0665,15, -1, 0, 0, 0, 0, 0, 0);
           default:
   }
   for (new b = 102; b <= 102; b++) switch(b)
   {
           case 280..288, 300..311
                   AddPlayerClass(b, 21202, 212151, 21215, 15, -1, 0, 0, 0, 0 , 0, 0);
           default:
   }
That looks good,but the problem when i just do that,i get an error of undefined symbols : a,b
so i typed in the top of my script : new a = 0; , b = 102; Now here is the problem:
Finally when i tested my server,I found that the script reads the Addplayerclass(a or b) as a skins
so i only get skin 0 CJ ,and skin 102 one of the ballas.
Any ideas?
Reply
#7

REMOVE THE LINE YOU ADDED: new a = 0, b = 102;

Now notice you didn't do anything in the "default;" therefore, you can remove that like so:
pawn Код:
for (new a = 0; a < 312; a++) // You must use 312.
{
    switch(a)
    {
        case 0..279, 289..299:
            AddPlayerClass(a, 2485.6213,-1665.0665,15, -1, 0, 0, 0, 0, 0, 0);
        case 280..288, 300..311:
            AddPlayerClass(a, 21202, 212151, 21215, 15, -1, 0, 0, 0, 0 , 0, 0);
    }
}
The reason you must use 312 is because there are 311 skin ID's. A loop starts at 0 and goes up to the point the statement is true. So, when it gets up to 312 it will stop running and not run the last (312 in this case because there isn't a skin ID 312). Lastly, you don't need two loops! That's the whole point of the switch.
Reply
#8

Under OnGameModeInit

AddPlayerClass(a, 2485.6213,-1665.0665,15, -1, 0, 0, 0, 0, 0, 0);
AddPlayerClass(b, 21202, 212151, 15, -1, 0, 0, 0, 0 , 0, 0); (coordines are fake..)

I get those errors which i made the new a,b for : error 017: undefined symbol "a"
. error 017: undefined symbol "b"

any ideas?
Reply
#9

Put this entire thing under OnGameModeInit:
pawn Код:
for (new a = 0; a < 312; a++) // You must use 312.
{
    switch(a)
    {
        case 0..279, 289..299:
            AddPlayerClass(a, 2485.6213,-1665.0665,15, -1, 0, 0, 0, 0, 0, 0);
        case 280..288, 300..311:
            AddPlayerClass(a, 21202, 212151, 21215, 15, -1, 0, 0, 0, 0 , 0, 0);
    }
}
Reply
#10

SO i should put what you said above under it,Look,The whole code i got it from tut,should remove the "stock Addclasses ()" and then add it?i will compile,and wait for your respons
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)