diff --git a/entities/weapons/quantum_hands/shared.lua b/entities/weapons/quantum_hands/shared.lua new file mode 100644 index 0000000..c55993a --- /dev/null +++ b/entities/weapons/quantum_hands/shared.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 \ No newline at end of file diff --git a/gamemode/engine/core/client/cl_hud.lua b/gamemode/engine/core/client/cl_hud.lua index 4230128..0a6dcda 100644 --- a/gamemode/engine/core/client/cl_hud.lua +++ b/gamemode/engine/core/client/cl_hud.lua @@ -7,7 +7,8 @@ local enabledHUDs = { ["CHudChat"] = true, - ["CHudGMod"] = true + ["CHudGMod"] = true, + ["CHudWeaponSelection"] = true } hook.Add( "HUDShouldDraw", "Quantum_RemoveDefualtHUD", function( hudid ) @@ -46,10 +47,10 @@ local function renderStatHUD() surface.DrawText( hptxt ) -- Crosshair - if( Quantum.Client.ShowCrosshair ) then - surface.SetDrawColor( 255, 255, 255, 200 ) - surface.DrawRect( sw/2 - radius, sh/2 - radius, radius*2, radius*2 ) - end + -- if( Quantum.Client.ShowCrosshair ) then + -- surface.SetDrawColor( 255, 255, 255, 200 ) + -- surface.DrawRect( sw/2 - radius, sh/2 - radius, radius*2, radius*2 ) + -- end end 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( "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 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 @@ -96,7 +97,7 @@ local function renderCharNamesHUD3D2D() local distance = LocalPlayer():GetPos():Distance( ent:GetPos() ) 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 pos = ent:GetPos() pos.z = pos.z + 75 @@ -234,7 +235,7 @@ function GM:Think() end 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 DrawMotionBlur( 0.4, 0.8, 0.1 ) DrawColorModify( { diff --git a/gamemode/engine/core/server/sv_player_init.lua b/gamemode/engine/core/server/sv_player_init.lua index ba82074..8742a8f 100644 --- a/gamemode/engine/core/server/sv_player_init.lua +++ b/gamemode/engine/core/server/sv_player_init.lua @@ -37,6 +37,9 @@ local function setUpPlayer( ply ) ply:SetCrouchedWalkSpeed( Quantum.Server.Settings.PlayerSpeeds.duck) ply:SetMaxSpeed( Quantum.Server.Settings.PlayerSpeeds.run ) + ply:Give( "quantum_hands" ) + ply:SetActiveWeapon( "quantum_hands" ) + Quantum.Debug( tostring( ply ) .. charnametxt ) end diff --git a/gamemode/engine/derma/menus/menu_charinfo.lua b/gamemode/engine/derma/menus/menu_charinfo.lua index 60782f7..2c82343 100644 --- a/gamemode/engine/derma/menus/menu_charinfo.lua +++ b/gamemode/engine/derma/menus/menu_charinfo.lua @@ -160,6 +160,7 @@ function menu.open( dt ) if( !f ) then Quantum.Client.IsInMenu = true + Quantum.Client.IsInInventory = true local f = vgui.Create( "DFrame" ) f:SetSize( sw, sh ) @@ -175,6 +176,7 @@ function menu.open( dt ) end function f:OnClose() Quantum.Client.IsInMenu = false -- show the hud when closed + Quantum.Client.IsInInventory = false Quantum.Client.Cam.Stop() end diff --git a/gamemode/engine/lib/server/sv_inventory.lua b/gamemode/engine/lib/server/sv_inventory.lua index d3c5eff..4baca0a 100644 --- a/gamemode/engine/lib/server/sv_inventory.lua +++ b/gamemode/engine/lib/server/sv_inventory.lua @@ -25,41 +25,36 @@ local function isStackable( item ) return item.stack || false 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 +local function setupWeaponItem( pl, itemTbl, dontSelect ) + if( itemTbl.equipgive != nil ) then + pl:Give( itemTbl.equipgive, false ) + if( !dontSelect ) then pl:SelectWeapon( itemTbl.equipgive ) end + end +end - char.equipped[equipslot] = itemindex -- set it in the table - if( itemTbl.equipeffect != nil ) then - Quantum.Effect.Give( pl, itemTbl.equipeffect ) -- give the player the effect - end - if( itemTbl.equipgive != nil ) then - pl:Give( itemTbl.equipgive ) - pl:SelectWeapon( itemTbl.equipgive ) - end - Quantum.Debug( tostring(pl) .. " equipped item (" .. tostring(slotitem[1]) .. ") - (" .. tostring(itemindex) .. ")" ) - -- NETWORKING -- - Quantum.Net.Inventory.SetEquipItem( pl, itemindex, equipslot ) +local function setupEquipedItem( pl, itemTbl ) + if( itemTbl.equipeffect != nil ) then + Quantum.Effect.Give( pl, itemTbl.equipeffect ) -- give the player the effect + end + setupWeaponItem( pl, itemTbl ) +end - else - Quantum.Error( tostring(pl) .. " tried to equip an item in a non-existent equip slot: (" .. tostring(equipslot) .. ")" ) - return - end +local function setupWeaponOnRespawn( pl, char ) + char = char || Quantum.Server.Char.GetCurrentCharacter( pl ) + local slotItem = Quantum.Server.Inventory.GetSlotItem( char, char.equipped[Quantum.EquipSlots.Weapon] ) + if( slotItem != nil ) then + local itemTbl = Quantum.Item.Get( slotItem[1] ) + if( itemTbl != nil ) then + setupEquipedItem( pl, itemTbl, true ) 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 ) char = char || Quantum.Server.Char.GetCurrentCharacter( pl ) @@ -82,6 +77,37 @@ function Quantum.Server.Inventory.UnEquipItem( pl, equipslot, char ) 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 ) char = char || Quantum.Server.Char.GetCurrentCharacter( pl ) local returnTbl = {} diff --git a/gamemode/engine/vars/sh_vars.lua b/gamemode/engine/vars/sh_vars.lua index 926b4a1..42df895 100644 --- a/gamemode/engine/vars/sh_vars.lua +++ b/gamemode/engine/vars/sh_vars.lua @@ -17,7 +17,8 @@ Quantum.Rarity = { Common = { txt = "Common", color = Color( 250, 250, 250, 40 ) }, Rare = { txt = "Rare", color = Color( 48, 163, 230, 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 = { diff --git a/plugins/plugin_addweaponsasitems.lua b/plugins/plugin_addweaponsasitems.lua index 29f1557..244d90f 100644 --- a/plugins/plugin_addweaponsasitems.lua +++ b/plugins/plugin_addweaponsasitems.lua @@ -7,13 +7,32 @@ local plugin = {} +plugin.types = { + pwb = "weapon_pwb", + quantum = "quantum", + cw = "cw", + m9k = "m9k", + weapon = "weapon" +} + plugin.AllowedTypes = { - ["fas2"] = true, - ["weapon"] = true, - ["quantum"] = true, - ["cw"] = true + [plugin.types.pwb] = true, + [plugin.types.weapon] = true, + [plugin.types.quantum] = 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() local returnTbl = {} for _, ent in pairs( weapons.GetList() ) do @@ -38,11 +57,12 @@ function plugin.CreateItems( weps ) for _, wepID in pairs( weps ) do local swepTbl = weapons.Get( wepID ) Quantum.Debug( "Added " .. wepID .. " as an item!" ) + local wepName = createItemName( wepID ) Quantum.Item.Create( wepID, { - name = swepTbl.PrintName, - desc = swepTbl.Purpose, + name = wepName, + desc = "A firearm." || swepTbl.Purpose, model = swepTbl.WorldModel, - rarity = Quantum.Rarity.Common, + rarity = Quantum.Rarity.Weapon, equipslot = Quantum.EquipSlots.Weapon, equipgive = wepID } )