-- LUA Script - precede every function and global member with lowercase name of script + '_main' -- Player Collects Weapon weapon_therecanbeonlyone = 0 local gunstate = {} local gunName = {} local gunSpareAmmo = {} local gunClipAmmo = {} local last_weapon = "" pressedT = 0 function weapon_init_name(e,name) weapon_name[e] = name gunstate[e] = "wait pick up" end function weapon_main(e) if gunstate[e] == "carrying" then SetPosition(e,g_PlayerPosX,g_PlayerPosY+200,g_PlayerPosZ) ResetPosition(e,g_PlayerPosX,g_PlayerPosY+200,g_PlayerPosZ) elseif gunstate[e] == "wait pick up" then if weapon_therecanbeonlyone==-1 then if g_KeyPressE == 0 and g_InKey == "" then weapon_therecanbeonlyone = 0 end end PlayerDist = GetPlayerDistance(e) if PlayerDist < 150 and g_PlayerHealth > 0 and g_PlayerThirdPerson==0 then SourceAngle = g_PlayerAngY while SourceAngle < 0.0 do SourceAngle = SourceAngle + 360.0 end while SourceAngle > 340.0 do SourceAngle = SourceAngle - 360.0 end PlayerDX = (g_Entity[e]['x'] - g_PlayerPosX) PlayerDZ = (g_Entity[e]['z'] - g_PlayerPosZ) DestAngle = math.atan2( PlayerDZ , PlayerDX ) -- Convert to degrees DestAngle = (DestAngle * 57.2957795) - 90.0 Result = math.abs(math.abs(SourceAngle)-math.abs(DestAngle)) if Result > 180 then Result = 0 end if Result < 20.0 and weapon_therecanbeonlyone==0 then weapon_therecanbeonlyone = e end if Result >= 20.0 and weapon_therecanbeonlyone==e then weapon_therecanbeonlyone = 0 end if Result < 20.0 and weapon_therecanbeonlyone==e then if g_PlayerGunCount < 9 then if g_PlayerGunID > 0 then if g_PlayerController==0 then Prompt("Press E to pick up the " .. weapon_name[e] .. " or T to replace" ) else Prompt("Press Y Button to pick up the " .. weapon_name[e] ) end else if g_PlayerController==0 then Prompt("Press E To pick up the " .. weapon_name[e] ) else Prompt("Press Y Button to pick up the " .. weapon_name[e] ) end end if g_KeyPressE == 1 then Prompt("Collected the " .. weapon_name[e]) PlaySound(e,0) last_weapon = g_PlayerGunName gunstate[e] = "picking up" Hide(e) AddPlayerWeapon(e) --Destroy(e) ActivateIfUsed(e) weapon_therecanbeonlyone = -1 end else if g_PlayerController==0 then if g_PlayerGunID > 0 then Prompt("Press T to replace with " .. weapon_name[e] ) else Prompt("Cannot collect any more weapons" ) end else Prompt("Cannot collect any more weapons" ) end end if g_Scancode == 20 and g_PlayerGunID > 0 and pressedT == 0 then pressedT = 1 local thisX,thisY,thisZ,thisAX,thisAY,thisAZ = GetEntityPosAng(e) for a,b in pairs (gunName) do if g_PlayerGunName == b then SetPosition(a,thisX,thisY,thisZ) ResetPosition(a,thisX,thisY,thisZ) SetRotation(a,thisAX,thisAY,thisAZ) ResetRotation(a,thisAX,thisAY,thisAZ) Show(a) gunstate[a] = "wait pick up" break end end --Prompt("Replaced with " .. weapon_name[e]) PlaySound(e,0) last_weapon = g_PlayerGunName gunstate[e] = "picking up" Hide(e) ReplacePlayerWeapon(e) --Destroy(e) ActivateIfUsed(e) weapon_therecanbeonlyone = -1 end end else if weapon_therecanbeonlyone==e then weapon_therecanbeonlyone = 0 end end elseif gunstate[e] == "picking up" then if g_PlayerGunName ~= last_weapon then last_weapon = g_PlayerGunName gunName[e] = g_PlayerGunName gunstate[e] = "carrying" if gunClipAmmo[e] ~= nil then for a = 1, 10 do if GetPlayerWeaponID ( ) == GetWeaponSlot ( a ) then --SetWeaponClipAmmo ( a, gunClipAmmo[e] ) SetWeaponPoolAmmo ( a, gunSpareAmmo[e] ) --UpdateWeaponStatsItem(5,a,gunSpareAmmo[e]) SetWeaponAmmo ( a, gunClipAmmo[e]) break end end end end end if g_PlayerGunName == gunName[e] then for a = 1, 10 do if GetPlayerWeaponID ( ) == GetWeaponSlot ( a ) then gunClipAmmo[e] = GetWeaponAmmo(a) gunSpareAmmo[e] = g_PlayerGunClipCount break end end end if g_Scancode ~= 20 then pressedT = 0 end if gunClipAmmo[e] ~= nil and gunSpareAmmo[e] ~= nil then PromptLocal(e,gunClipAmmo[e].." / "..gunSpareAmmo[e]) end end