Jump to content

Car engine start


DzMGZXL

Recommended Posts

Okay i want make for my Roleplay server when you start engine it starts 3 secunds.When you press J it starts after 3 secunds.

I try use setTimer but i don't know why it doesn't work.

function toggleEngine(source, key, keystate) 
    local veh = getPedOccupiedVehicle(source) 
    local inVehicle = getElementData(source, "realinvehicle") 
  
    if veh and inVehicle == 1 then 
        local seat = getPedOccupiedVehicleSeat(source) 
         
        if (seat == 0) then 
            local model = getElementModel(veh) 
            if not (enginelessVehicle[model]) then 
                local engine = getElementData(veh, "engine") 
                local vehID = getElementData(veh, "dbid") 
                local vehKey = exports['global']:hasItem(source, 3, vehID) 
                if engine == 0 then 
                    local vjob = tonumber(getElementData(veh, "job")) 
                    local job = getElementData(source, "job") 
                    local owner = getElementData(veh, "owner") 
                    local faction = tonumber(getElementData(veh, "faction")) 
                    local playerFaction = tonumber(getElementData(source, "faction")) 
                    if (vehKey) or (owner < 0) and (faction == -1) or (playerFaction == faction) and (faction ~= -1) or ((getElementData(source, "adminduty") or 0) == 1) then 
                        local fuel = getElementData(veh, "fuel") 
                        local broke = getElementData(veh, "enginebroke") 
                        if broke == 1 then 
                            exports.global:sendLocalMeAction(source, "cenšās piestartēt transportlīdzekļa dzinēju, bet tas atsakās strādāt.") 
                            outputChatBox("Transportlīdzekļa dzinējs ir sabojājies.", source) 
                        elseif exports.global:hasItem(veh, 74) then 
                        elseif fuel >= 1 then 
                            toggleControl(source, 'brake_reverse', true) 
                            setVehicleEngineState(veh, true) 
                                                       setTimer(setVehicleEngineState, 9200, 1, true) 
                            exports['anticheat-system']:changeProtectedElementDataEx(veh, "engine", 1, false) 
                        elseif fuel < 1 then 
                            exports.global:sendLocalMeAction(source, "cenšās piestartēt transportlīdzekļa dzinēju, bet tas atsakās strādāt.") 
                            outputChatBox("Transportlīdzeklim ir beigusies degviela.", source) 
                        end 
                    else 
                        outputChatBox("Jums ir nepieciešamas transportlīdzekļa atslēgas, lai piestartētu tā dzinēju.", source, 255, 0, 0) 
                    end 
                else 
                    toggleControl(source, 'brake_reverse', false) 
                    setVehicleEngineState(veh, false) 
                    exports['anticheat-system']:changeProtectedElementDataEx(veh, "engine", 0, false) 
                end 
            end 
        end 
    end 
end 
addCommandHandler("engine", toggleEngine) 

Link to comment

Try it.

function toggleEngine(source, key, keystate) 
    local veh = getPedOccupiedVehicle(source) 
    local inVehicle = getElementData(source, "realinvehicle") 
  
    if veh and inVehicle == 1 then 
        local seat = getPedOccupiedVehicleSeat(source) 
        
        if (seat == 0) then 
            local model = getElementModel(veh) 
            if not (enginelessVehicle[model]) then 
                local engine = getElementData(veh, "engine") 
                local vehID = getElementData(veh, "dbid") 
                local vehKey = exports['global']:hasItem(source, 3, vehID) 
                if engine == 0 then 
                    local vjob = tonumber(getElementData(veh, "job")) 
                    local job = getElementData(source, "job") 
                    local owner = getElementData(veh, "owner") 
                    local faction = tonumber(getElementData(veh, "faction")) 
                    local playerFaction = tonumber(getElementData(source, "faction")) 
                    if (vehKey) or (owner < 0) and (faction == -1) or (playerFaction == faction) and (faction ~= -1) or ((getElementData(source, "adminduty") or 0) == 1) then 
                        local fuel = getElementData(veh, "fuel") 
                        local broke = getElementData(veh, "enginebroke") 
                        if broke == 1 then 
                            exports.global:sendLocalMeAction(source, "cenšās piestartēt transportlīdzekļa dzinēju, bet tas atsakās strādāt.") 
                            outputChatBox("Transportlīdzekļa dzinējs ir sabojājies.", source) 
                        elseif exports.global:hasItem(veh, 74) then 
                        elseif fuel >= 1 then 
                            toggleControl(source, 'brake_reverse', true) 
                            setVehicleEngineState(veh, true) 
                                                       setTimer(setVehicleEngineState, 9200, 1, true, veh) 
                            exports['anticheat-system']:changeProtectedElementDataEx(veh, "engine", 1, false) 
                        elseif fuel < 1 then 
                            exports.global:sendLocalMeAction(source, "cenšās piestartēt transportlīdzekļa dzinēju, bet tas atsakās strādāt.") 
                            outputChatBox("Transportlīdzeklim ir beigusies degviela.", source) 
                        end 
                    else 
                        outputChatBox("Jums ir nepieciešamas transportlīdzekļa atslēgas, lai piestartētu tā dzinēju.", source, 255, 0, 0) 
                    end 
                else 
                    toggleControl(source, 'brake_reverse', false) 
                    setVehicleEngineState(veh, false) 
                    exports['anticheat-system']:changeProtectedElementDataEx(veh, "engine", 0, false) 
                end 
            end 
        end 
    end 
end 
addCommandHandler("engine", toggleEngine) 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...