else if's -
BrivibasGars - 05.02.2014
So, the next is the race command. I tryed do that in many ways, searched aswell, but nothing. Ok, the command is;
Код:
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;
}
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;
}
So, the problem is that, i can't figure out how can i add correctly
Код:
SendClientMessage(playerid,COLOR_LIGHTBLUE,"You already joined the race!");
and it's always showing together with the
Код:
SendClientMessage(playerid,COLOR_LIGHTBLUE,"You joined the race!");
I would like to know, what i'm doing wrong with the if's and else if's, i know, i'm doing wrong.
Re: else if's -
PowerPC603 - 05.02.2014
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;
}
Re: else if's -
BrivibasGars - 05.02.2014
Thank you very much, dude!
Re: else if's -
Vince - 05.02.2014
pawn Код:
else if(PLAYER_STATE_ONFOOT && IsPlayerInStreamedCheckpoint(playerid,Cp1))
Should note that you forgot the GetPlayerState right there.
Re: else if's -
Konstantinos - 05.02.2014
All those
else if statements are pointless in my opinion. Since you return the same message no matter whether the state is on foot or driver/passenger and streamed in the cp or not, you can use
else instead.
http://forum.sa-mp.com/showpost.php?...06&postcount=6