SA-MP Forums Archive
Question about multipul numbers in "if" - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Question about multipul numbers in "if" (/showthread.php?tid=214107)



Question about multipul numbers in "if" - linuxthefish - 20.01.2011

I am trying to make a script that tells the player the spawn point they have chosen (based on skin ID) when they spawn. so if there skin is "282" they get the message "Police Spawn" when they spawn. At the moment i can only do it for one skin, how do i do it for a number of skins e.g 281, 183 and 287? My current code is pasted at the bottom but that compiles but dosnt work

pawn Код:
public OnPlayerSpawn(playerid)
{
    if(GetPlayerSkin(playerid) == 285/282/281/283/287/286) return SendClientMessage(playerid, COLOR_RED, "Police Spawn");
    else if(GetPlayerSkin(playerid) == 274/275/276) return SendClientMessage(playerid, COLOR_RED, "Medic Spawn");
    else if(GetPlayerSkin(playerid) == 105/106/107/269/270/271) return SendClientMessage(playerid, COLOR_RED, "Grove Spawn");
    else if(GetPlayerSkin(playerid) == 0) return SendClientMessage(playerid, COLOR_RED, "CJ Spawn");
    else if(GetPlayerSkin(playerid) == 274/275/276) return SendClientMessage(playerid, COLOR_RED, "Police Class!");
    return 1;
}



Re: Question about multipul numbers in "if" - SkizzoTrick - 20.01.2011

Quote:
Originally Posted by linuxthefish
Посмотреть сообщение
I am trying to make a script that tells the player the spawn point they have chosen (based on skin ID) when they spawn. so if there skin is "282" they get the message "Police Spawn" when they spawn. At the moment i can only do it for one skin, how do i do it for a number of skins e.g 281, 183 and 287? My current code is pasted at the bottom but that compiles but dosnt work

pawn Код:
public OnPlayerSpawn(playerid)
{
    if(GetPlayerSkin(playerid) == 285/282/281/283/287/286) return SendClientMessage(playerid, COLOR_RED, "Police Spawn");
    else if(GetPlayerSkin(playerid) == 274/275/276) return SendClientMessage(playerid, COLOR_RED, "Medic Spawn");
    else if(GetPlayerSkin(playerid) == 105/106/107/269/270/271) return SendClientMessage(playerid, COLOR_RED, "Grove Spawn");
    else if(GetPlayerSkin(playerid) == 0) return SendClientMessage(playerid, COLOR_RED, "CJ Spawn");
    else if(GetPlayerSkin(playerid) == 274/275/276) return SendClientMessage(playerid, COLOR_RED, "Police Class!");
    return 1;
}
OMFG!!!!You need 1 line for every skin like

pawn Код:
if(GetPlayerSkin(playerid) == 285 || GetPlayerSkin(playerid) == 282 || GetPlayerSkin(playerid) == 281) {return SendClientMessage(playerid, COLOR_RED, "Police Spawn");}
//LIKE THIS if you want,or simple one line per skin



    else if(GetPlayerSkin(playerid) == 274) {return SendClientMessage(playerid, COLOR_RED, "Medic Spawn");}
    else if(GetPlayerSkin(playerid) == 105/106/107/269/270/271) {return SendClientMessage(playerid, COLOR_RED, "Grove Spawn");}
    else if(GetPlayerSkin(playerid) == 0) {return SendClientMessage(playerid, COLOR_RED, "CJ Spawn");}
    else if(GetPlayerSkin(playerid) == 274) {return SendClientMessage(playerid, COLOR_RED, "Police Class!");}



Respuesta: Question about multipul numbers in "if" - [M]xFire - 20.01.2011

