-- LUA Script - precede every function and global member with lowercase name of script + '_main' local U = require "scriptbank\\utillib" local rad = math.rad local deg = math.deg g_handIcon = g_handIcon or nil g_handOn = g_handOn or {} local lamp_collected = nil local lamp_light = nil function lamp_init( e ) lamp_collected = nil end local handSize = 15 local handOn = g_handOn local collectTimer = {} g_disableWeapon = g_disableWeapon or nil function PU_GetEntityCarried() return g_disableWeapon end function LampAddLight( lightId ) lamp_light = lightId end local keyOrMousePressed = {} local lpX, lpY, lpZ = 0, 0, 0 local lampState = 'idle' local FlashOn = true function lamp_main( e ) if g_handIcon == nil then g_handIcon = CreateSprite( LoadImage( "scriptbank\\pickuppable\\hand1.png" ) ) SetSpriteOffset ( g_handIcon, -1 , handSize / 2 ) SetSpriteSize ( g_handIcon, -1 , handSize ) SetSpriteDepth ( g_handIcon, 0 ) SetSpritePosition( g_handIcon, 250, 250 ) handOn[ e ] = false end if lamp_collected == nil then if U.PlayerLookingNear( e, 100, 20 ) then if not handOn[ e ] then SetSpritePosition( g_handIcon, 50, 50 ) handOn[ e ] = true g_disableWeapon = true return end if ( g_MouseClick == 1 or g_KeyPressE == 1 ) and not keyOrMousePressed[ e ] then keyOrMousePressed[ e ] = true PlaySound( e, 0 ) Hide( e ) lamp_collected = e if GetGamePlayerStateFlashlightControl() == 0 then SetGamePlayerStateFlashlightControl( 0.2 ) end CollisionOff( e ) collectTimer[ e ] = g_Time + 200 end elseif handOn[ e ] then handOn[ e ] = false SetSpritePosition( g_handIcon, 250, 250 ) for _, v in pairs( handOn ) do if v then return end end g_disableWeapon = nil end elseif lamp_collected == e then if FlashOn then -- if lamp selected then position entity relative to player and show it local pX, pY, pZ = g_PlayerPosX, g_PlayerPosY + 31, g_PlayerPosZ if GetGamePlayerStatePlayerDucking() == 1 then pY = pY - 10 end local aX, aY, aZ = rad( g_PlayerAngX ), rad( g_PlayerAngY ), rad( g_PlayerAngZ ) local XO, YO, ZO = U.Rotate3D ( 15, -5, 20, aX, aY, aZ ) local lx, ly, lz = pX + XO, pY + YO, pZ + ZO lpX = ( lpX + lx ) / 2 lpY = ( lpY + ly ) / 2 lpZ = ( lpZ + lz ) / 2 CollisionOff( e ) ResetPosition( e, lpX, lpY, lpZ ) ResetRotation( e, 0, deg( aY), 0 ) Show( e ) -- CollisionOn( e ) -- wobble lamp when walking -- if dynamic light associated with lamp position it if lamp_light ~= nil then SetLightRange( lamp_light, 400 ) SetLightPosition( lamp_light, lpX, lpY, lpZ ) local xv, yv, zv = U.Rotate3D( 0, 0, 1, 0, aY, 0 ) SetLightAngle( lamp_light, xv, yv, zv ) end if GetGamePlayerStateFlashlightControl() == 1 then SetGamePlayerStateFlashlightControl( 0.2 ) end -- handle flicker of lighting else if lamp_light ~= nil then SetLightRange( lamp_light, 0 ) end CollisionOff( e ) Hide( e ) end -- Prompt( "Lamp : " .. g_PlayerFlashlight ) elseif lamp_light ~= nil then SetLightRange( lamp_light, 0 ) end if collectTimer[ e ] ~= nil and g_Time > collectTimer[ e ] then handOn[ e ] = false keyOrMousePressed[ e ] = false for _, v in pairs( handOn ) do if v then return end end SetSpritePosition( g_handIcon, 250, 250 ) g_disableWeapon = nil collectTimer[ e ] = nil end end