-- LUA Script - precede every function and global member with lowercase name of script + '_main' -- Player Collects Weapon local U = require "scriptbank\\utillib" local weapons = {} g_handIcon = g_handIcon or nil local names = {} local handSize = 15 local handOn = {} local swapWpn = nil local keyOrMousePressed = false local currentInventory = { Pistol = nil, Rifle = nil, Rpg = nil, Shotgun = nil } local wpnList = { [ 'Shotgun' ] = { gTyp = 'Shotgun', gName = 'modern\\shotgun' }, [ 'Colt 1911' ] = { gTyp = 'Pistol', gName = 'modern\\colt1911' }, [ 'Magnum 357' ] = { gTyp = 'Pistol', gName = 'modern\\magnum357' }, [ 'Uzi' ] = { gTyp = 'Rifle', gName = 'modern\\uzi' }, [ 'Sniper M700' ] = { gTyp = 'Rifle', gName = 'modern\\sniperm700' }, [ 'Rpg' ] = { gTyp = 'Rpg', gName = 'modern\\rpg' }, [ 'Futuretek Shotgun' ] = { gTyp = 'Shotgun', gName = 'futuristic\\futuretekshotgun' } } function limited_weapons_init_name( e, name ) weapons[ e ] = { name = name, inUse = false, timer = math.huge } end local function playerCanSee( e ) local Ent = g_Entity[ e ] local pxp, pyp, pyz = g_PlayerPosX, g_PlayerPosY, g_PlayerPosZ if GetGamePlayerStatePlayerDucking() == 0 then pyp = pyp + 31 else pyp = pyp + 10 end return IntersectAll( Ent.x, Ent.y + 1, Ent.z, pxp, pyp, pzp, Ent.obj ) == 0 end g_disableWeapon = g_disableWeapon or nil function PU_GetEntityCarried() return g_disableWeapon end local function sameType( typ ) for _, v in pairs( wpnList ) do if v.gTyp == typ and v.gName == g_PlayerGunName then return true end end return false end function limited_weapons_main(e) local wpn = weapons[ e ] if wpn == nil or wpn.inUse then return end 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 U.PlayerLookingNear( e, 100, 20 ) and playerCanSee( e ) then if not handOn[ e ] then SetSpritePosition( g_handIcon, 50, 50 ) handOn[ e ] = true g_disableWeapon = true return end PromptLocal( e, wpn.name ) local thisWeapon = wpnList[ wpn.name ] if thisWeapon == nil then return end Prompt( ( thisWeapon.gTyp or 'nil' ) .. "," .. g_PlayerGunName ) if currentInventory[ thisWeapon.gTyp ] == nil then if ( g_MouseClick == 1 or g_KeyPressE == 1 ) and not keyOrMousePressed then currentInventory[ thisWeapon.gTyp ] = e keyOrMousePressed = true PlaySound( e, 0 ) AddPlayerWeapon( e ) ActivateIfUsed(e) Hide( e ) CollisionOff( e ) wpn.timer = g_Time + 200 end elseif ( g_MouseClick == 2 or string.lower( GetInKey() ) == 't' ) and not keyOrMousePressed and sameType( thisWeapon.gTyp ) then local Ent = g_Entity[ e ] swapWpn = { name = g_PlayerGunName, x = Ent.x, y = Ent.y, z = Ent.z, xa = Ent.anglex, ya = Ent.angley, za = Ent.anglez } keyOrMousePressed = true PlaySound( e, 0 ) ReplacePlayerWeapon( e ) Hide( e ) CollisionOff( e ) wpn.timer = g_Time + 200 end elseif handOn[ e ] then SetSpritePosition( g_handIcon, 250, 250 ) handOn[ e ] = false g_disableWeapon = nil end if g_Time > wpn.timer then SetSpritePosition( g_handIcon, 250, 250 ) handOn[ e ] = false keyOrMousePressed = false g_disableWeapon = nil wpn.inUse = true wpn.timer = math.huge if swapWpn ~= nil then for k, v in pairs( weapons ) do if v.name == swapWpn.name then ResetPosition( k, swapWpn.x, swapWpn.y, swapWpn.z ) ResetRotation( k, swapWpn.xa, swapWpn.ya, swapWpn.za ) Show( k ) CollisionOn( k ) weapons[ k ].inUse = false break end end swapWpn = nil end end end