Hi everyone,
I am trying to create a function that stops and starts an engine on demand, but somehow, I’m calling a function with a “nil” argument.
AddEventHandler("turnengine", function()
Citizen.CreateThread(function()
while true do
local Ped = GetPlayerPed(-1)
local lastCar = GetVehiclePedIsUsing(Ped)
-- if (not car and lastCar == nil) then
-- TriggerEvent("chatMessage", "ERROR", {255, 0, 0}, "You have to sit in a vehicle to set it as yours.")
-- if (car) then
-- lastCar = car
-- end
local engineStatus = GetIsVehicleEngineRunning(lastCar) -- the error occurs here
--rest of the program below
Any help would be appreciated !
Quentin
Can you send me whole script, so i can help you?
is the script client sided? If its server sided Citizen.CreateThread
won’t work
The script is server sided. What would work then ?
Thanks !
Why would you need CreateThread anyways?
just remove it and it should work fine
It doesn’t, I still have an error
Not the same though
Hi,
Here’s the complete client.lua
RegisterNetEvent("turnengine")
AddEventHandler('turnengine', function()
local car = GetVehiclePedIsIn(GetPlayerPed(-1), false)
engineStatus = GetIsVehicleEngineRunning(car)
if engineStatus == 0 then
SetVehicleUndriveable(car, false)
SetVehicleEngineOn(car, true, false, true)
TriggerEvent("chatMessage", "INFO", {255, 255, 0}, "Engine is now on.")
elseif engineStatus == 1 then
SetVehicleEngineOn(car, false, false, true)
TriggerEvent("chatMessage", "INFO", {255, 255, 0}, "Engine is now off.")
SetVehicleUndriveable(car, true)
end
end)
I still have an error using GetIsVehicleEngineRunning.
Here’s the server.lua :
RegisterServerEvent("chatCommandEntered")
AddEventHandler('chatCommandEntered', function(p, color, msg)
if msg:sub(1, 1) == "/" then
fullcmd = stringSplit(msg, " ")
cmd = fullcmd[1]
if cmd == "/engine" then
TriggerClientEvent("turnengine", p)
CancelEvent()
end
end
end)
function stringSplit(self, delimiter)
local a = self:Split(delimiter)
local t = {}
for i = 0, #a - 1 do
table.insert(t, a[i])
end
return t
end
Thanks for your help