diff --git a/entities/entities/q_node/init.lua b/entities/entities/q_node/init.lua index eb69999..867f63e 100644 --- a/entities/entities/q_node/init.lua +++ b/entities/entities/q_node/init.lua @@ -24,33 +24,14 @@ function ENT:Initialize() end -function ENT:InitializeNode( nodeid, pos, ang ) - if( pos == nil || ang == nil ) then return end - - local nodeTbl = Quantum.node.Get( nodeid ) - - if( nodeTbl != nil ) then - self:SetModel( nodeTbl.model ) - self.nodeid = nodeid - - self:SetNWString( "q_node_id", nodeid ) - - self:SetPos( pos ) - self:SetAngles( ang ) - self:SetHealth( nodeTbl.health ) - print( "#########", self:Health() ) - else - Quantum.Error( "Node Table could not be found '" .. nodeid .. "'!" ) - self:Remove() - end -end - function ENT:OnTakeDamage( dmgInfo ) if( !self.m_bApplyingDamage ) then - self.m_bApplyingDamage = true - self:TakeDamageInfo( dmgInfo ) - print( self:Health() ) + self:SetHealth( self:Health() - dmgInfo:GetDamage() ) + if( self:Health() <= 0 ) then + Quantum.Node.Remove( self ) + end + print( self:Health(), dmgInfo:GetDamage() ) local attacker = dmgInfo:GetAttacker() local wep = attacker:GetActiveWeapon() @@ -58,6 +39,5 @@ function ENT:OnTakeDamage( dmgInfo ) Quantum.Node.Gather( attacker, wep:GetClass(), self ) end - self.m_bApplyingDamage = false end end \ No newline at end of file diff --git a/gamemode/engine/lib/sh_node.lua b/gamemode/engine/lib/sh_node.lua index 52947bb..80fe0fa 100644 --- a/gamemode/engine/lib/sh_node.lua +++ b/gamemode/engine/lib/sh_node.lua @@ -42,6 +42,10 @@ if SERVER then ent:SetPos( vec ) ent:SetAngles( ang ) + ent:SetNWString( "q_node_id", nodeid ) + ent:SetHealth( node.health ) + print( "#########", ent:Health() ) + ent:Spawn() end @@ -94,6 +98,16 @@ if SERVER then end end + function Quantum.Node.UpdateAll() + Quantum.Debug( "Updating all nodes..." ) + Quantum.Node.RemoveAllPerma() + Quantum.Node.SpawnAllRegistered() + end + + if( #player.GetAll() > 0 ) then + Quantum.Node.UpdateAll() -- update all nodes on lua refresh + end + hook.Add( "PlayerInitialSpawn", "Quantum_Init_Nodes_Load", function() Quantum.Debug( "Spawning registered nodes..." )