• ply a Null entity???
    6 replies, posted
Soo apparently, I can't do GetActiveWeapon():GetClass() on ply ( the person dieing )?? Tried to use a NULL entity!(Hook: DoPlayerDeath) [lua] function GM:DoPlayerDeath(ply, attacker, dmginfo) --random bits of code from TTT -- Score only when there is a round active. if GetRoundState() == ROUND_ACTIVE then SCORE:HandleKill(ply, attacker, dmginfo) if ValidEntity(attacker) and attacker:IsPlayer() and ply:SteamID() == attacker:SteamID() then DamageLog(Format("SUICIDE:\t\t %s killed himself!", ply:Nick() ) ) elseif ValidEntity(attacker) and attacker:IsPlayer() then attacker:RecordKill(ply) DamageLog(Format("KILL:\t\t %s [%s](%s) killed %s [%s](%s)", attacker:Nick(), attacker:GetRoleString(), attacker:GetActiveWeapon():GetClass(), ply:Nick(), ply:GetRoleString(), ply:GetActiveWeapon():GetClass())) else DamageLog(Format("KILL:\t\t <something/world> killed %s [%s]", ply:Nick(), ply:GetRoleString())) end KARMA.Killed(attacker, ply, dmginfo) end --More random bits of code end [/lua]
Add this to your function. [lua] if (!ValidEntity(ply)) then return; end; [/lua]
I forgot to mention, everything works except when I add the GetActiveWeapon():GetClass()
The active weapon isn't a valid entity then.
Ooooooh.... Cuz the player is dead so it's not finding the weapon cuz he has none! Duhh... [editline]4th March 2012[/editline] Wait no, that's not it... Because it says earlier in the code: [lua] if GetConVar("ttt_dyingshot"):GetBool() then local wep = ply:GetActiveWeapon() if ValidEntity(wep) and wep.DyingShot and not ply.was_headshot and dmginfo:IsBulletDamage() then local fired = wep:DyingShot() if fired then return end end end [/lua]
Why would you put ';' after your 'end'? That's silly. And the useless () don't make your code any more readable either. [editline]4th March 2012[/editline] Also, it doesn't matter if it sais that earlier in the code, infernalcookie, because the code is not terminated if ValidEntity(*weapon*) is false.
[QUOTE=_NewBee;34986455] And the useless () don't make your code any more readable either. [/QUOTE] What useless parenthesis? Unless you're talking about Chessnut... And I guess, but I still don't understand why it would think the weapon is null.. Doesn't this function get called before the player actually dies?
Sorry, you need to Log In to post a reply to this thread.