Problem with my /engine command
#1

Hi guys, what's up?
I'm trying to make an /engine command. It works fine. Problem is, when I enter a vehicle, and /engine it says that I turned off the engine (When it was already off), and only after that it says that I turned it on (and turns it on).
What's the problem? Here's my code:
pawn Код:
CMD:engine(playerid, params[]) {
    if (GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SCM(playerid, COLOR_RED, "You have to be the driver!");
    new engine, lights, alarm, doors, bonnet, boot, objective;
    new pname[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pname, sizeof(pname));
    strreplace(pname, '_', ' ');
    GetVehicleParamsEx(GetPlayerVehicleID(playerid), engine, lights, alarm, doors, bonnet, boot, objective);
    if (!engine) {
            SetVehicleParamsEx(GetPlayerVehicleID(playerid), 1, 1, alarm, doors, bonnet, boot, objective);
            format(str, sizeof(str), "* %s attempts to turn on the engine, and succeeds", pname);
            ProxDetector(30.0, playerid, str, COLOR_LIGHTGREEN,COLOR_LIGHTGREEN,COLOR_LIGHTGREEN,COLOR_LIGHTGREEN,COLOR_LIGHTGREEN);
    } else if (engine) {
            SetVehicleParamsEx(GetPlayerVehicleID(playerid), 0, 0, alarm, doors, bonnet, boot, objective);
            format(str, sizeof(str), "* %s attempts to turn off the engine, and succeeds", pname);
            ProxDetector(30.0, playerid, str, COLOR_PINK,COLOR_PINK,COLOR_PINK,COLOR_PINK,COLOR_PINK);
    }
    return 1;
}
Thanks !
Reply
#2

Your indentation style kills me, anyways I've taken the /engine command from my script and changed it to fit on yours, also use this stock instead of GetPlayerName on every single command and place RPNU(playerid) instead of pname

pawn Код:
stock RPNU(playerid)
{
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    for(new i = 0; i < MAX_PLAYER_NAME; i++)
    {
        if(name[i] == '_') name[i] = ' ';
    }
    return name;
}
pawn Код:
CMD:engine(playerid, params[])
{
    new engine, lights, alarm, doors, bonnet, boot, objective, vehicleid, string[128];
    if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessage(playerid, COLOR_GREY, "You are not driving a vehicle.");
    vehicleid = GetPlayerVehicleID(playerid);
    GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
    if(!engine)
    {
        SetVehicleParamsEx(vehicleid, 1, lights, alarm, doors, bonnet, boot, objective);
        format(string, sizeof(string), "* %s attempts to turn on the engine, and succeeds", RPNU(playerid));
        ProxDetector(30.0, playerid, str, COLOR_LIGHTGREEN,COLOR_LIGHTGREEN,COLOR_LIGHTGREEN,COLOR_LIGHTGREEN,COLOR_LIGHTGREEN);
    }
    else
    {
        SetVehicleParamsEx(vehicleid, 0, lights, alarm, doors, bonnet, boot, objective);
        format(string, sizeof(string), "* %s attempts to turn off the engine, and succeeds", RPNU(playerid));
        ProxDetector(30.0, playerid, str, COLOR_PINK,COLOR_PINK,COLOR_PINK,COLOR_PINK,COLOR_PINK);
    }
    return 1;
}
Reply
#3

Thanks, really like the RPNU .
I really appreciate your help. (rep+)
But still, it first turns the engine off (Even when it's already off), and only then turns it on (When typing /engine again ofc). I can't really see what is wrong. :S
Reply
#4

Use this under OnVehicleSpawn
pawn Код:
SetVehicleParamsEx(vehicleid, 0, 0, 0, 0, 0, 0, 0);
If you have a lock system for vehicles you will have to make it detect if the vehicle is locked and if so it would do this
pawn Код:
SetVehicleParamsEx(vehicleid, 0, 0, 0, 1, 0, 0, 0);

Same applies with the /engine command, it would unlock vehicles on /engine until you make it detect if the vehicle is locked and change the 4th 0 to 1 in SetVehicleParamsEx
Reply
#5

Thanks, I'll try it later and edit .
Reply
#6

how to change it to start with key 2 its starting with shift or /engline i want with 2
Reply
#7

Verbal, no need to do what iRage said to do.

Instead of:
pawn Код:
if(!engine)
Use:
pawn Код:
if(engine != 1)
Then it'll work.
Reply
#8

Change the key SHIFT to KEY_SUBMISSION check GetPlayerKeys on Wiki.SA-MP.
Reply
#9

Thank you very much Riddick94! Rep+
Reply
#10

Quote:
Originally Posted by Jack_Leslie
Посмотреть сообщение
Verbal, no need to do what iRage said to do.

Instead of:
pawn Код:
if(!engine)
Use:
pawn Код:
if(engine != 1)
Then it'll work.
!engine = 0
engine != 1 = 0 in engine's case

Get your facts straight smart man.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)