So, i have a script for open-up headlights who worked on 1.5.6 version of MTA, but when i changed all my things to 1.5.8 it always returns 1 warning and 2 errors... (Images below, using debugscript 3);
? Fullscreen print: here!
? Debug focus: here!
? Follow bellow the full script:
? Download: here!
local LIGHTS_COMPONENT_NAME = "LightsOpen"
local LIGHTS_STATE_DATA = "LightsState"
-- Ângulo de giro dos faróis abertos / fechados
local ANGLE_OPENED = 60
local ANGLE_CLOSED = 0
local overrideAngleOpened = {
nissan_180sx = 40,
mazda_mx5miata = 55,
mazda_rx7_fc = 45,
nsx = 35,
}
-- Velocidade de abertura / fechamento do farol
local LIGHTS_ROTATION_SPEED = 45
-- Carros para serem animados
-- (animado, carros próximos ao jogador)
local animateVehicles = {
nissan_180sx,
mazda_mx5miata,
mazda_rx7_fc,
nsx
}
-- Atualiza o estado do componente do farol do veículo, inicia uma animação
local function updateVehicleLightsState(vehicle)
if not isElement(vehicle) then
return
end
local state = not not vehicle:getData(LIGHTS_STATE_DATA)
-- Ângulo dependendo do estado
local angle = ANGLE_CLOSED
if state then
angle = ANGLE_OPENED
local vehicleName = exports.dpShared:getVehicleNameFromModel(vehicle.model)
if vehicleName and overrideAngleOpened[vehicleName] then
angle = overrideAngleOpened[vehicleName]
end
end
local stateId = 1
if state then
stateId = 2
end
local components = vehicle:getComponents()
local hasComponent = components[LIGHTS_COMPONENT_NAME]
-- Se o carro estiver próximo, comece a animação do farol
if hasComponent and isElementStreamedIn(vehicle) then
-- Direção
local direction = 1
if not state then
direction = -1
end
-- Desligue as luzes antes que a animação comece
if stateId == 1 then
setVehicleOverrideLights(vehicle, stateId)
else
local rotation = vehicle:getComponentRotation(LIGHTS_COMPONENT_NAME)
if rotation > 300 then
vehicle:setComponentRotation(LIGHTS_COMPONENT_NAME, ANGLE_CLOSED, 0, 0)
end
end
animateVehicles[vehicle] = {targetAngle = angle, direction = direction, stateId = stateId}
else
if hasComponent then
-- Se o carro estiver longe, abra / feche imediatamente os faróis
vehicle:setComponentRotation(LIGHTS_COMPONENT_NAME, angle, 0, 0)
end
setVehicleOverrideLights(vehicle, stateId)
end
end
addEventHandler("onClientPreRender", root, function (deltaTime)
deltaTime = deltaTime / 1000
for vehicle, animation in pairs(animateVehicles) do
if not isElement(vehicle) then
animateVehicles[vehicle] = nil
else
local rotation = vehicle:getComponentRotation(LIGHTS_COMPONENT_NAME)
rotation = rotation + animation.direction * LIGHTS_ROTATION_SPEED * deltaTime
if animation.direction > 0 and rotation >= animation.targetAngle then
rotation = animation.targetAngle
animateVehicles[vehicle] = nil
setVehicleOverrideLights(vehicle, animation.stateId)
elseif animation.direction < 0 and rotation <= animation.targetAngle then
rotation = animation.targetAngle
animateVehicles[vehicle] = nil
setVehicleOverrideLights(vehicle, animation.stateId)
end
vehicle:setComponentRotation(LIGHTS_COMPONENT_NAME, rotation, 0, 0)
end
end
end)
addEventHandler("onClientElementDataChange", root, function (name, oldVaue)
if source.type ~= "vehicle" then
return
end
if name == LIGHTS_STATE_DATA then
updateVehicleLightsState(source)
end
end)
addEventHandler("onClientResourceStart", resourceRoot, function ()
for i, vehicle in ipairs(getElementsByType("vehicle")) do
updateVehicleLightsState(vehicle)
end
end)
addEventHandler("onClientElementStreamedIn", root, function ()
if source.type ~= "vehicle" then
return
end
updateVehicleLightsState(source)
end)