Multiple 'if' statements problem
#5

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


Messages In This Thread
[SOLVED] Multiple 'if' statements problem - by thenachoman180 - 07.10.2012, 00:23
AW: Multiple 'if' statements problem - by Nero_3D - 07.10.2012, 00:31
Re: AW: Multiple 'if' statements problem - by thenachoman180 - 07.10.2012, 00:37
Re: Multiple 'if' statements problem - by thenachoman180 - 07.10.2012, 00:41
AW: Multiple 'if' statements problem - by Nero_3D - 07.10.2012, 01:02
Re: Multiple 'if' statements problem - by RedFusion - 07.10.2012, 01:03
Re: Multiple 'if' statements problem - by thenachoman180 - 07.10.2012, 01:05

Forum Jump:


Users browsing this thread: 1 Guest(s)