SRCDS.exe Has stopped working, again !

So now it’s no longer the VC2:EjectPassengers that is crashing, it’s much more a problem, due to the fact these are now core functions that crashs the server !!

The first crashing function is crashing the server randomly : DFrame:Close() !! I know it’s client side function, however sometimes when you close a derma frame it crashs the server !

The second crashing function is this time ALWAYS crashing the server : hooking into ENT:OnTakeDamage and apply damages to self causes the crash, here is the code to reproduce the issue :



SpawnBackNPCs = {}
timer.Create("RealisticRoleplay_NPCReSpawner", 15, 0, function()
	for k, v in pairs(SpawnBackNPCs) do
		local ent = ents.Create(v.Class)
		ent:SetPos(v.Pos)
		ent:SetAngles(v.Ang)
		ent:Spawn()
		table.remove(SpawnBackNPCs, k)
		return
	end	
end)

function ENT:OnTakeDamage(dmg)
	self:TakePhysicsDamage(dmg)
	self:TakeDamage(dmg:GetDamage())
	if (self:Health() <= 0) then
		table.insert(SpawnBackNPCs, {Class = self:GetClass(), Pos = self:GetPos(), Ang = self:GetAngles()})
	end
	return false
end


You’re causing an infinite loop… Think about it. On Take Damage, apply damage which triggers On Take Damage which applies damage which triggers…

Don’t apply damage in an OnTakeDamage hook. If ANYTHING you modify the Damage Info based on the data you’re given; you’re simply creating a new damage instance which defeats the purpose of the hook. Here, so you can print the data:

https://dl.dropboxusercontent.com/u/26074909/tutoring/__projects/acecooldev_base/gamemode/shared/_definitions/__metatables.lua
https://dl.dropboxusercontent.com/u/26074909/tutoring/__projects/acecooldev_base/gamemode/shared/_definitions/__metatables__tostring.lua


//
// DamageInfo tostring
//
META_CTAKEDAMAGEINFO = FindMetaTable( "CTakeDamageInfo" );
function META_CTAKEDAMAGEINFO:__tostring( )
	-- local _depth = string.rep( DEPTH_DELIMITER, 1 + depth );
	local _depth = "	";
	return "DAMAGE INFO:
" .. _depth .. "GetMaxDamage		" .. tostring( self:GetMaxDamage( ) ) ..
		"
" .. _depth .. "GetAttacker		" .. tostring( self:GetAttacker( ) ) ..
		"
" .. _depth .. "GetDamage		" .. tostring( self:GetDamage( ) ) ..
		"
" .. _depth .. "GetReportedPosition	" .. tostring( self:GetReportedPosition( ) ) ..
		"
" .. _depth .. "GetDamageForce		" .. tostring( self:GetDamageForce( ) ) ..
		"
" .. _depth .. "GetDamagePosition	" .. tostring( self:GetDamagePosition( ) ) ..
		"
" .. _depth .. "GetInflictor		" .. tostring( self:GetInflictor( ) ) ..
		"
" .. _depth .. "GetDamageType		" .. tostring( self:GetDamageType( ) ) ..
		"
" .. _depth .. "GetBaseDamage		" .. tostring( self:GetBaseDamage( ) ) ..
		"
" .. _depth .. "GetAmmoType		" .. tostring( self:GetAmmoType( ) ) ..
		"
" .. _depth .. "IsExplosionDamage	" .. tostring( self:IsExplosionDamage( ) ) ..
		"
" .. _depth .. "IsFallDamage		" .. tostring( self:IsFallDamage( ) ) ..
		"
" .. _depth .. "IsBulletDamage		" .. tostring( self:IsBulletDamage( ) );
end
	

Ok so no problem i’ll redirect damages to health, if i remember it’s SetHealth !

You shouldn’t manually SetHealth because it doesn’t kill the player if you set it to 0 meaning you’d have to manually control that too… SetHealth isn’t meant for taking damage…

There are so many hooks and functions to manage damage, scale it, handle it, etc…

Look these up ( ignore second arg on hook.Adds, these are just unique names ):

hook.Add( “EntityTakeDamage”, “ScaleNPCDamage:InjurySounds”, function( _t, _dmgInfo )
hook.Add( “ScaleNPCDamage”, “ScaleNPCDamage:InjurySounds”, function( _p, _hitGroup, _dmgInfo )
hook.Add( “ScalePlayerDamage”, “ScalePlayerDamage:InjurySounds”, function( _p, _hitGroup, _dmgInfo )
hook.Add( “PlayerShouldTakeDamage”, “AcecoolAdmin:FreezePlayer:PlayerShouldTakeDamage”, function( _victim, _attacker )
function ENT:OnTakeDamage( _dmgInfo )
function META_ENTITY:TakeDamageInfo( _dmgInfo )
function META_ENTITY:TakeDamage( … )

PlayerShouldTakeDamage( _p, _inflictor )

and some examples of systems which deal damage: https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/drowning.lua.html

https://dl.dropboxusercontent.com/u/26074909/tutoring/takedamageinfo_example.lua.html