Help with engine script (in GM)
#1

Can someone please help me fix the major problem with this Gamemode script. The problem is that once the engine is turned off, it will not re-start. When starting it again it says it's on, but it will not let me drive (does not matter if I get back in or not)... Can someone please help me fix this.

Thanks so much: jakejohnsonusa

Код:
if(!strcmp(cmd, "/engine", true)) 
    { 
        if(IsPlayerInAnyVehicle(playerid)) 
        { 
            if(IsPlayerConnected(playerid)) 
            { 
                if(!engineOn[GetPlayerVehicleID(playerid)]) 
                { 
                    if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER) return 1; 
                    if(pveh == 510 || pveh == 462 || pveh == 481 || pveh == 509) return 1; 
                    { 
                        if(HireCar[playerid] != idcar) return 1; 
                    } 
                    if(IsAHarvest(idcar)) return 1; 
                    if(IsADrugHarvest(idcar)) return 1; 
                    if(IsASweeper(idcar)) return 1; 
                    if(IsASalesVehicle(idcar)) return 1; 

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

                    new plname[MAX_PLAYER_NAME]; 
                    GetPlayerName(playerid, plname, sizeof(plname)); 

                    format(string, sizeof(string), "* %s spins a key and tries to start vehicle engine.", plname); 
                    ProxDetector(30.0, playerid, string, COLOR_CHAT1,COLOR_CHAT2,COLOR_CHAT3,COLOR_CHAT4,COLOR_CHAT5); 
                    if(PlayerInfo[playerid][pAdmin] < 1337 && PlayerInfo[playerid][pAdminDuty] == 1) 
                    { 
                        SetTimerEx("StartingTheVehicle",1,0,"i",playerid); 
                    } 
                    else 
                    { 
                        SetTimerEx("StartingTheVehicle",3500,0,"i",playerid); 
                    } 
                    GameTextForPlayer(playerid, "~w~Starting vehicle engine...",3500,3); 
                    gEngine[playerid] = 1; 
                    new vid = GetPlayerVehicleID(playerid); 
                    new engine,lights,alarm,doors,bonnet,boot,objective; 
                    GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective); 
                    SetVehicleParamsEx(vid,1,lights,alarm,doors,bonnet,boot,objective); 
                //    engineOn[GetPlayerVehicleID(playerid)] = true; 
                    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(engineOn[GetPlayerVehicleID(playerid)]) 
                { 
                    if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER) return 1; 
                    if(pveh == 510 || pveh == 462 || pveh == 481 || pveh == 509) return 1; 
                    if(IsASalesVehicle(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 Turned Off.",3500,3); 
                    gEngine[playerid] = 0; 
                    new vid = GetPlayerVehicleID(playerid); 
                    new engine,lights,alarm,doors,bonnet,boot,objective; 
                    GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective); 
                    SetVehicleParamsEx(vid,0,lights,alarm,doors,bonnet,boot,objective); 
                    engineOn[GetPlayerVehicleID(playerid)] = false; 
                    TogglePlayerControllable(playerid, 0);//// ath the dealship's in the game, you can go there and try to get a car, buy when you do /v it spawns you a car, but you can take it away, idk how you can buy it,can you fix it where they cant leave with the car, they have to buy it first? 
                    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

Please somebody help fix this.... PLEASEEE

Thanks: jakejohnsonusa
Reply
#3

Anyone please help me...
Reply
#4

Try this:

pawn Код:
if(!strcmp(cmd, "/engine", true))
    {
        if(IsPlayerInAnyVehicle(playerid))
        {
            if(IsPlayerConnected(playerid))
            {
                if(!engineOn[GetPlayerVehicleID(playerid)])
                {
                    if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER) return 1;
                    if(pveh == 510 || pveh == 462 || pveh == 481 || pveh == 509) return 1;
                    {
                        if(HireCar[playerid] != idcar) return 1;
                    }
                    if(IsAHarvest(idcar)) return 1;
                    if(IsADrugHarvest(idcar)) return 1;
                    if(IsASweeper(idcar)) return 1;
                    if(IsASalesVehicle(idcar)) return 1;

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

                    new plname[MAX_PLAYER_NAME];
                    GetPlayerName(playerid, plname, sizeof(plname));

                    format(string, sizeof(string), "* %s spins a key and tries to start vehicle engine.", plname);
                    ProxDetector(30.0, playerid, string, COLOR_CHAT1,COLOR_CHAT2,COLOR_CHAT3,COLOR_CHAT4,COLOR_CHAT5);
                    if(PlayerInfo[playerid][pAdmin] < 1337 && PlayerInfo[playerid][pAdminDuty] == 1)
                    {
                        SetTimerEx("StartingTheVehicle",1,0,"i",playerid);
                    }
                    else
                    {
                        SetTimerEx("StartingTheVehicle",3500,0,"i",playerid);
                    }
                    GameTextForPlayer(playerid, "~w~Starting vehicle engine...",3500,3);
                    gEngine[playerid] = 1;
                    new vid = GetPlayerVehicleID(playerid);
                    new engine,lights,alarm,doors,bonnet,boot,objective;
                    GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
                    SetVehicleParamsEx(vid,1,lights,alarm,doors,bonnet,boot,objective);
                    engineOn[GetPlayerVehicleID(playerid)] = true;  // Why was this commented? lol
                    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(engineOn[GetPlayerVehicleID(playerid)])
                {
                    if(GetPlayerState(playerid) == PLAYER_STATE_PASSENGER) return 1;
                    if(pveh == 510 || pveh == 462 || pveh == 481 || pveh == 509) return 1;
                    if(IsASalesVehicle(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 Turned Off.",3500,3);
                    gEngine[playerid] = 0;
                    new vid = GetPlayerVehicleID(playerid);
                    new engine,lights,alarm,doors,bonnet,boot,objective;
                    GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
                    SetVehicleParamsEx(vid,0,lights,alarm,doors,bonnet,boot,objective);
                    engineOn[GetPlayerVehicleID(playerid)] = false;
                    TogglePlayerControllable(playerid, 0);//// ath the dealship's in the game, you can go there and try to get a car, buy when you do /v it spawns you a car, but you can take it away, idk how you can buy it,can you fix it where they cant leave with the car, they have to buy it first?
                    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
#5

OK, will test and PM you... Thanks +1 Rep. added.
Reply
#6

Same problem. Engine will not start after shuttind down... (please help me fix this anyone)...
Reply
#7

What happens if you try to start the engine when it shuts down?
Reply
#8

im with jakejohnsonusa he runs the server and im a admin and kinda a scripter but what happens when you shut down the engine then try to start it back up.when you try to start it back up again it said engine started but the engine is not started it just stays off
Reply
#9

Why don't you try to improve your codes by removing the "engineOn" variable? This is a start, edit so it fits your script. And like I said in an other topic, try to learn by yourself, stop taking the codes of other GM or FS. The codes are always easier to understand when you made them yourself. Plus, if you learn, you'll reduce posting in scripting help.
pawn Код:
if(!strcmp(cmd, "/engine", true))
    {
        if(IsPlayerInAnyVehicle(playerid))
        {
            if(IsPlayerConnected(playerid))
            {
                new vid = GetPlayerVehicleID(playerid);
                new engine,lights,alarm,doors,bonnet,boot,objective;
                GetVehicleParamsEx(vid,engine,lights,alarm,doors,bonnet,boot,objective);
                if(engine == 0)
                {
                    SetVehicleParamsEx(vid,1,lights,alarm,doors,bonnet,boot,objective);
                    return 1;
                }
                else
                {
                    SetVehicleParamsEx(vid,0,lights,alarm,doors,bonnet,boot,objective);
                    return 1;
                }
            }
        }
        return 1;
    }
Edit: I forgot things in the codes.
Reply
#10

Thanks for your help and the tip. I had my own, but it caused problems, as I am horrble at scripting. I am learning more everyday, and soon will never need to post here again, hopefully. In the mean time I will check this script to see if it works. Thanks for your help. +1 Rep.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)