Advertisement
NanoBob

searchlight system V2

May 10th, 2016
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.31 KB | None | 0 0
  1. local positions = {
  2.     -- input your positions for all your lights here
  3.     -- {x,y,z,rotation}
  4. }
  5.  
  6. local lights = {}
  7.  
  8. function createLight(x,y,z,rotation)
  9.     local id = #lights+1
  10.     lights[id] = {
  11.         objects = {
  12.             createObject(2889, x, y, z, 0, 0, 129.40130615234),
  13.             createObject(2888, x, y, z, 340, 0, 129.40130615234),
  14.             bulb = createObject(2887, x, y, z, 340, 0, 129.40130615234),
  15.         }
  16.     }
  17.     return id
  18. end
  19.  
  20. function setLightActivated(id,state)
  21.     if state == true then
  22.         if lights[id].light ~= nil then return end
  23.         local posX, posY, posZ = getElementPosition(lights[id].objects.bulb)
  24.         local spotLightObjectMatrix = getElementMatrix(lights[id].objects.bulb)
  25.         local targetPos = Vector3(spotLightObjectMatrix[4][1] + spotLightObjectMatrix[2][1] * 50, spotLightObjectMatrix[4][2] + spotLightObjectMatrix[2][2] * 50, spotLightObjectMatrix[4][3] + spotLightObjectMatrix[2][3] * 50)          
  26.         lights[id].light = createSearchLight(posX, posY, posZ+0.85,targetPos, 0.5, 20)
  27.     else
  28.         if lights[id].light == nil then return end
  29.         destroyElement(lights[id].light)
  30.         lights[id].light = nil
  31.     end
  32. end
  33.  
  34. function setAllLightsActivated(state)
  35.     for id,_ in pairs(lights) do
  36.         setLightsActivated(id,state)
  37.     end
  38. end
  39.  
  40. function createAllLights()
  41.     for _,pos in ipairs(positions) do
  42.         createLight(pos.x,pos.y,pos.z,pos.rot or 0)
  43.     end
  44. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement