-- LUA Script - precede every function and global member with lowercase name of script + '_main' local U = require "scriptbank\\utillib" local lights = {} local bulbs = {} local minAnim, maxAnim = 0, 124 local sweep = 70 function searchlight_init_name( e, name ) if name == 'Light' then lights[ e ] = { used = false } else bulbs[ e ] = { gotLight = false } end end function searchlight_main(e) local bulb = bulbs[ e ] if bulb == nil then return end if bulb.delay == nil then bulb.delay = g_Time + math.random( 1000, 5000 ) return end if g_Time > bulb.delay then SetAnimationFrames( minAnim, maxAnim ) LoopAnimation( e ) bulb.delay = math.huge return end if bulb.gotlight then -- first work out angle of spotlight base, only do this once if bulb.baseY == nil then bulb.baseY = math.rad( g_Entity[ e ].angley ) end -- get current animation frame local anim = GetAnimationFrame( e ) local lightAngle = bulb.baseY if anim > maxAnim / 2 then anim = maxAnim - anim end local angle = bulb.baseY - anim * (math.rad( sweep / ( maxAnim / 2 ) ) ) --PromptLocal( e, math.deg( angle ) ) local xv, yv, zv = U.Rotate3D( 0, 0, -1, math.rad( -20 ), angle, 0 ) SetLightAngle( bulb.light, xv, yv, zv ) else -- try and find an unused light local E1 = g_Entity[ e ] for k, v in pairs( lights ) do local E2 = g_Entity[ k ] if not v.used then if U.CloserThan( E1.x, E1.y, E1.z, E2.x, E2.y, E2.z, 10 ) then bulb.gotlight = true bulb.light = GetEntityLightNumber( k ) lights[ k ].used = true return end end end -- couldn't find a light so wipe ourselves out bulb = nil end end