• SRCDS.exe Has stopped working, again !
    3 replies, posted
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 : [code] 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 [/code]
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: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/__projects/acecooldev_base/gamemode/shared/_definitions/__metatables.lua[/url] [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/__projects/acecooldev_base/gamemode/shared/_definitions/__metatables__tostring.lua[/url] [code]// // DamageInfo tostring // META_CTAKEDAMAGEINFO = FindMetaTable( "CTakeDamageInfo" ); function META_CTAKEDAMAGEINFO:__tostring( ) -- local _depth = string.rep( DEPTH_DELIMITER, 1 + depth ); local _depth = "\t"; return "DAMAGE INFO:\n" .. _depth .. "GetMaxDamage\t\t" .. tostring( self:GetMaxDamage( ) ) .. "\n" .. _depth .. "GetAttacker\t\t" .. tostring( self:GetAttacker( ) ) .. "\n" .. _depth .. "GetDamage\t\t" .. tostring( self:GetDamage( ) ) .. "\n" .. _depth .. "GetReportedPosition\t" .. tostring( self:GetReportedPosition( ) ) .. "\n" .. _depth .. "GetDamageForce\t\t" .. tostring( self:GetDamageForce( ) ) .. "\n" .. _depth .. "GetDamagePosition\t" .. tostring( self:GetDamagePosition( ) ) .. "\n" .. _depth .. "GetInflictor\t\t" .. tostring( self:GetInflictor( ) ) .. "\n" .. _depth .. "GetDamageType\t\t" .. tostring( self:GetDamageType( ) ) .. "\n" .. _depth .. "GetBaseDamage\t\t" .. tostring( self:GetBaseDamage( ) ) .. "\n" .. _depth .. "GetAmmoType\t\t" .. tostring( self:GetAmmoType( ) ) .. "\n" .. _depth .. "IsExplosionDamage\t" .. tostring( self:IsExplosionDamage( ) ) .. "\n" .. _depth .. "IsFallDamage\t\t" .. tostring( self:IsFallDamage( ) ) .. "\n" .. _depth .. "IsBulletDamage\t\t" .. tostring( self:IsBulletDamage( ) ); end [/code]
Ok so no problem i'll redirect damages to health, if i remember it's SetHealth !
[QUOTE=Yuri6037;47449768]Ok so no problem i'll redirect damages to health, if i remember it's SetHealth ![/QUOTE] 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: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/drowning.lua.html[/url] [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/takedamageinfo_example.lua.html[/url]
Sorry, you need to Log In to post a reply to this thread.