From 59c368624282c04b714247d3613aa43a5ee4a2b6 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Fri, 22 May 2020 16:34:37 +0200 Subject: [PATCH] Began work on dialogue system --- entities/entities/q_npc/init.lua | 24 ++++++++++++++++++- entities/entities/q_npc/shared.lua | 6 +++-- gamemode/engine/lib/sh_dialogue.lua | 36 +++++++++++++++++++++++++++++ gamemode/engine/lib/sh_node.lua | 4 +++- gamemode/settings/sh_nodes.lua | 25 ++++++++++++++++++-- 5 files changed, 89 insertions(+), 6 deletions(-) create mode 100644 gamemode/engine/lib/sh_dialogue.lua diff --git a/entities/entities/q_npc/init.lua b/entities/entities/q_npc/init.lua index 0566efb..1ba8f72 100644 --- a/entities/entities/q_npc/init.lua +++ b/entities/entities/q_npc/init.lua @@ -18,8 +18,30 @@ function ENT:Initialize() self:SetNPCState( NPC_STATE_IDLE ) self:SetSolid( SOLID_BBOX ) - self:CapabilitiesAdd( CAP_ANIMATEDFACE + CAP_TURN_HEAD ) + self:CapabilitiesAdd( CAP_ANIMATEDFACE ) + self:CapabilitiesAdd( CAP_TURN_HEAD ) self:SetUseType( SIMPLE_USE ) + self:SetSequence(self:SelectWeightedSequence(ACT_IDLE)) + self:DropToFloor() +end + +function ENT:Use() + if( self.node != nil ) then + -- open up dialogue menu + if( #self.node.voiceLines > 0 ) then + self:EmitSound(self.node.voiceLines[math.random(1, #self.node.voiceLines)]) + end + end +end + +function ENT:OnTakeDamage( dmgInfo ) + if( !self.m_bApplyingDamage ) then + if( self.node != nil ) then + if( #self.node.damageSounds > 0 ) then + self:EmitSound( self.node.damageSounds[math.random(1, #self.node.damageSounds)] ) + end + end + end end \ No newline at end of file diff --git a/entities/entities/q_npc/shared.lua b/entities/entities/q_npc/shared.lua index 95391d5..dec4908 100644 --- a/entities/entities/q_npc/shared.lua +++ b/entities/entities/q_npc/shared.lua @@ -5,11 +5,13 @@ -- \ \ / ____ \| | | | | | | | __/ (__| | | | / / -- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ -ENT.Type = "ai" ENT.Base = "base_ai" +ENT.Type = "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 +ENT.AdminSpawnable = false + +--ENT.AutomaticFrameAdvance = true \ No newline at end of file diff --git a/gamemode/engine/lib/sh_dialogue.lua b/gamemode/engine/lib/sh_dialogue.lua new file mode 100644 index 0000000..f023a01 --- /dev/null +++ b/gamemode/engine/lib/sh_dialogue.lua @@ -0,0 +1,36 @@ +-- __ _ _______ _ __ +-- / / /\ | | |__ __| | | \ \ +-- / / / \ | |_ __ ___ | | ___ ___| |__ \ \ +-- < < / /\ \ | | '_ ` _ \| |/ _ \/ __| '_ \ > > +-- \ \ / ____ \| | | | | | | | __/ (__| | | | / / +-- \_\ /_/ \_\_|_| |_| |_|_|\___|\___|_| |_| /_/ + +Quantum.Dialogue = {} + +Quantum.DialogueTbl = {} + +function Quantum.Dialogue.Create( id, tbl ) + local dialogue = { + bye = tbl.bye || "Nevermind, goodbye.", + options = tbl.options || {} + } + + Quantum.DialogueTbl[id] = dialogue + return dialogue +end + +function Quantum.Dialogue.AddQuestion( id, qid, q ) + Quantum.DialogueTbl[id][qid] = { + question = q || "...", + response = {} + } + return qid +end + +function Quantum.Dialogue.AddResponse( id, qid, tbl, order ) + table.insert(Quantum.DialogueTbl[id][qid].response, order, { + text = tbl.text || "...", + func = tbl.func, + newqID = tbl.newqID + }) +end \ No newline at end of file diff --git a/gamemode/engine/lib/sh_node.lua b/gamemode/engine/lib/sh_node.lua index 8fdf88b..373856e 100644 --- a/gamemode/engine/lib/sh_node.lua +++ b/gamemode/engine/lib/sh_node.lua @@ -23,7 +23,9 @@ function Quantum.Node.Create( nodeid, tbl ) give = tbl.give || {}, giveprobability = tbl.giveprobability || 1, health = tbl.health || Quantum.DefaultNodeHealth, - respawn = tbl.respawn || Quantum.DefaultNodeRespawnTimer + respawn = tbl.respawn || Quantum.DefaultNodeRespawnTimer, + voiceLines = tbl.voiceLines || {}, + damageSounds = tbl.damageSounds || {} } node.id = nodeid diff --git a/gamemode/settings/sh_nodes.lua b/gamemode/settings/sh_nodes.lua index 927ee0c..02026d4 100644 --- a/gamemode/settings/sh_nodes.lua +++ b/gamemode/settings/sh_nodes.lua @@ -7,10 +7,31 @@ -- NPC Nodes -- Quantum.Node.Create( "generalvendor", { - type = Quantum.NodeType.NPC, - canGather = false, name = "General Goods Vendor", model = "models/kleiner.mdl", + type = Quantum.NodeType.npc, + + voiceLines = { + "vo/coast/odessa/nlo_cub_hello.wav", + "vo/coast/odessa/male01/nlo_citizen_greet01.wav", + "vo/coast/odessa/male01/nlo_citizen_greet02.wav", + "vo/coast/odessa/male01/nlo_citizen_greet03.wav", + "vo/coast/odessa/male01/nlo_citizen_greet04.wav" + }, + + damageSounds = { + "vo/npc/male01/ow01.wav", + "vo/npc/male01/ow02.wav", + "vo/npc/male01/pain01.wav", + "vo/npc/male01/pain02.wav", + "vo/npc/male01/pain03.wav", + "vo/npc/male01/pain04.wav", + "vo/npc/male01/pain05.wav", + "vo/npc/male01/pain06.wav", + "vo/npc/male01/pain07.wav", + "vo/npc/male01/pain08.wav", + "vo/npc/male01/pain09.wav" + }, } ) -- Resource Nodes --