Advertisement
Filexdoj

client.lua

Jun 30th, 2020
1,113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.85 KB | None | 0 0
  1. local Light = {}
  2. local Checker = {}
  3. local Lights = {}
  4. local allowedVehiclesLightPositions = {
  5.     ["596"] = {
  6.         Vector3(0.3, -1.45, 0.60),
  7.         Vector3(0.2, -1.45, 0.60),
  8.         Vector3(0, -1.45, 0.60),
  9.         Vector3(-0.2, -1.45, 0.60),
  10.         Vector3(-0.3, -1.45, 0.60)
  11.     },
  12.     ["490"] = {
  13.         Vector3(0.4, -2.45, 0.85),
  14.         Vector3(0.3, -2.45, 0.85),
  15.         Vector3(0.2, -2.45, 0.85),
  16.         Vector3(0, -2.45, 0.85),
  17.         Vector3(-0.2, -2.45, 0.85),
  18.         Vector3(-0.3, -2.45, 0.85),
  19.         Vector3(-0.4, -2.45, 0.85)
  20.     }
  21. }
  22. local timeouts = {
  23.     -- in ms
  24.     lightEffect = 100,
  25.     lightMovement = 300
  26. }
  27.  
  28. function Checker.new(LightObject)
  29.     local self = {}
  30.     self.constantChecker =
  31.         Timer(
  32.         function()
  33.             if (not isElement(LightObject.vehicle)) then
  34.                 Light.destroy(LightObject)
  35.             end
  36.         end,
  37.         timeouts["constantCheck"],
  38.         0
  39.     )
  40.     self.lightEffectChecker =
  41.         Timer(
  42.         function()
  43.             Light.effect(LightObject)
  44.         end,
  45.         timeouts["lightEffect"],
  46.         0
  47.     )
  48.     self.lightMovementChecker =
  49.         Timer(
  50.         function()
  51.             Light.move(LightObject)
  52.         end,
  53.         timeouts["lightMovement"],
  54.         0
  55.     )
  56.     return self
  57. end
  58.  
  59. function Light.new(vehicle)
  60.     local self = {}
  61.     self.vehicle = vehicle
  62.     self.vehicleModel = tostring(vehicle:getModel())
  63.     self.light = Marker(Vector3(0, 0, 0), "corona", 0.3, 255, 140, 0, 250)
  64.     self.lightEffect = true
  65.     self.position = 1
  66.     self.checker = Checker.new(self)
  67.     return self
  68. end
  69.  
  70. function Light.effect(self)
  71.     if (isElement(self.vehicle) and isElement(self.light)) then
  72.         if (self.lightEffect) then
  73.             self.light:setAlpha(100)
  74.         else
  75.             self.light:setAlpha(250)
  76.         end
  77.         self.lightEffect = not self.lightEffect
  78.     else
  79.         return self.checker.lightEffectChecker:destroy()
  80.     end
  81. end
  82.  
  83. function Light.move(self)
  84.     if (isElement(self.vehicle) and isElement(self.light)) then
  85.         if (self.position == #allowedVehiclesLightPositions[self.vehicleModel]) then
  86.             self.position = 0
  87.         end
  88.         self.position = self.position + 1
  89.         self.light:attach(self.vehicle, allowedVehiclesLightPositions[self.vehicleModel][self.position])
  90.     else
  91.         return self.checker.lightMovementChecker:destroy()
  92.     end
  93. end
  94.  
  95. function Light.destroy(self)
  96.     self.light:destroy()
  97.     self.checker.constantChecker:destroy()
  98. end
  99.  
  100. function addLight()
  101.     local vehicle = source
  102.     local newLight = Light.new(vehicle)
  103.     Lights[vehicle] = newLight
  104. end
  105. addEvent("addLight", true)
  106. addEventHandler("addLight", getRootElement(), addLight)
  107.  
  108. function removeLight()
  109.     local vehicle = source
  110.     local myLight = Lights[vehicle]
  111.     Light.destroy(myLight)
  112.     Lights[vehicle] = nil
  113. end
  114. addEvent("removeLight", true)
  115. addEventHandler("removeLight", getRootElement(), removeLight)
  116.  
  117. function startAllCurrentLightsCreation()
  118.     triggerServerEvent("createAllLights", localPlayer)
  119. end
  120. addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), startAllCurrentLightsCreation)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement