[SOLVED] Multiple 'if' statements problem -
thenachoman180 - 07.10.2012
Hello, i am kind of a noob at this stuff as im only 12 years old XD (dont pay me out) ive been coding in pawno for about a year now and ive made a little server for me and my friends. I have a stunter class that just does stunts and i want just that team to be able to do /repair to repair their vehicle, but to do that i need to use 2 if statements
Код:
if(gTeam[playerid] == TEAM_STUNTS
and
Код:
if(!IsPlayerInAnyVehicle(playerid))
But i have absolutely no idea on how to call the second if statement after the first (like to check if a player is in a vehicle after it has checked if they are on the stunter team) this is my public OnPlayerCommandText code.
Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if (strcmp("/stunts", cmdtext, true, 10) == 0)
{
if(gTeam[playerid] == TEAM_STUNTS)
{
SetPlayerPos(playerid, 1593.85059,2502.72729,578.09845);
}
else SendClientMessage(playerid,0xAA3333AA,"You must be on the stunter team to teleport to the stunter spawn!");
}
if (!strcmp("/repair", cmdtext))
{
if(gTeam[playerid] == TEAM_STUNTS)
if(!IsPlayerInAnyVehicle(playerid))
RepairVehicle(GetPlayerVehicleID(playerid));
SendClientMessage(playerid, COLOR_GREEN, "Your vehicle has been repaired!");
return 1;
}
}
As you can see i have no idea lol. Please help all you can
-Nacho
AW: Multiple 'if' statements problem -
Nero_3D - 07.10.2012
You will maybe notice that the you already made something similar with the "/stunts" command
pawn Код:
//
if(strcmp("/repair", cmdtext, true) == 0)
{
if(gTeam[playerid] == TEAM_STUNTS)
{
if(IsPlayerInAnyVehicle(playerid))
{
RepairVehicle(GetPlayerVehicleID(playerid));
return SendClientMessage(playerid, COLOR_GREEN, "Your vehicle has been repaired!");
}
}
}
or you use && (and)
pawn Код:
//
if(
(strcmp("/repair", cmdtext, true) == 0) &&
(gTeam[playerid] == TEAM_STUNTS) &&
(IsPlayerInAnyVehicle(playerid))
) {
RepairVehicle(GetPlayerVehicleID(playerid));
return SendClientMessage(playerid, COLOR_GREEN, "Your vehicle has been repaired!");
}
Also read that
Control Structures
Re: AW: Multiple 'if' statements problem -
thenachoman180 - 07.10.2012
Quote:
Originally Posted by Nero_3D
You will maybe notice that the you already made something similar with the "/stunts" command
pawn Код:
// if(strcmp("/repair", cmdtext, true) == 0) { if(gTeam[playerid] == TEAM_STUNTS) { if(IsPlayerInAnyVehicle(playerid)) { RepairVehicle(GetPlayerVehicleID(playerid)); return SendClientMessage(playerid, COLOR_GREEN, "Your vehicle has been repaired!"); } } }
or you use && (and)
pawn Код:
// if( (strcmp("/repair", cmdtext, true) == 0) && (gTeam[playerid] == TEAM_STUNTS) && (IsPlayerInAnyVehicle(playerid)) ) { RepairVehicle(GetPlayerVehicleID(playerid)); return SendClientMessage(playerid, COLOR_GREEN, "Your vehicle has been repaired!"); }
Also read that Control Structures
|
Ah, thankyou. But now i get 26 errors when compiling lol. Its something to do with the brackets. Can you please send me a code snippit of the whole OnPlayerCommandText? Thanks in advance
Re: Multiple 'if' statements problem -
thenachoman180 - 07.10.2012
Wait, no dont worry i just added another bracket at the end that i must of missed XD. but how do i do an else thing like what i had before. say if i wasnt in a vehicle, it would say "you must be in a vehicle" and if i wasnt on the stunter team it would say "You must be on the stunter team to repair your vehicle" thanks again
-Nacho
AW: Multiple 'if' statements problem -
Nero_3D - 07.10.2012
There you can do
pawn Код:
//
if(strcmp("/repair", cmdtext, true) == 0) {
if(gTeam[playerid] == TEAM_STUNTS) {
if(IsPlayerInAnyVehicle(playerid)) {
RepairVehicle(GetPlayerVehicleID(playerid));
SendClientMessage(playerid, COLOR_GREEN, "Your vehicle has been repaired!");
} else {
SendClientMessage(playerid, COLOR_GREEN, "You must be in a vehicle!");
}
} else {
SendClientMessage(playerid, COLOR_GREEN, "You must be on the stunter team!");
}
return true;
}
But thats gets confusing if you got a large block of code between
pawn Код:
//
if(strcmp("/repair", cmdtext, true) == 0) {
if(gTeam[playerid] != TEAM_STUNTS) { // if the player is not in TEAM_SUNTS
return SendClientMessage(playerid, COLOR_GREEN, "You must be on the stunter team!");
}
if(!IsPlayerInAnyVehicle(playerid)) { // not in the vehicle
return SendClientMessage(playerid, COLOR_GREEN, "You must be in a vehicle!");
}
RepairVehicle(GetPlayerVehicleID(playerid));
return SendClientMessage(playerid, COLOR_GREEN, "Your vehicle has been repaired!");
}
No else if needed since we return always, you can also leave the brackets away if you only got one line after the if statment
pawn Код:
//
if(strcmp("/repair", cmdtext, true) == 0) {
if(gTeam[playerid] != TEAM_STUNTS)
return SendClientMessage(playerid, COLOR_GREEN, "You must be on the stunter team!");
if(!IsPlayerInAnyVehicle(playerid))
return SendClientMessage(playerid, COLOR_GREEN, "You must be in a vehicle!");
RepairVehicle(GetPlayerVehicleID(playerid));
return SendClientMessage(playerid, COLOR_GREEN, "Your vehicle has been repaired!");
}
Re: Multiple 'if' statements problem -
RedFusion - 07.10.2012
AND Operator
pawn Код:
if(var1 == 1 && var2 == 1)
(If both var1 and var2 are equal to 1)
OR Operator
pawn Код:
if(var1 == 1 || var2 == 1)
(If either var1 or var2 are equal to 1)
Source
Re: Multiple 'if' statements problem -
thenachoman180 - 07.10.2012
THANKYOU problem [SOLVED]