Help with starting engine using key
#1

I need help. I have tried and tried to get this to work... I can't figure out whats wrong!

The key doesn't start the engine for the first time, but if I do /engine (twice: on and then off again) and then try pressing the key it turns on perfectly. Whats wrong with my key code and why does it work with /engine?!?

Key Code:
pawn Код:
if (PRESSED(KEY_HANDBRAKE))
    {
        new idcar = GetPlayerVehicleID(playerid);
        if(IsPlayerConnected(playerid))
        {
            if(IsPlayerInAnyVehicle(playerid))
            {
                if(gEngine[idcar] == 0)
                {
                    if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER) return 1;
                    if(pveh == 510 || pveh == 462 || pveh == 481 || pveh == 509) return 1;
                    if(IsARentableCar(idcar))
                    {
                        if(HireCar[playerid] != idcar) return 1;
                    }
                    if(IsAHarvest(idcar)) return 1;
                    if(IsADrugHarvest(idcar)) return 1;
                    if(IsASweeper(idcar)) return 1;


                    if(CanTurnEngine[playerid] != idcar && CanTurnEngine[playerid] == 9999)
                        return SendClientMessage(playerid, COLOR_GREY,"* You cannot turn this car's engine!");

                    format(string, sizeof(string), "* %s spins a key and tries to start vehicle engine.", sendername);
                    ProxDetector(30.0, playerid, string, COLOR_CHAT1,COLOR_CHAT2,COLOR_CHAT3,COLOR_CHAT4,COLOR_CHAT5);
                    SetTimerEx("StartingTheVehicle",3500,0,"i",playerid);
                    GameTextForPlayer(playerid, "~w~Starting vehicle engine...",3500,3);
                    gEngine[idcar] = 1;
                    new engine,lights,alarm,doors,bonnet,boot,objective;
                    GetVehicleParamsEx(GetPlayerVehicleID(playerid),engine,lights,alarm,doors,bonnet,boot,objective);
                    SetVehicleParamsEx(GetPlayerVehicleID(playerid), 1, lights, 0, 0, 0, 0, 0);
                    new y, m, d;
                    new h,mi,s;
                    getdate(y,m,d);
                    gettime(h,mi,s);
                    format(string,sizeof(string), "(%d/%d/%d)[%d:%d:%d] %s [CMD] -> /engine",d,m,y,h,mi,s,sendername);
                    CommandLog(string);
                    return 1;
                }
            }
        }
    }
/engine code:
pawn Код:
if(!strcmp(cmd, "/engine", true))
    {
        if(IsPlayerConnected(playerid))
        {
            if(IsPlayerInAnyVehicle(playerid))
            {
                if(gEngine[idcar] == 0)
                {
                    if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER) return 1;
                    if(pveh == 510 || pveh == 462 || pveh == 481 || pveh == 509) return 1;
                    if(IsARentableCar(idcar))
                    {
                        if(HireCar[playerid] != idcar) return 1;
                    }
                    if(IsAHarvest(idcar)) return 1;
                    if(IsADrugHarvest(idcar)) return 1;
                    if(IsASweeper(idcar)) return 1;


                    if(CanTurnEngine[playerid] != idcar && CanTurnEngine[playerid] == 9999)
                        return SendClientMessage(playerid, COLOR_GREY,"* You cannot turn this car's engine!");

                    format(string, sizeof(string), "* %s spins a key and tries to start vehicle engine.", sendername);
                    ProxDetector(30.0, playerid, string, COLOR_CHAT1,COLOR_CHAT2,COLOR_CHAT3,COLOR_CHAT4,COLOR_CHAT5);
                    SetTimerEx("StartingTheVehicle",3500,0,"i",playerid);
                    GameTextForPlayer(playerid, "~w~Starting vehicle engine...",3500,3);
                    gEngine[idcar] = 1;
                    new engine,lights,alarm,doors,bonnet,boot,objective;
                    GetVehicleParamsEx(GetPlayerVehicleID(playerid),engine,lights,alarm,doors,bonnet,boot,objective);
                    SetVehicleParamsEx(GetPlayerVehicleID(playerid), 1, lights, 0, 0, 0, 0, 0);
                    new y, m, d;
                    new h,mi,s;
                    getdate(y,m,d);
                    gettime(h,mi,s);
                    format(string,sizeof(string), "(%d/%d/%d)[%d:%d:%d] %s [CMD] -> /engine",d,m,y,h,mi,s,sendername);
                    CommandLog(string);
                    return 1;
                }
                else if(gEngine[idcar] == 1)
                {
                    if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER) return 1;
                    if(pveh == 510 || pveh == 462 || pveh == 481 || pveh == 509) return 1;
                    if(IsARentableCar(idcar))
                    {
                        if(HireCar[playerid] != idcar) return 1;
                    }
                    if(IsAHarvest(idcar)) return 1;
                    if(IsADrugHarvest(idcar)) return 1;
                    if(IsASweeper(idcar)) return 1;

                    if(CanTurnEngine[playerid] != idcar && CanTurnEngine[playerid] == 9999)
                        return SendClientMessage(playerid, COLOR_GREY,"* You cannot turn this car's engine!");

                    format(string, sizeof(string), "* %s spins a key and turns off the engine.", sendername);
                    ProxDetector(30.0, playerid, string, COLOR_CHAT1,COLOR_CHAT2,COLOR_CHAT3,COLOR_CHAT4,COLOR_CHAT5);
                    GameTextForPlayer(playerid, "~w~Engine Has Shut Down.",3500,3);
                    gEngine[idcar] = 0;
                    new engine,lights,alarm,doors,bonnet,boot,objective;
                    GetVehicleParamsEx(GetPlayerVehicleID(playerid),engine,lights,alarm,doors,bonnet,boot,objective);
                    SetVehicleParamsEx(GetPlayerVehicleID(playerid), 0, lights, 0, 0, 0, 0, 0);
                    new y, m, d;
                    new h,mi,s;
                    getdate(y,m,d);
                    gettime(h,mi,s);
                    format(string,sizeof(string), "(%d/%d/%d)[%d:%d:%d] %s [CMD] -> /engine",d,m,y,h,mi,s,sendername);
                    CommandLog(string);
                    return 1;
                }
            }
        }
        return 1;
    }
