Added respawning for nodes

master
E. Almqvist 5 years ago
parent 30205ceb10
commit 7d6d9099c7
  1. 30
      entities/entities/q_node/init.lua
  2. 14
      gamemode/engine/lib/sh_node.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

@ -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..." )

Loading…
Cancel
Save