/engine command not working (ZCMD)
#1

Well, alright, heres my problem.

I'm currently making a simple engine system for my script. All cars, by default, are spawned with their engines off. Now, when I type in /engine when not in my vehicle, it says "You are not driving a vehicle!". If I am actually inside the vehicle, it responds with "Server: Unknown command". Probably an easy fix, I just don't see whats wrong with it.

pawn Код:
CMD:engine(playerid, params[])
{
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER) //This here is checking if the player is inside a vehicle as a driver.
    {
        new vehicle = GetPlayerVehicleID(playerid); //This part here is defining the vehicle ID that the player is currently in.
        new vehicleid;
        new pname[24];
        pname = GetName(playerid);
        new string[100];
        if(VEngine[vehicle] == 0) //This is checking if the engine of the vehicle, is turned off or not.
        {
            new engine, lights, alarm, doors, bonnet, boot, objective;
            GetVehicleParamsEx(vehicle, engine, lights, alarm, doors, bonnet, boot, objective);
            VEngine[vehicle] = 1;
            SetVehicleParamsEx(vehicle, 1, lights, alarm, doors, bonnet, boot, 0);
        }
        else
        {
            new engine, lights, alarm, doors, bonnet, boot, objective;
            GetVehicleParamsEx(vehicle, engine, lights, alarm, doors, bonnet, boot, objective);
            VEngine[vehicle] = 0;
            SetVehicleParamsEx(vehicle, 1, lights, alarm, doors, bonnet, boot, 0);
        }
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(PlayerToPlayer(playerid,i,7))
            {
                new enginestatus[4];
                if(VEngine[vehicle] == 0) { enginestatus = "Off"; }
                else if(VEngine[vehicle] == 1) { enginestatus = "On"; }
                new model = GetVehicleModel(vehicleid);
                strreplace(pname, '_', ' ');
                format(string, sizeof(string), "* %s has turned the engine of his %s %s *", pname, VehicleNames[model - 400], enginestatus);
                SendClientMessage(i, COLOR_PURPLE, string);
            }
        }
    }
    else return SendClientMessage(playerid, COLOR_WHITE, "You are not driving a vehicle!");
    return 1;
}
Thanks in advance,
Stevolas. Help is appreciated.

EDIT: Felt I should include some more information

pawn Код:
new VEngine[MAX_VEHICLES], VLights[MAX_VEHICLES]; //Global variable at top of script

//Under on vehicle spawn
VEngine[vehicleid] = 0;
VLights[vehicleid] = 0;
Reply
#2

Try this instead. Bit less messy.

pawn Код:
CMD:engine(playerid, params[])
{
    if(GetPlayerState(playerid) == 2)
    {
        new vehicleid = GetPlayerVehicleID(playerid), name[24] = GetName(playerid), string[100];
        new engine, lights, alarm, doors, bonnet, boot, objective;
        strreplace(name, '_', ' ');
        GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
        if(engine)
        {
            SetVehicleParamsEx(vehicleid, false, lights, alarm, doors, bonnet, boot, objective);
            format(string, 100, "* %s has turned the engine of his %s off. *", name, VehicleNames[GetVehicleModel(vehicleid)-400]);
        }
        else
        {
            SetVehicleParamsEx(vehicleid, true, lights, alarm, doors, bonnet, boot, objective);
            format(string, 100, "* %s has turned the engine of his %s on. *", name, VehicleNames[GetVehicleModel(vehicleid)-400]);
        }
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(PlayerToPlayer(playerid, i, 7))
            {
                SendClientMessage(i, COLOR_PURPLE, string);
            }
        }
    }
    else
    {
        SendClientMessage(playerid, COLOR_WHITE, "You are not driving a vehicle!");
    }
    return 1;
}
And put this to solve a bug that you will encounter on, trust me, using GetVehiceParamsEx.
pawn Код:
public OnVehicleSpawn(vehicleid)
{
    SetVehicleParamsEx(vehicleid, false, false, false, false, false, false, false);
    return 1;
}
EDIT: You can put the change the value of VEngine, but I just recommend using GetVehicleParamsEx
Reply
#3

I get an error saying its a constant expression or what not on this line:
pawn Код:
new vehicleid = GetPlayerVehicleID(playerid), name[24] = GetName(playerid), string[100];
Also, I realized when I do /engine inside the vehicle, it says unknown command, yet it still turns the engine on. While it does this, I can drive, but when i do /engine again, it doesn't shut down and says unknown command as well.

Anyone might know the cause?
Reply
#4

Still looking for a response, BUMP.
Reply
#5

maybe u can do like new vehicleid = GetPlayerVehicleID(playerid) and upside of getplayerstats new string[100]; and GetName(playerid) and all of that shit? maybe that will work?
Reply
#6

Doesn't change anything, that's just simplifying the command. I need it to actually work.

Right now, if i'm not in a car, it sends a client message saying i'm not in a vehicle. If i'm in a vehicle with the engine off, and i type it, it says "unknown command" although the engine still starts. if I do it with the engine on, it sends "Unknown command" and doesn't turn off the engine.
Reply
#7

Have you somewhere in your script the following callback?

pawn Код:
OnPlayerCommandPerformed(playerid, cmdtext[], success)
Reply
#8

hmm, try to change the format(string, in something else maybe is that the problem ?
Reply
#9

This is my newest command, yet, it does the same effect

pawn Код:
CMD:engine(playerid, params[])
{
    if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER) //This here is checking if the player is inside a vehicle as a driver.
    {
        new engine, lights, alarm, doors, bonnet, boot, objective;
        new vehicle = GetPlayerVehicleID(playerid); //This part here is defining the vehicle ID that the player is currently in.
        new pname[24], string[100], vehicleid, enginestatus[4];
        pname = GetName(playerid);
        GetVehicleParamsEx(vehicle, engine, lights, alarm, doors, bonnet, boot, objective);
        if(VEngine[vehicle] != 1) //This is checking if the engine of the vehicle, is turned off or not.
        {
            VEngine[vehicle] = 0;
            SetVehicleParamsEx(vehicle, 0, lights, alarm, doors, bonnet, boot, 0);
        }
        else
        {
            VEngine[vehicle] = 1;
            SetVehicleParamsEx(vehicle, 1, lights, alarm, doors, bonnet, boot, 0);
        }
        for(new i = 0; i < MAX_PLAYERS; i++)
        {
            if(PlayerToPlayer(playerid,i,7))
            {
                if(VEngine[vehicle] == 0) { enginestatus = "Off"; }
                else if(VEngine[vehicle] == 1) { enginestatus = "On"; }
                new model = GetVehicleModel(vehicleid);
                strreplace(pname, '_', ' ');
                format(string, sizeof(string), "* %s has turned the engine of his %s %s *", pname, VehicleNames[model - 400], enginestatus);
                SendClientMessage(i, COLOR_PURPLE, string);
            }
        }
    }
    else return SendClientMessage(playerid, COLOR_WHITE, "You are not driving a vehicle!");
    return 1;
}
That is not the problem.
Reply
#10

Alright, so I fixed the command, but whenever I get in the vehicle, the engine is turned on. This is the OnVehicle Spawn:

pawn Код:
public OnVehicleSpawn(vehicleid)
{
    SetVehicleParamsEx(vehicleid, false, false, false, false, false, false, false);
    return 1;
}
Can someone help me? The engine should be off *^^* because the engine is set to false, yet all cars have their engines on when I get in it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)