Reply
#2

pawn Код:
if (PRESSED(KEY_HANDBRAKE))
    {
        new idcar = GetPlayerVehicleID(playerid);
        if(IsPlayerConnected(playerid))
        {
            print("conected");
            if(IsPlayerInAnyVehicle(playerid))
            {
                print("in any car");  
                if(gEngine[idcar] == 0)
                {
                    print("gEngine is 0");
                    if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER) return 1;
                    if(pveh == 510 || pveh == 462 || pveh == 481 || pveh == 509) return 1;
                    if(IsARentableCar(idcar))
                    {
                        if(HireCar[playerid] != idcar) return 1;
                    }
                    if(IsAHarvest(idcar)) return 1;
                    if(IsADrugHarvest(idcar)) return 1;
                    if(IsASweeper(idcar)) return 1;
                    print("not forbiden");


                    if(CanTurnEngine[playerid] != idcar && CanTurnEngine[playerid] == 9999)
                        return SendClientMessage(playerid, COLOR_GREY,"* You cannot turn this car's engine!");

                    format(string, sizeof(string), "* %s spins a key and tries to start vehicle engine.", sendername);
                    ProxDetector(30.0, playerid, string, COLOR_CHAT1,COLOR_CHAT2,COLOR_CHAT3,COLOR_CHAT4,COLOR_CHAT5);
                    SetTimerEx("StartingTheVehicle",3500,0,"i",playerid);
                    GameTextForPlayer(playerid, "~w~Starting vehicle engine...",3500,3);
                    gEngine[idcar] = 1;
                    print("gEngine is 1");
                    new engine,lights,alarm,doors,bonnet,boot,objective;
                    GetVehicleParamsEx(GetPlayerVehicleID(playerid),engine,lights,alarm,doors,bonnet,boot,objective);
                    SetVehicleParamsEx(GetPlayerVehicleID(playerid), 1, lights, 0, 0, 0, 0, 0);
                    print("Engine is ON");
                    new y, m, d;
                    new h,mi,s;
                    getdate(y,m,d);
                    gettime(h,mi,s);
                    format(string,sizeof(string), "(%d/%d/%d)[%d:%d:%d] %s [CMD] -> /engine",d,m,y,h,mi,s,sendername);
                    CommandLog(string);
                    return 1;
                }
            }
        }
    }
Replace with you command and show me server log.
Reply
#3

Ok I did and It didn't show any signs of it working:

Код:
[16:46:06]   Loaded.
[16:46:06]  Loading plugin: sscanf
[16:46:06] 

[16:46:06]  ===============================

[16:46:06]       sscanf plugin loaded.     

[16:46:06]    © 2009 Alex "******" Cole

[16:46:06]    0.3d-R2 500 Players "dnee"

[16:46:06]  ===============================

[16:46:06]   Loaded.
[16:46:06]  Loaded 2 plugins.

[16:46:06] 
[16:46:06] Filterscripts
[16:46:06] ---------------
[16:46:06]   Loading filterscript 'mapeditor.amx'...
[16:46:06] >> SA-MP Map Editor Loaded
[16:46:06]   Loading filterscript 'baitcar.amx'...
[16:46:06]   Loading filterscript 'snow.amx'...
[16:46:06]   Loading filterscript 'boombox.amx'...
[16:46:06]   Loading filterscript 'real_lights.amx'...
[16:46:06] 
--------------------------------------
[16:46:06]  Infinite-Gaming.com Presents:
[16:46:06]  Real Vehicle Lights v2 by Cyber_Punk
[16:46:06] --------------------------------------

[16:46:06]   Loading filterscript 'lights.amx'...
[16:46:06]   Unable to load filterscript 'lights.amx'.
[16:46:06]   Loading filterscript 'GiftBox.amx'...
[16:46:06] 
--------------------------------------------------
[16:46:06]  Holiday Update! Creator, MouseBreaker (v1.0)
[16:46:06] --------------------------------------------------

[16:46:06]   Loaded 6 filterscripts.

[16:46:09] [SCRIPT]: Loaded Houses
[16:46:09] [SCRIPT]: Loaded Bizzes
[16:46:09] [SCRIPT]: Loaded S-Bizzes
[16:46:09] weburl = "jakesroleplay.frmods.com"  (string)
[16:46:09] AllowAdminTeleport() : function is deprecated. Please see OnPlayerClickMap()
[16:46:09] [SCRIPT]: Loaded 1438 Objects
[16:46:09] [SCRIPT]: Loaded 801 Pickups
[16:46:09]  
[16:46:09]         Jake's Roleplay 
[16:46:09] _________________________________________
[16:46:09]        By: CuervO_NegrO & Jared_Isa   
[16:46:09]  
[16:46:09] Number of vehicle models: 190
[16:47:00] Incoming connection: 192.168.0.3:54081
[16:47:01] [join] Jared_Isa has joined the server (0:192.168.0.3)
But again it worked when I used /engine first and then it showed all the messages you added in the server log.

ALSO NOTE that I have this script under in my GM:
pawn Код:
Public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)