else if's
#2

Just add "return 1;" in the first if-statement.
This will prevent any further code to be executed.

pawn Код:
if (strcmp("/joinrace", cmdtext, true, 10) == 0)
{
    if(IsPlayerInStreamedCheckpoint(playerid,Cp1) && IsPlayerInAnyVehicle(playerid))
    {
        SendClientMessage(playerid,COLOR_LIGHTBLUE,"You joined the race!");
        new vehicleid = GetPlayerVehicleID(playerid);
        SetVehiclePos(vehicleid, 2466.4861,-1661.6304,12.8521);
        SetPlayerFacingAngle(playerid, 0);
        ++racers;
        joined[playerid] = true;

        return 1; //Exit the command here to stop executing the code below
    }
    else if(PLAYER_STATE_ONFOOT && IsPlayerInStreamedCheckpoint(playerid,Cp1))
    {
        SendClientMessage(playerid,COLOR_LIGHTBLUE,"You must be at the cp to do that!");
    }
    else if(IsPlayerInAnyVehicle(playerid))
    {
        SendClientMessage(playerid,COLOR_LIGHTBLUE,"You must be at the cp to do that!");
    }
    else if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
    {
        SendClientMessage(playerid,COLOR_LIGHTBLUE,"You must be at the cp to do that!");
    }

    if(joined[playerid] == true)
    {
        SendClientMessage(playerid,COLOR_LIGHTBLUE,"You already joined the race!");
    }

    return 1;
}
Or this (if he joined before, the first statement will send the message and exit the command: "return SendClientMessage").
If joined = false, the rest of the code will be executed.
pawn Код:
if (strcmp("/joinrace", cmdtext, true, 10) == 0)
{
    if(joined[playerid] == true)
        return SendClientMessage(playerid,COLOR_LIGHTBLUE,"You already joined the race!");


    if(IsPlayerInStreamedCheckpoint(playerid,Cp1) && IsPlayerInAnyVehicle(playerid))
    {
        SendClientMessage(playerid,COLOR_LIGHTBLUE,"You joined the race!");
        new vehicleid = GetPlayerVehicleID(playerid);
        SetVehiclePos(vehicleid, 2466.4861,-1661.6304,12.8521);
        SetPlayerFacingAngle(playerid, 0);
        ++racers;
        joined[playerid] = true;

        return 1; //Exit the command here to stop executing the code below
    }
    else if(PLAYER_STATE_ONFOOT && IsPlayerInStreamedCheckpoint(playerid,Cp1))
    {
            SendClientMessage(playerid,COLOR_LIGHTBLUE,"You must be at the cp to do that!");
    }
    else if(IsPlayerInAnyVehicle(playerid))
    {
        SendClientMessage(playerid,COLOR_LIGHTBLUE,"You must be at the cp to do that!");
    }
    else if(GetPlayerState(playerid) == PLAYER_STATE_ONFOOT)
    {
        SendClientMessage(playerid,COLOR_LIGHTBLUE,"You must be at the cp to do that!");
    }

    return 1;
}
Reply


Messages In This Thread
else if's - by BrivibasGars - 05.02.2014, 06:19
Re: else if's - by PowerPC603 - 05.02.2014, 06:27
Re: else if's - by BrivibasGars - 05.02.2014, 06:57
Re: else if's - by Vince - 05.02.2014, 11:02
Re: else if's - by Konstantinos - 05.02.2014, 11:26

Forum Jump:


Users browsing this thread: 1 Guest(s)