From dda29f599fc49dbb649dbf5bfec76e6b9cda86e4 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Thu, 21 May 2020 18:39:24 +0200 Subject: [PATCH] Added node types to include NPCs --- .../entities/{q_node => q_npc}/cl_init.lua | 0 entities/entities/q_npc/init.lua | 26 +++++++++++ entities/entities/q_npc/shared.lua | 15 +++++++ entities/entities/q_resource/cl_init.lua | 12 +++++ .../entities/{q_node => q_resource}/init.lua | 0 .../{q_node => q_resource}/shared.lua | 0 gamemode/engine/lib/sh_node.lua | 45 ++++++++++++++----- gamemode/engine/vars/sh_vars.lua | 10 ++++- gamemode/settings/sh_nodes.lua | 4 ++ 9 files changed, 100 insertions(+), 12 deletions(-) rename entities/entities/{q_node => q_npc}/cl_init.lua (100%) create mode 100644 entities/entities/q_npc/init.lua create mode 100644 entities/entities/q_npc/shared.lua create mode 100644 entities/entities/q_resource/cl_init.lua rename entities/entities/{q_node => q_resource}/init.lua (100%) rename entities/entities/{q_node => q_resource}/shared.lua (100%) diff --git a/entities/entities/q_node/cl_init.lua b/entities/entities/q_npc/cl_init.lua similarity index 100% rename from entities/entities/q_node/cl_init.lua rename to entities/entities/q_npc/cl_init.lua diff --git a/entities/entities/q_npc/init.lua b/entities/entities/q_npc/init.lua new file mode 100644 index 0000000..f824a7a --- /dev/null +++ b/entities/entities/q_npc/init.lua @@ -0,0 +1,26 @@ +-- __ _ _______ _ __ +-- / / /\ | | |__ __| | | \ \ +-- / / / \ | |_ __ ___ | | ___ ___| |__ \ \ +-- < < / /\ \ | | '_ ` _ \| |/ _ \/ __| '_ \ > > +-- \ \ / ____ \| | | | | | | | __/ (__| | | | / / +-- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ + +AddCSLuaFile( "cl_init.lua" ) +AddCSLuaFile( "shared.lua" ) + +include( "shared.lua" ) + +function ENT:Initialize() + + self:PhysicsInit( SOLID_BSP ) + self:SetMoveType( MOVETYPE_VPHYSICS ) + self:SetSolid( SOLID_VPHYSICS ) + self:SetCollisionGroup( COLLISION_GROUP_NONE ) + self:SetModel("models/kleiner.mdl") -- mingebad model :) + + local physObj = self:GetPhysicsObject() + if( IsValid( physObj ) ) then + physObj:EnableMotion( false ) + end + +end \ No newline at end of file diff --git a/entities/entities/q_npc/shared.lua b/entities/entities/q_npc/shared.lua new file mode 100644 index 0000000..95391d5 --- /dev/null +++ b/entities/entities/q_npc/shared.lua @@ -0,0 +1,15 @@ +-- __ _ _______ _ __ +-- / / /\ | | |__ __| | | \ \ +-- / / / \ | |_ __ ___ | | ___ ___| |__ \ \ +-- < < / /\ \ | | '_ ` _ \| |/ _ \/ __| '_ \ > > +-- \ \ / ____ \| | | | | | | | __/ (__| | | | / / +-- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ + +ENT.Type = "ai" +ENT.Base = "base_ai" + +ENT.PrintName = "Quantum NPC" +ENT.Author = "AlmTech" +ENT.Contact = "elias@almtech.se" +ENT.Spawnable = false +ENT.AdminSpawnable = false \ No newline at end of file diff --git a/entities/entities/q_resource/cl_init.lua b/entities/entities/q_resource/cl_init.lua new file mode 100644 index 0000000..d615b1b --- /dev/null +++ b/entities/entities/q_resource/cl_init.lua @@ -0,0 +1,12 @@ +-- __ _ _______ _ __ +-- / / /\ | | |__ __| | | \ \ +-- / / / \ | |_ __ ___ | | ___ ___| |__ \ \ +-- < < / /\ \ | | '_ ` _ \| |/ _ \/ __| '_ \ > > +-- \ \ / ____ \| | | | | | | | __/ (__| | | | / / +-- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ + +include( "shared.lua" ) + +function ENT:Draw() + self:DrawModel() +end \ No newline at end of file diff --git a/entities/entities/q_node/init.lua b/entities/entities/q_resource/init.lua similarity index 100% rename from entities/entities/q_node/init.lua rename to entities/entities/q_resource/init.lua diff --git a/entities/entities/q_node/shared.lua b/entities/entities/q_resource/shared.lua similarity index 100% rename from entities/entities/q_node/shared.lua rename to entities/entities/q_resource/shared.lua diff --git a/gamemode/engine/lib/sh_node.lua b/gamemode/engine/lib/sh_node.lua index 3bbb9b6..8bf8d15 100644 --- a/gamemode/engine/lib/sh_node.lua +++ b/gamemode/engine/lib/sh_node.lua @@ -9,12 +9,18 @@ Quantum.Node = {} -- lib Quantum.Nodes = {} -- container for vars Quantum.NodesLocations = {} +function Quantum.Node.AddNodeType(id, entclass) + Quantum.NodeType[id] = entclass -- for plugins and such +end + function Quantum.Node.Create( nodeid, tbl ) local node = { name = tbl.name || "Unknown Node", model = tbl.model, - toolids = tbl.toolids || { "q_hands" }, - give = tbl.give || {}, + type = tbl.type || Quantum.NodeType.resource, + toolids = tbl.toolids || {}, -- if it's empty then you can use all sweps/tools + canGather = tbl.canGather || false, + give = tbl.give || {}, giveprobability = tbl.giveprobability || 1, health = tbl.health || Quantum.Server.DefaultNodeHealth, respawn = tbl.respawn || Quantum.Server.DefaultNodeRespawnTimer @@ -34,7 +40,7 @@ if SERVER then function Quantum.Node.Spawn( nodeid, vec, ang ) local node = Quantum.Node.Get( nodeid ) - local ent = ents.Create( "q_node" ) + local ent = ents.Create( node.type ) ent.node = node ent.respawndelay = node.respawn || 30 ent.probability = node.probability || 1 @@ -66,14 +72,26 @@ if SERVER then end end + function Quantum.Node.GetAllEntities() + local out = {} + + for k, nodetype in pairs( Quantum.NodeType ) do + for k, node in pairs( ents.FindByClass(nodetype) ) do + out[#out + 1] = node + end + end + + return out + end + function Quantum.Node.RemoveAll() - for k, node in pairs( ents.FindByClass("q_node") ) do + for k, node in pairs( Quantum.Node.GetAllEntities() ) do Quantum.Node.Remove( node ) end end function Quantum.Node.RemoveAllPerma() - for k, node in pairs( ents.FindByClass("q_node") ) do + for k, node in pairs( Quantum.Node.GetAllEntities() ) do node:Remove() end end @@ -130,17 +148,22 @@ if SERVER then local nodeTbl = ent.node if( ent.node != nil ) then + if( !nodeTbl.canGather ) then return end local nodeid = nodeTbl.id local toolids = nodeTbl.toolids - if( #toolids > 0 ) then + if( toolids != nil ) then local canGather = false - - for i, t in pairs( toolids ) do - if( tool == t ) then - canGather = true - break + -- This is fucking retarded. + if( #toolids > 0 ) then + for i, t in pairs( toolids ) do + if( tool == t ) then + canGather = true + break + end end + else + canGather = true end if( canGather ) then diff --git a/gamemode/engine/vars/sh_vars.lua b/gamemode/engine/vars/sh_vars.lua index 56dacf1..f590827 100644 --- a/gamemode/engine/vars/sh_vars.lua +++ b/gamemode/engine/vars/sh_vars.lua @@ -36,7 +36,7 @@ Quantum.EmptyFunction = function() end ---- NETWORKING VARS DO NOT TOUCH ---- Quantum.IntCode = { - SET_ITEM = 0, + SET_ITEM = 0, DROP_ITEM = 1, USE_ITEM = 2, EAT_ITEM = 3, @@ -58,6 +58,14 @@ function Quantum.PrintPlayer( pl ) return "[" .. pl:Nick() .. "|" .. pl:SteamID() .. "]" end +---- Node vars ---- +Quantum.NodeType = { + resource = "q_resource", + npc = "q_npc" +} + +---- Property vars ---- + Quantum.DoorSounds = { Lock = "doors/default_locked.wav", Unlock = "doors/default_locked.wav" diff --git a/gamemode/settings/sh_nodes.lua b/gamemode/settings/sh_nodes.lua index 9382aea..f2f98ca 100644 --- a/gamemode/settings/sh_nodes.lua +++ b/gamemode/settings/sh_nodes.lua @@ -8,6 +8,8 @@ local miningTools = { "tool_pickaxe" } Quantum.Node.Create( "stone", { + type = Quantum.NodeType.resource, + canGather = true, name = "Stone", model = "models/props/cs_militia/militiarock05.mdl", toolids = miningTools, @@ -21,6 +23,8 @@ Quantum.Node.Create( "stone", { } ) Quantum.Node.Create( "bigstone", { + type = Quantum.NodeType.resource, + canGather = true, name = "Big Stone", model = "models/props/cs_militia/militiarock03.mdl", toolids = miningTools,