Advertisement
NanoBob

searchlight system

May 10th, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.97 KB | None | 0 0
  1. local lights = {}
  2.  
  3. function createLight(x,y,z)
  4.     local id = #lights+1
  5.     lights[id] = {
  6.         objects = {
  7.             createObject(2889, x, y, z, 0, 0, 129.40130615234),
  8.             createObject(2888, x, y, z, 340, 0, 129.40130615234),
  9.             bulb = createObject(2887, x, y, z, 340, 0, 129.40130615234),
  10.         }
  11.     }
  12.     return id
  13. end
  14.  
  15. function setLightActivated(id,state)
  16.     if state == true then
  17.         if lights[id].light ~= nil then return end
  18.         local posX, posY, posZ = getElementPosition(lights[id].objects.bulb)
  19.         local spotLightObjectMatrix = getElementMatrix(lights[id].objects.bulb)
  20.         local targetPos = Vector3(spotLightObjectMatrix[4][1] + spotLightObjectMatrix[2][1] * 50, spotLightObjectMatrix[4][2] + spotLightObjectMatrix[2][2] * 50, spotLightObjectMatrix[4][3] + spotLightObjectMatrix[2][3] * 50)          
  21.         lights[id].light = createSearchLight(posX, posY, posZ+0.85,targetPos, 0.5, 20)
  22.     else
  23.         if lights[id].light == nil then return end
  24.         destroyElement(lights[id].light)
  25.         lights[id].light = nil
  26.     end
  27. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement