Engine timer
#1

I have a command that starts a vehicle's engine, but i want so that when you use the command, it takes 3 seconds before the engine actually starts, but i dont know how to do that.
Reply
#2

Show your engine command.
Reply
#3

Use SetTimerEx to start a timer and move the functions you use to start the engine from the command to the timer-function.
Reply
#4

pawn Код:
CMD:engine(playerid, params[])
{
     SetTimer("start", 3000, false);
     return 1;
}

forward start(playerid);

public start(playerid)
{
      SetVehicleParams(vehicleid, 0, 1, 0, 0, 0, 0, 0);
      return 1;
}
Reply
#5

Quote:
Originally Posted by Schneider
Посмотреть сообщение
Use SetTimerEx to start a timer and move the functions you use to start the engine from the command to the timer-function.
Can you explain further how to do this?
Reply
#6

pawn Код:
cmd:engine(playerid, params[])
{
    if((IsPlayerInAnyVehicle(playerid)) && (GetPlayerState(playerid) == PLAYER_STATE_DRIVER))
    {
        SetTimerEx("StartEngine", 3000, false, "i", playerid);
    }
    else
    {
        SendClientMessage(playerid, 0xFF0000AA, "You are not in a vehicle");
    }
    return 1;
}

forward StartEngine(playerid);
public StartEngine(playerid)
{
    new vid = GetPlayerVehicleID(playerid);
    SetVehicleParams(vid, 0, 1, 0, 0, 0, 0, 0);
    return 1;
}
Reply
#7

pawn Код:
CMD:engine(playerid, params[])
{
    new engine, lights, alarm, doors, bonnet, boot, objective, vehicleid, string[128];
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
    if(!PlayerInfo[playerid][pVeh] && !PlayerInfo[playerid][pVVeh] && !PlayerInfo[playerid][pBVeh]) return SendClientMessage(playerid, COLOR_GREY, "You don't own a vehicle.");
    if(GetPlayerVehicleID(playerid) != PlayerInfo[playerid][pVeh] && GetPlayerVehicleID(playerid) != PlayerInfo[playerid][pVVeh] && GetPlayerVehicleID(playerid) != PlayerInfo[playerid][pBVeh]) return SendClientMessage(playerid, COLOR_GREY, "You dont have the keys for this vehicle.");
    if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessage(playerid, COLOR_GREY, "You are not driving a vehicle.");
    if(vehicleid == 509 || vehicleid == 481 || vehicleid == 510) return SendClientMessage(playerid, COLOR_GREY, "Bicycles have no engine.");
    vehicleid = GetPlayerVehicleID(playerid);
    GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
    if(!engine)
    {
        SetVehicleParamsEx(vehicleid, 1, lights, alarm, doors, bonnet, boot, objective);
        if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pVeh])
        {SetVehicleParamsEx(vehicleid, 1, lights, alarm, PlayerInfo[playerid][vLocked], bonnet, boot, objective);}
        else if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pVVeh])
        {SetVehicleParamsEx(vehicleid, 1, lights, alarm, PlayerInfo[playerid][vVLocked], bonnet, boot, objective);}
        else if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pBVeh])
        {SetVehicleParamsEx(vehicleid, 1, lights, alarm, PlayerInfo[playerid][vBLocked], bonnet, boot, objective);}
        format(string, sizeof(string), "* %s turns the key's engine on.", RPN(playerid));
        if(PlayerInfo[playerid][pMaskOn] == 1)
        {
            format(string, sizeof(string), "* Stranger puts their key in the ignition and turns it.");
        }
        else
        {
            format(string, sizeof(string), "* %s puts their key in the ignition and turns it.", RPN(playerid));
        }
        SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
    }
    else
    {
        SetVehicleParamsEx(vehicleid, 0, lights, alarm, doors, bonnet, boot, objective);
        if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pVeh])
        {SetVehicleParamsEx(vehicleid, 0, lights, alarm, PlayerInfo[playerid][vLocked], bonnet, boot, objective);}
        if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pVVeh])
        {SetVehicleParamsEx(vehicleid, 0, lights, alarm, PlayerInfo[playerid][vVLocked], bonnet, boot, objective);}
        if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pBVeh])
        {SetVehicleParamsEx(vehicleid, 0, lights, alarm, PlayerInfo[playerid][vBLocked], bonnet, boot, objective);}
        format(string, sizeof(string), "* %s turns the vehicle's engine off.", RPN(playerid));
        if(PlayerInfo[playerid][pMaskOn] == 1)
        {
            format(string, sizeof(string), "* Stranger turns the key in the ignition and takes it out.");
        }
        else
        {
            format(string, sizeof(string), "* %s turns the key in the ignition and takes it out.", RPN(playerid));
        }
        SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
    }
    return 1;
}
This is the code, how should i put it in?
Reply
#8

