/engine timer bug
#1

Hi guys!
I created an engine system for my script (based off of Vortex 2).

However, upon using the command, it does everything fine leading up to the timer.
However for some reason, the timer works on ID 0. For example if I were ID 4, and I typed /hotwire in a vehicle, it would display everything fine, and all would be well, except that it doesn't start my engine and it submits the "Engine Started!" message to ID 0.

Can anybody help me out? I've tried multiple things but I can't figure out what is causing it.

pawn Код:
CMD:engine(playerid, params[]) {
    if(GetPlayerState(playerid) != 2)
        return SendClientMessage(playerid, COLOR_GREY, "You are not driving a vehicle!");
       
    new vid = GetPlayerVehicleID(playerid);
    new Float:health;

    GetVehicleHealth(vid, health);
    if(health <= 450) {
        format(szMessage, sizeof(szMessage), "* %s's engine stalls as they attempt to start the vehicle.", playerVariables[playerid][pNormalName]);
        nearByMessage(playerid, COLOR_PURPLE, szMessage);
        SendClientMessage(playerid, COLOR_GREY, "You must call a mechanic to fix this vehicle before it can be used again.");
        return 1;
    }
       
    if(Engine[vid] == 0 && health > 450) {
        if(vehicleVariables[vid][vVehicleGroup] == playerVariables[playerid][pGroup] || vid == playerVariables[playerid][pCarID]) {
            SetTimer("StartEngine", 2000, false);
            format(szMessage, sizeof(szMessage), "* %s turns the key in the ignition, starting the vehicle.", playerVariables[playerid][pNormalName]);
            nearByMessage(playerid, COLOR_PURPLE, szMessage);
            return 1;
        }
        else {
            return SendClientMessage(playerid, COLOR_GREY, "You do not have a key to this vehicle. Please use /hotwire.");
        }
    }
   
    if(Engine[vid] == 1 && health > 450) {
        new engine,lights,alarm,doors,bonnet,boot,objective;
        GetVehicleParamsEx(vid, engine, lights, alarm, doors, bonnet, boot, objective);
        SetVehicleParamsEx(vid, 0, 0, alarm, doors, bonnet, boot, objective);
        format(szMessage, sizeof(szMessage), "* %s turns the key in the ignition, disabling the vehicle.", playerVariables[playerid][pNormalName]);
        nearByMessage(playerid, COLOR_PURPLE, szMessage);
        Engine[vid] = 0;
        Lights[vid] = 0;
        return 1;
    }
    return 1;
}
pawn Код:
CMD:hotwire(playerid, params[]) {
    if(GetPlayerState(playerid) != 2)
        return SendClientMessage(playerid, COLOR_GREY, "You are not driving a vehicle!");
       
    new vid = GetPlayerVehicleID(playerid);
    new Float:health;
    GetVehicleHealth(vid, health);
   
    if(health <= 450) {
        format(szMessage, sizeof(szMessage), "* %s fiddles with a few wires under the dashboard, and the engine stalls as they attempt to hotwire it.", playerVariables[playerid][pNormalName]);
        nearByMessage(playerid, COLOR_PURPLE, szMessage);
        SendClientMessage(playerid, COLOR_GREY, "This vehicle must be fixed before it can be used again.");
        return 1;
    }
   
    if(Engine[vid] == 0 && health > 450) {
        if(playerVariables[playerid][pToolkit] == 1) {
            SetTimer("StartEngine", 2000, false);
            format(szMessage, sizeof(szMessage), "* %s fiddles with a few wires under the dashboard, and the engine starts as they hotwire it.", playerVariables[playerid][pNormalName]);
            nearByMessage(playerid, COLOR_PURPLE, szMessage);
            return 1;
        }
        else {
            return SendClientMessage(playerid, COLOR_GREY, "You do not have a tool kit! Buy one at a 24/7.");
        }
    }
    else {
        return SendClientMessage(playerid, COLOR_GREY, "The engine is already started! Use /engine to stop it.");
    }
}
pawn Код:
forward StartEngine(const playerid);
public StartEngine(const playerid) {
    new engine,lights,alarm,doors,bonnet,boot,objective;
    GetVehicleParamsEx(GetPlayerVehicleID(playerid), engine, lights, alarm, doors, bonnet, boot, objective);
    SetVehicleParamsEx(GetPlayerVehicleID(playerid), 1, 1, alarm, doors, bonnet, boot, objective);
    Engine[GetPlayerVehicleID(playerid)] = 1;
    Lights[GetPlayerVehicleID(playerid)] = 1;
    SendClientMessage(playerid, COLOR_GREEN, "Engine started!");
}
Thanks for any help given!

With kind regards,
Eric.
Reply
#2

if(GetPlayerState(playerid) != 2)

Whats can helps you this ? lvl 2 + can do /engine ?
Reply
#3

Quote:
Originally Posted by BigBaws
Посмотреть сообщение
if(GetPlayerState(playerid) != 2)

Whats can helps you this ? lvl 2 + can do /engine ?
No. This checks if they're driving a vehicle or not.
Reply
#4

You're using SetTimer, and not SetTimeEx.

pawn Код:
SetTimer("StartEngine", 2000, false);
With SetTimer, you can't pass extra parameters, watch this code:

pawn Код:
public StartEngine(const playerid)
StartEngine has 1 parameter which is "playerid" but can't be passed because you're using SetTimer, however, if you did this:

pawn Код:
SetTimerEx("StartingEngine", 2000, false, "d", playerid);
First you put the specifiers to know how many parameters you want to pass, and their type, then list them.
You could even do this:

pawn Код:
SetTimerEx("StartEngine", 2000, false, "dd", playerid, vehicleid);
This is how you do it with multiple parameters.

For future reference, you don't have to use the 'const' keyword in this situation, as it becomes a read-only variable that can't be altered by the program after initialised, at least in C / C++.
Reply
#5

Quote:
Originally Posted by admantis
Посмотреть сообщение
You're using SetTimer, and not SetTimeEx.

pawn Код:
SetTimer("StartEngine", 2000, false);
With SetTimer, you can't pass extra parameters, watch this code:

pawn Код:
public StartEngine(const playerid)
StartEngine has 1 parameter which is "playerid" but can't be passed because you're using SetTimer, however, if you did this:

pawn Код:
SetTimerEx("StartingEngine", 2000, false, "d", playerid);
First you put the specifiers to know how many parameters you want to pass, and their type, then list them.
You could even do this:

pawn Код:
SetTimerEx("StartEngine", 2000, false, "dd", playerid, vehicleid);
This is how you do it with multiple parameters.
Ahh, I see. Alright. I think I've got it from here.
Thanks!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)