local U = require "scriptbank\\utillib" local Q = require "scriptbank\\quatlib" local rad = math.rad local deg = math.deg local floor = math.floor local atan = math.atan2 local abs = math.abs local sqrt = math.sqrt local rotx = {} local rotz = {} local maxX = {} local minX = {} local maxZ = {} local minZ = {} local swingingX = {} local swingingZ = {} local light = {} lightName = {} local facingNorth = {} local facingEast = {} local facingUp = {} function swinging_light_init_name(e,name) --[[ set to 1 if you want the light facing that direction, set to -1 if facing opposite, set to 0 if not facing either i.e. if facing north (GG default direction) set as; facingNorth[e] = 1 facingEast[e] = 0 facingUp[e] = 0 but if you want the light to face towards the ground set as; facingNorth[e] = 0 facingEast[e] = 0 facingUp[e] = -1 --]] facingNorth[e] = 0 facingEast[e] = 0 facingUp[e] = -1 rotx[e] = 1 rotz[e] = 0 minX[e] = -25 maxX[e] = 25 --[[ set swinging x / z to 1 or -1 to make the light swing in that direction (depends on GG's default rotation facing) so a light facing north by default that you want to swing back and forth should be set as; swingingX[e] = -/+ 1 --]] swingingX[e] = math.random(0,1) if swingingX[e] == 0 then swingingX[e] = -1 end CollisionOff(e) lightName[e] = name light[e] = nil end function swinging_light_main(e) if light[e] == nil then for a,_ in pairs (isLight) do if lightName[e].."_light" == lightName[a] then light[e] = GetEntityLightNumber( a ) break end end if light[e] == nil then PromptLocal(e,"no light found") return end end local tempx = g_Entity[e]['anglex'] local tempz = g_Entity[e]['anglez'] local tempy = g_Entity[e]['angley'] if rotx[e] > 0 then tempx = tempx+swingingX[e] if tempx < minX[e] or tempx > maxX[e] then swingingX[e] = swingingX[e]*-1 end end if rotz[e] > 0 then tempz = tempz+swingingZ[e] if tempz < minZ[e] or tempz > maxZ[e] then swingingZ[e] = swingingZ[e]*-1 end end SetRotation(e,tempx,tempy,tempz) local rad = math.rad local xv, yv, zv = U.Rotate3D( facingEast[e], facingUp[e], facingNorth[e], rad( tempx ), rad( tempy ), rad( tempz ) ) SetLightAngle( light[e], xv, yv, zv ) --Prompt(GetLightAngle(light[e])) end