PAC3-Server / notagain

Custom Servercontent for the official PAC3 Server.
GNU General Public License v3.0
13 stars 22 forks source link

Rewrote RealisticFallDamage #85

Closed NanoAi closed 7 years ago

NanoAi commented 7 years ago

Myaats commented 7 years ago

@CapsAdmin

NanoAi commented 7 years ago

Yeah I've never seen Github reviews and I was very confused. But I'll try to make the above changes when I'm not in bed.

I passed the damage variable in the hook because I was thinking "micro optimization", felt that it would be faster to get the info like that.

Is there a difference for game.GetWorld() and Entity(0)?

As for the Goomba Stomp, to be honest I don't fully understand the exact meaning of making something "predicted". To make it predicted would I just need to mimic the movement involved clientside? On Fri, Apr 21, 2017, 4:57 AM Elias Hogstvedt, notifications@github.com wrote:

@CapsAdmin requested changes on this pull request.

testing github review

In lua/notagain/essential/autorun/server/goomba_stomp.lua https://github.com/PAC3-Server/notagain/pull/85#discussion_r112639721:

  • timer.Simple(0, function() -- Attempted Multiple Methods, this one seems to work the best.
  • if not IsValid(ent) then return end
  • ent:SetVelocity(Vector(vel.x,vel.y,vel.z*-0.7))
  • end) +end
  • +hook.Add("RealisticFallDamage", "GoombaStomp", function(ply, info, dmg, , , trace)

  • local vel = ply.fdmg_last_vel or info:GetDamageForce()
  • if trace.HitNormal.z == 1 and vel.z < 0 then
  • if not trace.HitWorld and IsValid(trace.Entity) then
  • trace.Entity.fdmg_read = true -- Sadly due to the nature of our modifications we have to apply this variable.
  • local info = DamageInfo()
  • info:SetDamagePosition(tr.HitPos)
  • info:SetDamage(dmg)
  • info:SetDamageType(DMG_FALL)

You could use DMG_CRUSH instead of DMG_FALL to avoid using the fdmg_read variable

In lua/notagain/essential/autorun/server/goomba_stomp.lua https://github.com/PAC3-Server/notagain/pull/85#discussion_r112639820:

  • timer.Simple(0, function() -- Attempted Multiple Methods, this one seems to work the best.
  • if not IsValid(ent) then return end
  • ent:SetVelocity(Vector(vel.x,vel.y,vel.z*-0.7))
  • end) +end
  • +hook.Add("RealisticFallDamage", "GoombaStomp", function(ply, info, dmg, , , trace)

  • local vel = ply.fdmg_last_vel or info:GetDamageForce()
  • if trace.HitNormal.z == 1 and vel.z < 0 then
  • if not trace.HitWorld and IsValid(trace.Entity) then
  • trace.Entity.fdmg_read = true -- Sadly due to the nature of our modifications we have to apply this variable.
  • local info = DamageInfo()
  • info:SetDamagePosition(tr.HitPos)
  • info:SetDamage(dmg)
  • info:SetDamageType(DMG_FALL)

github reviews? i'm not really sure what it is but i'm just adding comments

In lua/notagain/essential/autorun/server/goomba_stomp.lua https://github.com/PAC3-Server/notagain/pull/85#discussion_r112640355:

@@ -0,0 +1,30 @@ +local function bounce(ent,vel)

  • timer.Simple(0, function() -- Attempted Multiple Methods, this one seems to work the best.
  • if not IsValid(ent) then return end
  • ent:SetVelocity(Vector(vel.x,vel.y,vel.z*-0.7))
  • end) +end
  • +hook.Add("RealisticFallDamage", "GoombaStomp", function(ply, info, dmg, , , trace)

try to use filename (goomba_stomp) or library name as hook unique name

In lua/notagain/essential/autorun/server/goomba_stomp.lua https://github.com/PAC3-Server/notagain/pull/85#discussion_r112640541:

  • if not trace.HitWorld and IsValid(trace.Entity) then
  • trace.Entity.fdmg_read = true -- Sadly due to the nature of our modifications we have to apply this variable.
  • local info = DamageInfo()
  • info:SetDamagePosition(tr.HitPos)
  • info:SetDamage(dmg)
  • info:SetDamageType(DMG_FALL)
  • info:SetAttacker(ply)
  • info:SetInflictor(ply)
  • info:SetDamageForce(vel)
  • tr.Entity:TakeDamageInfo(info)
  • local sndindex = math.random(0,7)
  • ply:EmitSound("phx/epicmetal_hard"..(sndindex == 0 and "" or sndindex)..".wav", 45, 100) -- Play a funny sound when we stomp somone!
  • bounce(ply,vel)

I'm not so sure about bouncing. I'll have to see what it's like in game. It's also not predicted I assume (although it's not very important)

In lua/notagain/essential/autorun/server/realistic_falldamage.lua https://github.com/PAC3-Server/notagain/pull/85#discussion_r112641392:

\ No newline at end of file +end) +

I would suggest using a local variable inside the script to suppress damage instead of adding it to the player table. This makes the hack local to this file.

local suppress_fall_damage ... suppress_fall_damage = true ply:TakeDamageInfo(info) suppress_fall_damage = false ... hook.Add("EntityTakeDamage", "realistic_falldamage", function(ply, di) if suppress_fall_damage then return true end end)


In lua/notagain/essential/autorun/server/realistic_falldamage.lua https://github.com/PAC3-Server/notagain/pull/85#discussion_r112641722:

            info:SetDamage(dmg)

info:SetDamageType(DMG_FALL)

  • info:SetAttacker(ply)
  • info:SetInflictor(ply)
  • info:SetAttacker(Entity(0))
  • info:SetInflictor(Entity(0))

game.GetWorld()

In lua/notagain/essential/autorun/server/realistic_falldamage.lua https://github.com/PAC3-Server/notagain/pull/85#discussion_r112642911:

  • if fall_damage ~= 0 then
  • if fall_damage < dmg then
  • dmg = dmg - fall_damage
  • local pos = data:GetOrigin()
  • if hook.Run("RealisticFallDamage", ply, pos, dmg, len, res, params) ~= true then
  • local info = DamageInfo()
  • info:SetDamagePosition(pos)
  • info:SetDamage(dmg)
  • info:SetDamageType(DMG_FALL)
  • info:SetAttacker(Entity(0))
  • info:SetInflictor(Entity(0))
  • info:SetDamageForce(ply.fdmg_last_vel)
  • ply:TakeDamageInfo(info)
  • end
  • end
  • if hook.Run("RealisticFallDamage", ply, info, len, dmg, fall_damage, res, params) ~= true then

Since you're passing the damage info you could remove dmg sinced you can just use info:GetDamage()

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/PAC3-Server/notagain/pull/85#pullrequestreview-33969672, or mute the thread https://github.com/notifications/unsubscribe-auth/AC9ACPvUTBvfHESD5dH1dvmknJBEwp_Yks5ryG9sgaJpZM4ND3pV .

CapsAdmin commented 7 years ago

It should be faster to check upvalue but this is more about cleaner code.

Not really. Just that game.GetWorld() is more clear than Entity(0)

If your ping is high and you hit someone at a high speed you will most likely get stuck clientside for a few Ms until the client realizes the server bounced the player away from the player you hit. I think we should try the feature first and if it's a fun/good feature we can see about making it predicted

NanoAi commented 7 years ago

@CapsAdmin Fixed some stuff! :)