pawn Код:
public OnPlayerSpawn(playerid)
{
    if(GetPlayerSkin(playerid) == 285 || GetPlayerSkin(playerid) == 282 || GetPlayerSkin(playerid) == 281 || GetPlayerSkin(playerid) == 283 || GetPlayerSkin(playerid) == 287 || GetPlayerSkin(playerid) == 286) return SendClientMessage(playerid, COLOR_RED, "Police Spawn");
    else if(GetPlayerSkin(playerid) == 274/275/276) return SendClientMessage(playerid, COLOR_RED, "Medic Spawn");//same here
    else if(GetPlayerSkin(playerid) == 105/106/107/269/270/271) return SendClientMessage(playerid, COLOR_RED, "Grove Spawn");
    else if(GetPlayerSkin(playerid) == 0) return SendClientMessage(playerid, COLOR_RED, "CJ Spawn");
    else if(GetPlayerSkin(playerid) == 274/275/276) return SendClientMessage(playerid, COLOR_RED, "Police Class!");// and too same here!
    return 1;
}



Re: Respuesta: Question about multipul numbers in "if" - SkizzoTrick - 20.01.2011

Quote:
Originally Posted by [M]xFire
Посмотреть сообщение
pawn Код:
public OnPlayerSpawn(playerid)
{
    if(GetPlayerSkin(playerid) == 285 || GetPlayerSkin(playerid) == 282 || GetPlayerSkin(playerid) == 281 || GetPlayerSkin(playerid) == 283 || GetPlayerSkin(playerid) == 287 || GetPlayerSkin(playerid) == 286) return SendClientMessage(playerid, COLOR_RED, "Police Spawn");
    else if(GetPlayerSkin(playerid) == 274/275/276) return SendClientMessage(playerid, COLOR_RED, "Medic Spawn");//same here
    else if(GetPlayerSkin(playerid) == 105/106/107/269/270/271) return SendClientMessage(playerid, COLOR_RED, "Grove Spawn");
    else if(GetPlayerSkin(playerid) == 0) return SendClientMessage(playerid, COLOR_RED, "CJ Spawn");
    else if(GetPlayerSkin(playerid) == 274/275/276) return SendClientMessage(playerid, COLOR_RED, "Police Class!");// and too same here!
    return 1;
}
You just said what i've said ..


Respuesta: Question about multipul numbers in "if" - [M]xFire - 20.01.2011

Sorry, i didn't read


Re: Question about multipul numbers in "if" - linuxthefish - 20.01.2011

Thanks, that works


Re: Question about multipul numbers in "if" - bigcomfycouch - 20.01.2011

Faster and cleaner than calling GetPlayerSkin many times.

pawn Код:
public OnPlayerSpawn( playerid )
{
    switch ( GetPlayerSkin( playerid ) )
    {
        case 281 .. 283, 285 .. 287: SendClientMessage(playerid, COLOR_RED, "Police Spawn");
        case 274 .. 276: SendClientMessage(playerid, COLOR_RED, "Medic Spawn");
        case 105 .. 107, 269 .. 271: SendClientMessage(playerid, COLOR_RED, "Grove Spawn");
        case 0: SendClientMessage(playerid, COLOR_RED, "CJ Spawn");
    }
    return 1;
}



Re: Question about multipul numbers in "if" - legodude - 20.01.2011

Quote:
Originally Posted by bigcomfycouch
Посмотреть сообщение
Faster and cleaner than calling GetPlayerSkin many times.

pawn Код:
public OnPlayerSpawn( playerid )
{
    switch ( GetPlayerSkin( playerid ) )
    {
        case 281 .. 283, 285 .. 287: SendClientMessage(playerid, COLOR_RED, "Police Spawn");
        case 274 .. 276: SendClientMessage(playerid, COLOR_RED, "Medic Spawn");
        case 105 .. 107, 269 .. 271: SendClientMessage(playerid, COLOR_RED, "Grove Spawn");
        case default: SendClientMessage(playerid, COLOR_RED, "Unmonitored Spawn");
    }
    return 1;
}
thats better... or it wont let u see the message at other skins.