It's not working
#4

I haven't been using OnPlayerCommandText for a long time but I guess it should be this way:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(strcmp(cmdtext, "/engine", true) == 0) {
        new vehicle = GetPlayerVehicleID(playerid);
        new engine,lights,alarm,doors,bonnet,boot,objective;
        GetVehicleParamsEx(vehicle,engine,lights,alarm,doors,bonnet,boot,objective);
        if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_RED,"{FF6A22}INFO: {FFFFFF}You need to be in vehicle to start engine.");
        if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessage(playerid, COLOR_RED,"{FF6A22}INFO: {FFFFFF}You need to be driver to use this command.");
        SendClientMessage(playerid, COLOR_PURPLE,"{00FF00}INFO: {FFFFFF}You twist the key, and wait 4 seconds.");
        //if(Eng[playerid] == 1) return SendClientMessage(playerid, COLOR_RED,"{FF6A22}INFO: {FFFFFF}You already turned engine on.");
        SetTimerEx("EngStart", 4000, false, "d", playerid);
        if(engine == 1) {
            SetVehicleParamsEx(vehicle,0,lights,alarm,doors,bonnet,boot,objective);
            SendClientMessage(playerid, COLOR_PURPLE,"{00FF00}INFO: {FFFFFF}Engine turned off.");
        } else {
            SetTimerEx("EngStart", 4000, false, "d", playerid);
        }
        return 1; //Here's where the return 1 should go.
    }
    return 0;
}

//A tip I will give you is to only use return 1; if you really need to use it and at the end of functions because carelessly using return 1 will make your code halt (pause) when it reaches a return. It's like setting a break point in a debugger, well sort of... It's not really the same but you get the point.
//Using a return 1 for an if statement is absolutely correct but using it for no reason at all is just wrong and the compiler will complain.

// Pseudo
if(something == 1) {
    printf("Hey there");
    return 1; //Code will halt here because you used a return 1 and because we "assume" the condition is being met right now..
}
//Otherwise it will continue here..
//Execute something else here if something isn't 1.
Reply


Messages In This Thread
It's not working - by Lajko1 - 20.11.2013, 21:09
Re: It's not working - by InglewoodRoleplay - 20.11.2013, 21:19
Re: It's not working - by Lajko1 - 20.11.2013, 21:31
Re: It's not working - by InglewoodRoleplay - 20.11.2013, 21:42
Re: It's not working - by Lajko1 - 20.11.2013, 21:43

Forum Jump:


Users browsing this thread: 1 Guest(s)