Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Light = {}
- local Checker = {}
- local Lights = {}
- local allowedVehiclesLightPositions = {
- ["596"] = {
- Vector3(0.3, -1.45, 0.60),
- Vector3(0.2, -1.45, 0.60),
- Vector3(0, -1.45, 0.60),
- Vector3(-0.2, -1.45, 0.60),
- Vector3(-0.3, -1.45, 0.60)
- },
- ["490"] = {
- Vector3(0.4, -2.45, 0.85),
- Vector3(0.3, -2.45, 0.85),
- Vector3(0.2, -2.45, 0.85),
- Vector3(0, -2.45, 0.85),
- Vector3(-0.2, -2.45, 0.85),
- Vector3(-0.3, -2.45, 0.85),
- Vector3(-0.4, -2.45, 0.85)
- }
- }
- local timeouts = {
- -- in ms
- lightEffect = 100,
- lightMovement = 300
- }
- function Checker.new(LightObject)
- local self = {}
- self.constantChecker =
- Timer(
- function()
- if (not isElement(LightObject.vehicle)) then
- Light.destroy(LightObject)
- end
- end,
- timeouts["constantCheck"],
- 0
- )
- self.lightEffectChecker =
- Timer(
- function()
- Light.effect(LightObject)
- end,
- timeouts["lightEffect"],
- 0
- )
- self.lightMovementChecker =
- Timer(
- function()
- Light.move(LightObject)
- end,
- timeouts["lightMovement"],
- 0
- )
- return self
- end
- function Light.new(vehicle)
- local self = {}
- self.vehicle = vehicle
- self.vehicleModel = tostring(vehicle:getModel())
- self.light = Marker(Vector3(0, 0, 0), "corona", 0.3, 255, 140, 0, 250)
- self.lightEffect = true
- self.position = 1
- self.checker = Checker.new(self)
- return self
- end
- function Light.effect(self)
- if (isElement(self.vehicle) and isElement(self.light)) then
- if (self.lightEffect) then
- self.light:setAlpha(100)
- else
- self.light:setAlpha(250)
- end
- self.lightEffect = not self.lightEffect
- else
- return self.checker.lightEffectChecker:destroy()
- end
- end
- function Light.move(self)
- if (isElement(self.vehicle) and isElement(self.light)) then
- if (self.position == #allowedVehiclesLightPositions[self.vehicleModel]) then
- self.position = 0
- end
- self.position = self.position + 1
- self.light:attach(self.vehicle, allowedVehiclesLightPositions[self.vehicleModel][self.position])
- else
- return self.checker.lightMovementChecker:destroy()
- end
- end
- function Light.destroy(self)
- self.light:destroy()
- self.checker.constantChecker:destroy()
- end
- function addLight()
- local vehicle = source
- local newLight = Light.new(vehicle)
- Lights[vehicle] = newLight
- end
- addEvent("addLight", true)
- addEventHandler("addLight", getRootElement(), addLight)
- function removeLight()
- local vehicle = source
- local myLight = Lights[vehicle]
- Light.destroy(myLight)
- Lights[vehicle] = nil
- end
- addEvent("removeLight", true)
- addEventHandler("removeLight", getRootElement(), removeLight)
- function startAllCurrentLightsCreation()
- triggerServerEvent("createAllLights", localPlayer)
- end
- addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), startAllCurrentLightsCreation)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement