• Print

Author Topic: Tried to use a NULL entity  (Read 9450 times)

0 Members and 1 Guest are viewing this topic.

Offline ZeD

  • Newbie
  • *
  • Posts: 20
  • Karma: 0
Tried to use a NULL entity
« on: April 13, 2015, 12:14:27 pm »
Hello guys
I created function, that give to player bonus HealthPoint for killing other players.
Code: Lua
  1. function GM:PlayerDeath( victim, inflictor, attacker )
  2.         if ( victim == attacker ) then
  3.         return 
  4.         else
  5.         attacker:SetHealth( attacker:Health() + self.HunterHealthBonus:GetInt() )
  6.         end
  7. end
And when player suicided(shoot too many incorrect props(each prop -5 HP)) in server console printed next message

How to fix this?
Full text of init.lua:
Code: Lua
  1. AddCSLuaFile("shared.lua")
  2.  
  3. local rootFolder = (GM or GAMEMODE).Folder:sub(11) .. "/gamemode/"
  4.  
  5. // add cs lua all the cl_ or sh_ files
  6. local files, dirs = file.Find(rootFolder .. "*", "LUA")
  7. for k, v in pairs(files) do
  8.         if v:sub(1,3) == "cl_" || v:sub(1,3) == "sh_" then
  9.                 AddCSLuaFile(rootFolder .. v)
  10.         end
  11. end
  12.  
  13. include("shared.lua")
  14. include("sh_class.lua")
  15. include("sh_condef.lua")
  16. include("sv_ragdoll.lua")
  17. include("sv_chattext.lua")
  18. include("sv_playercolor.lua")
  19. include("sv_player.lua")
  20. include("sv_realism.lua")
  21. include("sv_rounds.lua")
  22. include("sv_spectate.lua")
  23. include("sv_respawn.lua")
  24. include("sv_health.lua")
  25. include("sh_weightedrandom.lua")
  26. include("sv_killfeed.lua")
  27. include("sv_statistics.lua")
  28. include("sv_bot.lua")
  29. include("sv_disguise.lua")
  30. include("sv_teams.lua")
  31. include("sv_taunt.lua")
  32. include("sv_mapvote.lua")
  33. include("sv_bannedmodels.lua")
  34. include("sv_version.lua")
  35.  
  36.  
  37. util.AddNetworkString("clientIPE")
  38. util.AddNetworkString("mb_openhelpmenu")
  39. util.AddNetworkString("player_model_sex")
  40.  
  41. resource.AddFile("materials/melonbomber/skull.png")
  42. --resource.AddFile("materials/melonbomber/skull_license.txt")
  43.  
  44. GM.VoiceHearTeam = CreateConVar("ph_voice_hearotherteam", 0, bit.bor(FCVAR_NOTIFY), "Can we hear the voices of opposing teams" )
  45. GM.VoiceHearDead = CreateConVar("ph_voice_heardead", 1, bit.bor(FCVAR_NOTIFY), "Can we hear the voices of dead players and spectators" )
  46. GM.RoundLimit = CreateConVar("ph_roundlimit", 10, bit.bor(FCVAR_NOTIFY), "Number of rounds before mapvote" )
  47. GM.StartWaitTime = CreateConVar("ph_mapstartwait", 30, bit.bor(FCVAR_NOTIFY), "Number of seconds to wait for players on map start before starting round" )
  48. GM.HunterDamagePenalty = CreateConVar("ph_hunter_dmgpenalty", 5, bit.bor(FCVAR_NOTIFY), "Amount of damage a hunter should take for shooting an incorrect prop" )
  49. GM.HunterHealthBonus = CreateConVar("ph_hunter_hpbonus", 20, bit.bor(FCVAR_NOTIFY), "Amouny of bonus HP for killing props" )
  50. GM.HunterGrenadeAmount = CreateConVar("ph_hunter_smggrenades", 1, bit.bor(FCVAR_NOTIFY), "Amount of SMG grenades hunters should spawn with" )
  51. GM.DeadSpectateRoam = CreateConVar("ph_dead_canroam", 0, bit.bor(FCVAR_NOTIFY), "Can dead players use the roam spectate mode" )
  52.  
  53. function GM:PlayerDeath( victim, inflictor, attacker )
  54.         if ( victim == attacker ) then
  55.         return 
  56.         else
  57.         attacker:SetHealth( attacker:Health() + self.HunterHealthBonus:GetInt() )
  58.         end
  59. end
  60.  
  61. function GM:Initialize()
  62.         self.RoundWaitForPlayers = CurTime()
  63.  
  64.         self.DeathRagdolls = {}
  65.         self:SetupStatisticsTables()
  66.         self:LoadMapList()
  67.         self:LoadBannedModels()
  68. end
  69.  
  70. function GM:InitPostEntity()
  71.         self:CheckForNewVersion()
  72.         self:InitPostEntityAndMapCleanup()
  73.  
  74.         RunConsoleCommand("mp_show_voice_icons", "0")
  75. end
  76.  
  77. function GM:InitPostEntityAndMapCleanup()
  78.         self:RemoveBannedModelProps()
  79.         for k, ent in pairs(ents.GetAll()) do
  80.                 if ent:GetClass():find("door") then
  81.                         ent:Fire("unlock","",0)
  82.                 end
  83.                 if ent:IsDisguisableAs() then
  84.                         -- ent:DrawShadow(false)
  85.                 end
  86.         end
  87. end
  88.  
  89. function GM:Think()
  90.         self:RoundsThink()
  91.         self:SpectateThink()
  92. end
  93.  
  94. function GM:ShutDown()
  95. end
  96.  
  97. function GM:AllowPlayerPickup( ply, ent )
  98.         return true
  99. end
  100.  
  101. function GM:PlayerNoClip( ply )
  102.         timer.Simple(0, function () ply:CalculateSpeed() end)
  103.         return ply:IsSuperAdmin() || ply:GetMoveType() == MOVETYPE_NOCLIP
  104. end
  105.  
  106. function GM:OnEndRound()
  107.  
  108. end
  109.  
  110. function GM:OnStartRound()
  111.        
  112. end
  113.  
  114. function GM:EntityTakeDamage( ent, dmginfo )
  115.         if IsValid(ent) then
  116.                 if ent:IsPlayer() then
  117.                         if IsValid(dmginfo:GetAttacker()) then
  118.                                 local attacker = dmginfo:GetAttacker()
  119.                                 if attacker:IsPlayer() then
  120.                                         if attacker:Team() == ent:Team() then
  121.                                                 return true
  122.                                         end
  123.                                 end
  124.                         end
  125.                 end
  126.                 if ent:IsDisguisableAs() then
  127.                         local att = dmginfo:GetAttacker()
  128.                         if IsValid(att) && att:IsPlayer() && att:Team() == 2 then
  129.  
  130.                                 if bit.band(dmginfo:GetDamageType(), DMG_CRUSH) != DMG_CRUSH then                                      
  131.                                         local tdmg = DamageInfo()
  132.                                         tdmg:SetDamage(math.min(dmginfo:GetDamage(), math.max(self.HunterDamagePenalty:GetInt(), 1) ))
  133.                                         tdmg:SetDamageType(DMG_AIRBOAT)
  134.  
  135.                                         -- tdmg:SetAttacker(ent)
  136.                                         -- tdmg:SetInflictor(ent)
  137.  
  138.                                         tdmg:SetDamageForce(Vector(0, 0, 0))
  139.                                         att:TakeDamageInfo(tdmg)
  140.  
  141.                                         // increase stat for end of round (Angriest Hunter)
  142.                                         att.PropDmgPenalty = (att.PropDmgPenalty or 0) + tdmg:GetDamage()
  143.                                 end
  144.                         end
  145.                 end
  146.         end
  147. end
  148.  
  149. function file.ReadDataAndContent(path)
  150.         local f = file.Read(path, "DATA")
  151.         if f then return f end
  152.         f = file.Read(GAMEMODE.Folder .. "/content/data/" .. path, "GAME")
  153.         return f
  154. end
  155.  
  156. function GM:OnReloaded()
  157. end
  158.  
  159. function GM:CleanupMap()
  160.         game.CleanUpMap()
  161.         hook.Call("InitPostEntityAndMapCleanup", self)
  162.         hook.Call("MapCleanup", self)
  163. end
  164.  
  165. function GM:ShowHelp(ply)
  166.         net.Start("mb_openhelpmenu")
  167.         net.Send(ply)
  168. end
  169.  
  170. function GM:ShowSpare1(ply)
  171.         net.Start("open_taunt_menu")
  172.         net.Send(ply)
  173. end
  174.  

Offline Aaron113

  • Hero Member
  • *****
  • Posts: 803
  • Karma: 102
Re: Tried to use a NULL entity
« Reply #1 on: April 13, 2015, 12:27:14 pm »
You don't know if the attacker is valid.  Other kinds of damage besides just PvP gets run on this hook.  Just check to make sure both the entities are valid before doing anything.

Offline ZeD

  • Newbie
  • *
  • Posts: 20
  • Karma: 0
Re: Tried to use a NULL entity
« Reply #2 on: April 13, 2015, 12:43:58 pm »
yea if attacker != NULL then
fixed this, thank you

  • Print