Fixed unequipp bug & other improvements

master
AlmTech Software 5 years ago
parent 4d06c66bbe
commit 04ad7282f3
  1. 67
      entities/weapons/quantum_hands/shared.lua
  2. 17
      gamemode/engine/core/client/cl_hud.lua
  3. 3
      gamemode/engine/core/server/sv_player_init.lua
  4. 2
      gamemode/engine/derma/menus/menu_charinfo.lua
  5. 78
      gamemode/engine/lib/server/sv_inventory.lua
  6. 3
      gamemode/engine/vars/sh_vars.lua
  7. 34
      plugins/plugin_addweaponsasitems.lua

@ -0,0 +1,67 @@
-- __ _ _______ _ __
-- / / /\ | | |__ __| | | \ \
-- / / / \ | |_ __ ___ | | ___ ___| |__ \ \
-- < < / /\ \ | | '_ ` _ \| |/ _ \/ __| '_ \ > >
-- \ \ / ____ \| | | | | | | | __/ (__| | | | / /
-- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/
AddCSLuaFile()
if CLIENT then
SWEP.PrintName = "Hands"
SWEP.Slot = 0
SWEP.SlotPos = 0
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = false
end
SWEP.WorldModel = ""
SWEP.UseHands = true
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = 0
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = ""
SWEP.Primary.Delay = 0.25
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = 0
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = ""
SWEP.Secondary.Delay = 0.25
function SWEP:Initialize()
if CLIENT || !IsValid(self:GetOwner()) then return true end
self:SetHoldType( "normal" )
end
function SWEP:Deploy()
--self:GetOwner():DrawWorldModel( false )
return true
end
function SWEP:Holster()
return true
end
function SWEP:PreDrawViewModel()
return true
end
function SWEP:PrimaryAttack()
if SERVER then
local ent = self:GetOwner():GetEyeTraceNoCursor().Entity
if( IsValid( ent ) && ent:GetPos():Distance( self:GetOwner():GetPos() ) < 100 ) then
if ( ent:IsPlayerHolding() ) then return end
self:GetOwner():PickupObject( ent )
end
end
return false
end
function SWEP:SecondaryAttack()
return false
end
function SWEP:Reload()
return false
end

@ -7,7 +7,8 @@
local enabledHUDs = { local enabledHUDs = {
["CHudChat"] = true, ["CHudChat"] = true,
["CHudGMod"] = true ["CHudGMod"] = true,
["CHudWeaponSelection"] = true
} }
hook.Add( "HUDShouldDraw", "Quantum_RemoveDefualtHUD", function( hudid ) hook.Add( "HUDShouldDraw", "Quantum_RemoveDefualtHUD", function( hudid )
@ -46,10 +47,10 @@ local function renderStatHUD()
surface.DrawText( hptxt ) surface.DrawText( hptxt )
-- Crosshair -- Crosshair
if( Quantum.Client.ShowCrosshair ) then -- if( Quantum.Client.ShowCrosshair ) then
surface.SetDrawColor( 255, 255, 255, 200 ) -- surface.SetDrawColor( 255, 255, 255, 200 )
surface.DrawRect( sw/2 - radius, sh/2 - radius, radius*2, radius*2 ) -- surface.DrawRect( sw/2 - radius, sh/2 - radius, radius*2, radius*2 )
end -- end
end end
local function renderItemInfoHUD() local function renderItemInfoHUD()
@ -78,7 +79,7 @@ local function renderItemInfoHUD()
draw.SimpleText( itemAmountTxt .. item.name, "q_item_hud_title", screenPos.x, screenPos.y, SetAlpha( item.rarity.color, 255 * alphaFrac ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) draw.SimpleText( itemAmountTxt .. item.name, "q_item_hud_title", screenPos.x, screenPos.y, SetAlpha( item.rarity.color, 255 * alphaFrac ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
draw.SimpleText( "Rarity: " .. item.rarity.txt, "q_item_hud_rarity", screenPos.x, screenPos.y + txtPadding, SetAlpha( item.rarity.color, 255 *alphaFrac ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) draw.SimpleText( item.rarity.txt, "q_item_hud_rarity", screenPos.x, screenPos.y + txtPadding, SetAlpha( item.rarity.color, 255 *alphaFrac ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
if( item.soulbound ) then if( item.soulbound ) then
draw.SimpleText( "Soulbound", "q_item_hud_soulbound", screenPos.x, screenPos.y + txtPadding*2, Color( 235, 64, 52, 255 * alphaFrac ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER ) draw.SimpleText( "Soulbound", "q_item_hud_soulbound", screenPos.x, screenPos.y + txtPadding*2, Color( 235, 64, 52, 255 * alphaFrac ), TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER )
end end
@ -96,7 +97,7 @@ local function renderCharNamesHUD3D2D()
local distance = LocalPlayer():GetPos():Distance( ent:GetPos() ) local distance = LocalPlayer():GetPos():Distance( ent:GetPos() )
local distFrac = Lerp( distance/Quantum.CharInfoDisplayDistance, 1, 0 ) local distFrac = Lerp( distance/Quantum.CharInfoDisplayDistance, 1, 0 )
if( distance <= Quantum.CharInfoDisplayDistance ) then if( distance <= Quantum.CharInfoDisplayDistance && ent:Alive() ) then
local name = ent:GetNWString( "q_char_name" ) local name = ent:GetNWString( "q_char_name" )
local pos = ent:GetPos() local pos = ent:GetPos()
pos.z = pos.z + 75 pos.z = pos.z + 75
@ -234,7 +235,7 @@ function GM:Think()
end end
hook.Add( "RenderScreenspaceEffects", "Quantum_HUD_RenderLowHealth", function() hook.Add( "RenderScreenspaceEffects", "Quantum_HUD_RenderLowHealth", function()
if( !Quantum.Client.IsInMenu ) then if( !Quantum.Client.IsInMenu || Quantum.Client.IsInInventory ) then
if( LocalPlayer():Health() / LocalPlayer():GetMaxHealth() <= 0.25 ) then if( LocalPlayer():Health() / LocalPlayer():GetMaxHealth() <= 0.25 ) then
DrawMotionBlur( 0.4, 0.8, 0.1 ) DrawMotionBlur( 0.4, 0.8, 0.1 )
DrawColorModify( { DrawColorModify( {

@ -37,6 +37,9 @@ local function setUpPlayer( ply )
ply:SetCrouchedWalkSpeed( Quantum.Server.Settings.PlayerSpeeds.duck) ply:SetCrouchedWalkSpeed( Quantum.Server.Settings.PlayerSpeeds.duck)
ply:SetMaxSpeed( Quantum.Server.Settings.PlayerSpeeds.run ) ply:SetMaxSpeed( Quantum.Server.Settings.PlayerSpeeds.run )
ply:Give( "quantum_hands" )
ply:SetActiveWeapon( "quantum_hands" )
Quantum.Debug( tostring( ply ) .. charnametxt ) Quantum.Debug( tostring( ply ) .. charnametxt )
end end

@ -160,6 +160,7 @@ function menu.open( dt )
if( !f ) then if( !f ) then
Quantum.Client.IsInMenu = true Quantum.Client.IsInMenu = true
Quantum.Client.IsInInventory = true
local f = vgui.Create( "DFrame" ) local f = vgui.Create( "DFrame" )
f:SetSize( sw, sh ) f:SetSize( sw, sh )
@ -175,6 +176,7 @@ function menu.open( dt )
end end
function f:OnClose() function f:OnClose()
Quantum.Client.IsInMenu = false -- show the hud when closed Quantum.Client.IsInMenu = false -- show the hud when closed
Quantum.Client.IsInInventory = false
Quantum.Client.Cam.Stop() Quantum.Client.Cam.Stop()
end end

@ -25,41 +25,36 @@ local function isStackable( item )
return item.stack || false return item.stack || false
end end
function Quantum.Server.Inventory.EquipItem( pl, itemindex ) local function setupWeaponItem( pl, itemTbl, dontSelect )
local char = Quantum.Server.Char.GetCurrentCharacter( pl ) if( itemTbl.equipgive != nil ) then
local slotitem = Quantum.Server.Inventory.GetSlotItem( char, itemindex ) pl:Give( itemTbl.equipgive, false )
local itemTbl = Quantum.Item.Get( slotitem[1] ) if( !dontSelect ) then pl:SelectWeapon( itemTbl.equipgive ) end
end
if( itemTbl != nil ) then end
local equipslot = itemTbl.equipslot
if( equipslot == nil ) then
Quantum.Error( tostring(pl) .. " tried to equip an non-equippable item: (" .. tostring(itemTbl[1]) .. ")" )
return
else
local equipslotKey = table.KeyFromValue( Quantum.EquipSlots, equipslot )
if( equipslotKey != nil ) then
char.equipped[equipslot] = itemindex -- set it in the table local function setupEquipedItem( pl, itemTbl )
if( itemTbl.equipeffect != nil ) then if( itemTbl.equipeffect != nil ) then
Quantum.Effect.Give( pl, itemTbl.equipeffect ) -- give the player the effect Quantum.Effect.Give( pl, itemTbl.equipeffect ) -- give the player the effect
end end
if( itemTbl.equipgive != nil ) then setupWeaponItem( pl, itemTbl )
pl:Give( itemTbl.equipgive ) end
pl:SelectWeapon( itemTbl.equipgive )
end
Quantum.Debug( tostring(pl) .. " equipped item (" .. tostring(slotitem[1]) .. ") - (" .. tostring(itemindex) .. ")" )
-- NETWORKING --
Quantum.Net.Inventory.SetEquipItem( pl, itemindex, equipslot )
else local function setupWeaponOnRespawn( pl, char )
Quantum.Error( tostring(pl) .. " tried to equip an item in a non-existent equip slot: (" .. tostring(equipslot) .. ")" ) char = char || Quantum.Server.Char.GetCurrentCharacter( pl )
return local slotItem = Quantum.Server.Inventory.GetSlotItem( char, char.equipped[Quantum.EquipSlots.Weapon] )
end if( slotItem != nil ) then
local itemTbl = Quantum.Item.Get( slotItem[1] )
if( itemTbl != nil ) then
setupEquipedItem( pl, itemTbl, true )
end end
end end
end end
hook.Add( "PlayerSpawn", "Quantum_Inventory_Equip_GiveWeapon", function( ply )
setupWeaponOnRespawn( ply )
ply:SelectWeapon( "quantum_hands" )
end)
function Quantum.Server.Inventory.UnEquipItem( pl, equipslot, char ) function Quantum.Server.Inventory.UnEquipItem( pl, equipslot, char )
char = char || Quantum.Server.Char.GetCurrentCharacter( pl ) char = char || Quantum.Server.Char.GetCurrentCharacter( pl )
@ -82,6 +77,37 @@ function Quantum.Server.Inventory.UnEquipItem( pl, equipslot, char )
end end
end end
function Quantum.Server.Inventory.EquipItem( pl, itemindex )
local char = Quantum.Server.Char.GetCurrentCharacter( pl )
local slotitem = Quantum.Server.Inventory.GetSlotItem( char, itemindex )
local itemTbl = Quantum.Item.Get( slotitem[1] )
if( itemTbl != nil ) then
local equipslot = itemTbl.equipslot
if( equipslot == nil ) then
Quantum.Error( tostring(pl) .. " tried to equip an non-equippable item: (" .. tostring(itemTbl[1]) .. ")" )
return
else
local equipslotKey = table.KeyFromValue( Quantum.EquipSlots, equipslot )
if( equipslotKey != nil ) then
Quantum.Server.Inventory.UnEquipItem( pl, equipslot, char ) -- unequip the slot first
char.equipped[equipslot] = itemindex -- set it in the table
setupEquipedItem( pl, itemTbl ) -- setup the player
Quantum.Debug( tostring(pl) .. " equipped item (" .. tostring(slotitem[1]) .. ") - (" .. tostring(itemindex) .. ")" )
-- NETWORKING --
Quantum.Net.Inventory.SetEquipItem( pl, itemindex, equipslot )
else
Quantum.Error( tostring(pl) .. " tried to equip an item in a non-existent equip slot: (" .. tostring(equipslot) .. ")" )
return
end
end
end
end
function Quantum.Server.Inventory.GetEquippedItems( pl, char ) function Quantum.Server.Inventory.GetEquippedItems( pl, char )
char = char || Quantum.Server.Char.GetCurrentCharacter( pl ) char = char || Quantum.Server.Char.GetCurrentCharacter( pl )
local returnTbl = {} local returnTbl = {}

@ -17,7 +17,8 @@ Quantum.Rarity = {
Common = { txt = "Common", color = Color( 250, 250, 250, 40 ) }, Common = { txt = "Common", color = Color( 250, 250, 250, 40 ) },
Rare = { txt = "Rare", color = Color( 48, 163, 230, 40 ) }, Rare = { txt = "Rare", color = Color( 48, 163, 230, 40 ) },
Epic = { txt = "Epic", color = Color( 220, 90, 90, 40 ) }, Epic = { txt = "Epic", color = Color( 220, 90, 90, 40 ) },
Legendary = { txt = "Legendary", color = Color( 235, 125, 52, 40 ) } Legendary = { txt = "Legendary", color = Color( 235, 125, 52, 40 ) },
Weapon = { txt = "Illegal", color = Color( 220, 90, 90, 40 ) }
} }
Quantum.EquipSlots = { Quantum.EquipSlots = {

@ -7,13 +7,32 @@
local plugin = {} local plugin = {}
plugin.types = {
pwb = "weapon_pwb",
quantum = "quantum",
cw = "cw",
m9k = "m9k",
weapon = "weapon"
}
plugin.AllowedTypes = { plugin.AllowedTypes = {
["fas2"] = true, [plugin.types.pwb] = true,
["weapon"] = true, [plugin.types.weapon] = true,
["quantum"] = true, [plugin.types.quantum] = true,
["cw"] = true [plugin.types.cw] = true,
[plugin.types.m9k] = true
} }
local function createItemName( entclass )
local str = string.Replace( entclass, "_", " " )
for i, ns in pairs( plugin.types ) do
str = string.Replace( str, ns, "" )
end
return string.upper( str )
end
function plugin.getAllWeaponID() function plugin.getAllWeaponID()
local returnTbl = {} local returnTbl = {}
for _, ent in pairs( weapons.GetList() ) do for _, ent in pairs( weapons.GetList() ) do
@ -38,11 +57,12 @@ function plugin.CreateItems( weps )
for _, wepID in pairs( weps ) do for _, wepID in pairs( weps ) do
local swepTbl = weapons.Get( wepID ) local swepTbl = weapons.Get( wepID )
Quantum.Debug( "Added " .. wepID .. " as an item!" ) Quantum.Debug( "Added " .. wepID .. " as an item!" )
local wepName = createItemName( wepID )
Quantum.Item.Create( wepID, { Quantum.Item.Create( wepID, {
name = swepTbl.PrintName, name = wepName,
desc = swepTbl.Purpose, desc = "A firearm." || swepTbl.Purpose,
model = swepTbl.WorldModel, model = swepTbl.WorldModel,
rarity = Quantum.Rarity.Common, rarity = Quantum.Rarity.Weapon,
equipslot = Quantum.EquipSlots.Weapon, equipslot = Quantum.EquipSlots.Weapon,
equipgive = wepID equipgive = wepID
} ) } )

Loading…
Cancel
Save