diff --git a/lua/autorun/client/g64_cl_init.lua b/lua/autorun/client/g64_cl_init.lua index 4b9ce0b..5417961 100644 --- a/lua/autorun/client/g64_cl_init.lua +++ b/lua/autorun/client/g64_cl_init.lua @@ -283,15 +283,16 @@ hook.Add("G64Initialized", "G64_ENTITY_GEO", function() end local mario = LocalPlayer().MarioEnt + local marioIsValid = IsValid(mario) for j,surfaceId in pairs(surfaceIds[k]) do --if v:GetSolidFlags() ~= 256 then print(v, v:GetSolidFlags()) end if v:GetCollisionGroup() == COLLISION_GROUP_WORLD or v.DontCollideWithMario == true or v == LocalPlayer():GetVehicle() or - (IsValid(mario) and mario.hasVanishCap == true) or + (marioIsValid and v.G64SurfaceType == 123 and mario.hasVanishCap) or v:IsSolid() == false or v:GetNWInt("Solidity") == 0 or - (IsValid(mario) and mario.heldObj == v) then + (marioIsValid and mario.heldObj == v) then libsm64.SurfaceObjectMove(surfaceId, noCollidePos, v:GetAngles()) else diff --git a/lua/autorun/server/g64_networkstrings.lua b/lua/autorun/server/g64_networkstrings.lua index 12d0c20..02cac90 100644 --- a/lua/autorun/server/g64_networkstrings.lua +++ b/lua/autorun/server/g64_networkstrings.lua @@ -25,4 +25,5 @@ util.AddNetworkString("G64_COLLECTED1UP") util.AddNetworkString("G64_COLLECTEDCOIN") util.AddNetworkString("G64_SPAWNNEWPLAYER") util.AddNetworkString("G64_UPDATEHELDOBJECT") -util.AddNetworkString("G64_TELEPORTMARIO") \ No newline at end of file +util.AddNetworkString("G64_TELEPORTMARIO") +util.AddNetworkString("G64_GRABREQUEST") \ No newline at end of file diff --git a/lua/autorun/server/g64_sv_init.lua b/lua/autorun/server/g64_sv_init.lua index bf50f8a..3bf5e28 100644 --- a/lua/autorun/server/g64_sv_init.lua +++ b/lua/autorun/server/g64_sv_init.lua @@ -352,14 +352,9 @@ net.Receive("G64_UPLOADCOLORS", function(len, ply) end end) -net.Receive("G64_DAMAGEENTITY", function(len, ply) - local mario = net.ReadEntity() - local victim = net.ReadEntity() - local forceVec = net.ReadVector() - local hitPos = net.ReadVector() - local minDmg = net.ReadUInt(8) - - if not IsValid(victim) or !IsValid(mario) then return end +local function damageEntity(mario, victim, forceVec, hitPos, minDmg, ply) + --print(mario, victim, forceVec, hitpos, minDmg, ply) + if not IsValid(victim) or not IsValid(mario) then return end local victimHealth = victim:Health() if victim:IsNPC() or victim:IsPlayer() or victimHealth > 0 then local d = DamageInfo() @@ -394,11 +389,34 @@ net.Receive("G64_DAMAGEENTITY", function(len, ply) local phys = victim:GetPhysicsObject() phys:ApplyForceOffset(forceVec * 7800, hitPos) + + -- Allow damage taking for things like damage detectors + if victim.TakeDamageInfo ~= nil then + local d = DamageInfo() + local damage = math.random(minDmg, minDmg+10) + d:SetDamage(damage) + d:SetAttacker(mario) + d:SetInflictor(mario) + d:SetDamageType(DMG_GENERIC) + d:SetDamageForce(forceVec * 15000) + d:SetDamagePosition(hitPos) + + victim:TakeDamageInfo(d) + end end if ply:GetUseEntity() ~= NULL then - ply:GetUseEntity():Use(mario, mario, USE_ON) + ply:GetUseEntity():Use(ply, mario, USE_ON) end +end + +net.Receive("G64_DAMAGEENTITY", function(len, ply) + local mario = net.ReadEntity() + local victim = net.ReadEntity() + local forceVec = net.ReadVector() + local hitPos = net.ReadVector() + local minDmg = net.ReadUInt(8) + damageEntity(mario, victim, forceVec, hitPos, minDmg, ply) end) net.Receive("G64_REMOVEINVALIDMARIO", function(len, ply) @@ -477,6 +495,33 @@ net.Receive("G64_UPDATEHELDOBJECT", function(len, ply) end end) +local function GrabRequestReply(_, ply) + local mario = ply.MarioEnt + local entity = net.ReadEntity() + local forceVec = net.ReadVector() + local hitPos = net.ReadVector() + local volume = 1000000 + local phys = entity:GetPhysicsObject() + + if phys:IsValid() and phys:IsMotionEnabled() and phys:IsMoveable() then -- if not frozen + volume = phys:GetVolume() + end + + if volume < 65000 then + net.Start("G64_GRABREQUEST") + net.WriteBool(true) + net.WriteEntity(entity) + net.Send(ply) + else + damageEntity(mario, entity, forceVec, hitPos, 15, ply) + net.Start("G64_GRABREQUEST", true) + net.WriteBool(false) + net.WriteEntity(entity) + net.Send(ply) + end +end +net.Receive("G64_GRABREQUEST", GrabRequestReply) + local meta = FindMetaTable("Player") meta.DefaultGodEnable = meta.DefaultGodEnable or meta.GodEnable diff --git a/lua/entities/g64_mario.lua b/lua/entities/g64_mario.lua index 181d609..c5fc734 100644 --- a/lua/entities/g64_mario.lua +++ b/lua/entities/g64_mario.lua @@ -807,6 +807,25 @@ if CLIENT then local pickUpWhitelist = { prop_physics = true } + + local function GrabRequestReply() + if net.ReadBool() then + local entity = net.ReadEntity() + -- If somehow these important things changed in between net messages + if pickUpWhitelist[entity:GetClass()] and self.holdingObject == false and IsValid(self.heldObject) == false then + libsm64.SetMarioAction(self.MarioId, g64types.SM64MarioAction.ACT_PICKING_UP) + self.heldObject = entity + self.waitForHold = true + end + else + net.ReadEntity().HitStunTimer = 0.25 + local soundArg = GetSoundArg(g64types.SM64SoundTable.SOUND_ACTION_HIT) + libsm64.PlaySoundGlobal(soundArg) + end + self.pickupMode = false + end + net.Receive("G64_GRABREQUEST", GrabRequestReply) + local function PerformGroundAttacks() if self:MarioIsAttacking() then local tr = util.TraceHull({ @@ -838,43 +857,30 @@ if CLIENT then net.WriteUInt(dmg, 8) net.SendToServer() end - else - local volume = 1000000 - if self.pickupMode == true and pickUpWhitelist[tr.Entity:GetClass()] and - g64utils.MarioHasFlag(self.marioFlags, g64types.MARIO_KICKING) == false and - g64utils.MarioHasFlag(self.marioFlags, g64types.MARIO_TRIPPING) == false and - self.marioAction ~= g64types.SM64MarioAction.ACT_SLIDE_KICK and - self.marioAction ~= g64types.SM64MarioAction.ACT_SLIDE_KICK_SLIDE then - tr.Entity:PhysicsInit(6) - local phys = tr.Entity:GetPhysicsObject() - if phys:IsValid() == false then - tr.Entity:PhysicsDestroy() - else - volume = phys:GetVolume() - end - tr.Entity:PhysicsDestroy() - self.pickupMode = false - end - - --print(volume) - if volume < 65000 then - if self.holdingObject == false and IsValid(self.heldObject) == false then - libsm64.SetMarioAction(self.MarioId, g64types.SM64MarioAction.ACT_PICKING_UP) - self.heldObject = tr.Entity - self.waitForHold = true - end - else - tr.Entity.HitStunTimer = 0.25 - local soundArg = GetSoundArg(g64types.SM64SoundTable.SOUND_ACTION_HIT) - libsm64.PlaySoundGlobal(soundArg) - net.Start("G64_DAMAGEENTITY") - net.WriteEntity(self) + -- Need this here because we need the check for the else case + elseif self.pickupMode == true and pickUpWhitelist[tr.Entity:GetClass()] and + g64utils.MarioHasFlag(self.marioFlags, g64types.MARIO_KICKING) == false and + g64utils.MarioHasFlag(self.marioFlags, g64types.MARIO_TRIPPING) == false and + self.marioAction ~= g64types.SM64MarioAction.ACT_SLIDE_KICK and + self.marioAction ~= g64types.SM64MarioAction.ACT_SLIDE_KICK_SLIDE and + self.holdingObject == false and IsValid(self.heldObject) == false then + net.Start("G64_GRABREQUEST", true) net.WriteEntity(tr.Entity) net.WriteVector(self.marioForward) net.WriteVector(tr.HitPos) - net.WriteUInt(15, 8) net.SendToServer() - end + self.pickupMode = false + else + tr.Entity.HitStunTimer = 0.25 + local soundArg = GetSoundArg(g64types.SM64SoundTable.SOUND_ACTION_HIT) + libsm64.PlaySoundGlobal(soundArg) + net.Start("G64_DAMAGEENTITY") + net.WriteEntity(self) + net.WriteEntity(tr.Entity) + net.WriteVector(self.marioForward) + net.WriteVector(tr.HitPos) + net.WriteUInt(15, 8) + net.SendToServer() end end end diff --git a/lua/weapons/gmod_tool/stools/g64surfacechanger.lua b/lua/weapons/gmod_tool/stools/g64surfacechanger.lua index bece415..677f145 100644 --- a/lua/weapons/gmod_tool/stools/g64surfacechanger.lua +++ b/lua/weapons/gmod_tool/stools/g64surfacechanger.lua @@ -77,4 +77,4 @@ list.Set( "SurfaceTypes", "#tool.g64surfacechanger.hard_not_slippery", { g64surf list.Set( "SurfaceTypes", "#tool.g64surfacechanger.vertical_wind", { g64surfacechanger_g64surfacetype = g64types.SM64SurfaceType.SURFACE_VERTICAL_WIND } ) list.Set( "SurfaceTypes", "#tool.g64surfacechanger.horizontal_wind", { g64surfacechanger_g64surfacetype = g64types.SM64SurfaceType.SURFACE_HORIZONTAL_WIND } ) list.Set( "SurfaceTypes", "#tool.g64surfacechanger.noise_default", { g64surfacechanger_g64surfacetype = g64types.SM64SurfaceType.SURFACE_NOISE_DEFAULT } ) ---list.Set( "SurfaceTypes", "#tool.g64surfacechanger.vanish_cap_walls", { g64surfacechanger_g64surfacetype = g64types.SM64SurfaceType.SURFACE_VANISH_CAP_WALLS } ) \ No newline at end of file +list.Set( "SurfaceTypes", "#tool.g64surfacechanger.vanish_cap_walls", { g64surfacechanger_g64surfacetype = g64types.SM64SurfaceType.SURFACE_VANISH_CAP_WALLS } ) \ No newline at end of file