Bump.
Reply
#9

Second bump.
Reply
#10

pawn Код:
CMD:engine(playerid, params[])
{
    new vehicleid = GetPlayerVehicleID(playerid);
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
    if(!PlayerInfo[playerid][pVeh] && !PlayerInfo[playerid][pVVeh] && !PlayerInfo[playerid][pBVeh]) return SendClientMessage(playerid, COLOR_GREY, "You don't own a vehicle.");
    if(GetPlayerVehicleID(playerid) != PlayerInfo[playerid][pVeh] && GetPlayerVehicleID(playerid) != PlayerInfo[playerid][pVVeh] && GetPlayerVehicleID(playerid) != PlayerInfo[playerid][pBVeh]) return SendClientMessage(playerid, COLOR_GREY, "You dont have the keys for this vehicle.");
    if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER) return SendClientMessage(playerid, COLOR_GREY, "You are not driving a vehicle.");
    if(vehicleid == 509 || vehicleid == 481 || vehicleid == 510) return SendClientMessage(playerid, COLOR_GREY, "Bicycles have no engine.");
    SetTimerEx("StartEngine", 3000, false, "ii", playerid, vehicleid);
    return 1;
}

forward StartEngine(playerid, vehicleid);
public StartEngine(playerid, vehicleid)
{
    new engine, lights, alarm, doors, bonnet, boot, objective, string[128];
    GetVehicleParamsEx(vehicleid, engine, lights, alarm, doors, bonnet, boot, objective);
    if(engine != 1)
    {
        SetVehicleParamsEx(vehicleid, 1, lights, alarm, doors, bonnet, boot, objective);
        if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pVeh])
        {SetVehicleParamsEx(vehicleid, 1, lights, alarm, PlayerInfo[playerid][vLocked], bonnet, boot, objective);}
        else if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pVVeh])
        {SetVehicleParamsEx(vehicleid, 1, lights, alarm, PlayerInfo[playerid][vVLocked], bonnet, boot, objective);}
        else if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pBVeh])
        {SetVehicleParamsEx(vehicleid, 1, lights, alarm, PlayerInfo[playerid][vBLocked], bonnet, boot, objective);}
        format(string, sizeof(string), "* %s turns the key's engine on.", RPN(playerid));
        if(PlayerInfo[playerid][pMaskOn] == 1)
        {
            format(string, sizeof(string), "* Stranger puts their key in the ignition and turns it.");
        }
        else
        {
            format(string, sizeof(string), "* %s puts their key in the ignition and turns it.", RPN(playerid));
        }
        SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
    }
    else
    {
        SetVehicleParamsEx(vehicleid, 0, lights, alarm, doors, bonnet, boot, objective);
        if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pVeh])
        {SetVehicleParamsEx(vehicleid, 0, lights, alarm, PlayerInfo[playerid][vLocked], bonnet, boot, objective);}
        if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pVVeh])
        {SetVehicleParamsEx(vehicleid, 0, lights, alarm, PlayerInfo[playerid][vVLocked], bonnet, boot, objective);}
        if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pBVeh])
        {SetVehicleParamsEx(vehicleid, 0, lights, alarm, PlayerInfo[playerid][vBLocked], bonnet, boot, objective);}
        format(string, sizeof(string), "* %s turns the vehicle's engine off.", RPN(playerid));
        if(PlayerInfo[playerid][pMaskOn] == 1)
        {
            format(string, sizeof(string), "* Stranger turns the key in the ignition and takes it out.");
        }
        else
        {
            format(string, sizeof(string), "* %s turns the key in the ignition and takes it out.", RPN(playerid));
        }
        SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
    }
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)