Question about multipul numbers in "if"
#1

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;
}
Reply
#2

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!");}
Reply
#3

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;
}
Reply
#4

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 ..
Reply
#5

Sorry, i didn't read
Reply
#6

Thanks, that works
Reply
#7

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;
}
Reply
#8

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)