Skip to content

Commit

Permalink
> Fixes for null errors
Browse files Browse the repository at this point in the history
  • Loading branch information
connawiles committed Oct 13, 2016
1 parent b49205d commit 3d9fe10
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,7 @@ if (SERVER) then

if (ragdoll and entity != ragdoll) then
hook.Call("EntityTakeDamage", Clockwork, ragdoll, damageInfo);

damageInfo:SetDamage(0);

return true;
Expand All @@ -1290,14 +1291,15 @@ if (SERVER) then
local curTime = CurTime();

if (damageInfo:IsDamageType(DMG_CRUSH)) then
if (entity.cwNextFallDamage
and curTime < entity.cwNextFallDamage) then
if (entity.cwNextFallDamage and curTime < entity.cwNextFallDamage) then
damageInfo:SetDamage(0);
return true;
end;

amount = hook.Call("GetFallDamage", Clockwork, player, velocity);

entity.cwNextFallDamage = curTime + 1;

damageInfo:SetDamage(amount)
end;
end;
Expand Down
50 changes: 31 additions & 19 deletions Clockwork/garrysmod/gamemodes/clockwork/framework/sv_kernel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3412,21 +3412,23 @@ function Clockwork:PlayerDeath(player, inflictor, attacker, damageInfo)
end;
end;

if (attacker:IsPlayer()) then
if (IsValid(attacker:GetActiveWeapon())) then
local weapon = attacker:GetActiveWeapon();
local itemTable = cwItem:GetByWeapon(weapon);

if (IsValid(weapon) and itemTable) then
cwKernel:PrintLog(LOGTYPE_CRITICAL, attacker:Name().." has dealt "..tostring(math.ceil(damageInfo:GetDamage())).." damage to "..player:Name().." with "..itemTable("name")..", killing them!");
if (damageInfo) then
if (attacker:IsPlayer()) then
if (IsValid(attacker:GetActiveWeapon())) then
local weapon = attacker:GetActiveWeapon();
local itemTable = cwItem:GetByWeapon(weapon);

if (IsValid(weapon) and itemTable) then
cwKernel:PrintLog(LOGTYPE_CRITICAL, attacker:Name().." has dealt "..tostring(math.ceil(damageInfo:GetDamage())).." damage to "..player:Name().." with "..itemTable("name")..", killing them!");
else
cwKernel:PrintLog(LOGTYPE_CRITICAL, attacker:Name().." has dealt "..tostring(math.ceil(damageInfo:GetDamage())).." damage to "..player:Name().." with "..cwPly:GetWeaponClass(attacker)..", killing them!");
end;
else
cwKernel:PrintLog(LOGTYPE_CRITICAL, attacker:Name().." has dealt "..tostring(math.ceil(damageInfo:GetDamage())).." damage to "..player:Name().." with "..cwPly:GetWeaponClass(attacker)..", killing them!");
cwKernel:PrintLog(LOGTYPE_CRITICAL, attacker:Name().." has dealt "..tostring(math.ceil(damageInfo:GetDamage())).." damage to "..player:Name()..", killing them!");
end;
else
cwKernel:PrintLog(LOGTYPE_CRITICAL, attacker:Name().." has dealt "..tostring(math.ceil(damageInfo:GetDamage())).." damage to "..player:Name()..", killing them!");
cwKernel:PrintLog(LOGTYPE_CRITICAL, attacker:GetClass().." has dealt "..tostring(math.ceil(damageInfo:GetDamage())).." damage to "..player:Name()..", killing them!");
end;
else
cwKernel:PrintLog(LOGTYPE_CRITICAL, attacker:GetClass().." has dealt "..tostring(math.ceil(damageInfo:GetDamage())).." damage to "..player:Name()..", killing them!");
end;
end;

Expand Down Expand Up @@ -3619,18 +3621,21 @@ function Clockwork:EntityTakeDamage(entity, damageInfo)
entity.cwDamageImmunity = curTime + 1;

damageInfo:SetDamage(0);

return false;
end;

if (IsValid(attacker) and attacker:GetClass() == "worldspawn"
and entity.cwDamageImmunity and entity.cwDamageImmunity > curTime) then
damageInfo:SetDamage(0);

return false;
end;

if ((IsValid(inflictor) and inflictor:IsBeingHeld())
or attacker:IsBeingHeld()) then
damageInfo:SetDamage(0);

return false;
end;
end;
Expand Down Expand Up @@ -3676,13 +3681,17 @@ function Clockwork:EntityTakeDamage(entity, damageInfo)

if (damageInfo:GetDamage() > 0) then
cwKernel:CalculatePlayerDamage(player, lastHitGroup, damageInfo);

player:SetVelocity(cwKernel:ConvertForce(damageInfo:GetDamageForce() * 32, 200));

if (player:Alive() and player:Health() == 1) then
player:SetFakingDeath(true);
hook.Call("DoPlayerDeath", self, player, attacker, damageInfo);
hook.Call("PlayerDeath", self, player, inflictor, attacker, damageInfo);
cwKernel:CreateBloodEffects(damageInfo:GetDamagePosition(), 1, player, damageInfo:GetDamageForce());

hook.Call("DoPlayerDeath", self, player, attacker, damageInfo);
hook.Call("PlayerDeath", self, player, inflictor, attacker, damageInfo);

cwKernel:CreateBloodEffects(damageInfo:GetDamagePosition(), 1, player, damageInfo:GetDamageForce());

player:SetFakingDeath(false, true);
else
local bNoMsg = cwPlugin:Call("PlayerTakeDamage", player, inflictor, attacker, lastHitGroup, damageInfo);
Expand All @@ -3709,6 +3718,7 @@ function Clockwork:EntityTakeDamage(entity, damageInfo)
end;

damageInfo:SetDamage(0);

player.cwLastHitGroup = nil;
end;
else
Expand All @@ -3735,11 +3745,13 @@ function Clockwork:EntityTakeDamage(entity, damageInfo)

if (player:Alive() and player:Health() == 1) then
player:SetFakingDeath(true);
player:GetRagdollTable().health = 0;
player:GetRagdollTable().armor = 0;

hook.Call("DoPlayerDeath", self, player, attacker, damageInfo);
hook.Call("PlayerDeath", self, player, inflictor, attacker, damageInfo);

player:GetRagdollTable().health = 0;
player:GetRagdollTable().armor = 0;

hook.Call("DoPlayerDeath", self, player, attacker, damageInfo);
hook.Call("PlayerDeath", self, player, inflictor, attacker, damageInfo);

player:SetFakingDeath(false, true);
elseif (player:Alive()) then
local bNoMsg = cwPlugin:Call("PlayerTakeDamage", player, inflictor, attacker, hitGroup, damageInfo);
Expand Down

0 comments on commit 3d9fe10

Please sign in to comment.