local U = require( "scriptbank\\utillib" ) local Q = require "scriptbank\\quatlib" local rad = math.rad local deg = math.deg local guns = {} local Ekey = false function static_gun_init_name( e, name ) Include( "utillib.lua" ) Include( "quatlib.lua" ) end local function wrapAng( ang ) -- Euler while ang > 180 do ang = ang - 180 end while ang < 180 do ang = ang + 180 end return ang end local usingEnt = nil function PU_GetEntityCarried() return usingEnt end function static_gun_main(e) local tg = guns[ e ] if tg == nil then local Ent = g_Entity[ e ] guns[ e ] = { obj = Ent.obj, state = 'idle' } return end if tg.state == 'idle' then if U.PlayerCloserThan( e, 80 ) then Prompt("E to use gun" ) if g_KeyPressE == 1 then if not Ekey then Ekey = true tg.state = 'init' local x, y, z, xa, ya, za = GetObjectPosAng( tg.obj ) tg.x, tg.y, tg.z = x, y, z tg.quat = Q.FromEuler( rad( xa ), rad( ya ), rad( za ) ) end else Ekey = false end end elseif tg.state == 'init' then local xr, yr, zr = Q.ToEuler( tg.quat ) local xo, yo, zo = U.Rotate3D( 0, -5, -15, xr, yr, zr ) tg.px, tg.py, tg.pz = g_PlayerPosX, g_PlayerPosY, g_PlayerPosZ SetFreezePosition( tg.x + xo, tg.y + yo, tg.z + zo ) SetFreezeAngle( deg( xr ), deg( yr ), deg( zr ) ) TransportToFreezePosition() usingEnt = e Hide( e ) CollisionOff( e ) if tg.ammo == nil then tg.ammo = 1000 end AddPlayerWeapon( e ) for index = 1, 10 do if GetPlayerWeaponID() == GetWeaponSlot( index ) then SetWeaponAmmo( index, tg.ammo ) break end end tg.state = 'used' elseif tg.state == 'used' then if g_KeyPressE == 1 then if not Ekey then Ekey = true tg.state = 'idle' RemovePlayerWeapons( e ) SetFreezePosition( tg.px, tg.py, tg.pz ) TransportToFreezePositionOnly() usingEnt = nil Show( e ) CollisionOn( e ) return end else Ekey = false end local pax, pay, paz = rad( wrapAng( g_PlayerAngX ) ), rad( wrapAng( g_PlayerAngY ) ), rad( wrapAng( g_PlayerAngZ ) ) local xo, yo, zo = U.Rotate3D( 0, -5, -15, pax, pay, 0 ) for index = 1, 10 do if GetPlayerWeaponID() == GetWeaponSlot( index ) then tg.ammo = GetWeaponAmmo( index ) break end end SetFreezePosition( tg.x + xo, tg.y + yo, tg.z + zo ) TransportToFreezePositionOnly() if g_MouseClick == 1 then SetGamePlayerStateFiringMode(1) else SetGamePlayerStateFiringMode(0) end end end