serverside cleanup

This commit is contained in:
Jonny_Bro (Nikita) 2023-05-20 14:34:59 +05:00
parent 7d937f7507
commit 7e58a2936e
12 changed files with 146 additions and 99 deletions

View file

@ -2,25 +2,31 @@ util.AddNetworkString("DisarmStart")
local cvardisarm = CreateConVar("Beatrun_Disarm", 1, FCVAR_ARCHIVE, "Whether 'using' NPCs triggers a disarm", 0, 1)
local function Disarm_Init(ply, victim)
victim:NextThink(CurTime()+100)
victim:NextThink(CurTime() + 100)
victim.InDisarm = true
victim:DropWeapon()
net.Start("DisarmStart")
net.WriteEntity(victim)
net.Send(ply)
timer.Simple(1.35, function() if IsValid(victim) then victim:TakeDamage(victim:Health()) end end)
timer.Simple(1.35, function()
if IsValid(victim) then
victim:TakeDamage(victim:Health())
end
end)
end
local function Disarm(ply, ent)
if !cvardisarm:GetBool() then return end
if ent:IsNPC() and !ent.InDisarm then
if not cvardisarm:GetBool() then return end
if ent:IsNPC() and not ent.InDisarm then
if ply:KeyPressed(IN_USE) then
Disarm_Init(ply, ent)
end
end
end
hook.Add("PlayerUse", "Disarm", Disarm)
hook.Add("CreateEntityRagdoll", "Disarm_Ragdoll", function(ent, rag)

View file

@ -1,35 +1,41 @@
local doors =
{
["func_door_rotating"] = true,
["prop_door_rotating"] = true
local doors = {
["func_door_rotating"] = true,
["prop_door_rotating"] = true
}
util.AddNetworkString("DoorBashAnim")
hook.Add("PlayerUse", "DoorBash", function(ply, ent)
if doors[ent:GetClass()] then
if ply:GetVelocity():Length() < 100 or ply:Crouching() then return end
if ent.bashdelay and ent.bashdelay > CurTime() then return end
if ent:GetInternalVariable("m_bLocked") then return end
local speed = ent:GetInternalVariable("speed")
if !ent.oldspeed then
if not ent.oldspeed then
ent.oldspeed = speed
ent.bashdelay = 0
end
net.Start("DoorBashAnim")
net.Send(ply)
ent:SetSaveValue("speed", ent.oldspeed*4)
ent:SetSaveValue("speed", ent.oldspeed * 4)
ent:Use(ply)
ent.bashdelay = CurTime()+1
ent.bashdelay = CurTime() + 1
ent:SetCycle(1)
ent:Fire("Lock")
timer.Simple(1, function()
if IsValid(ent) then
ent:SetSaveValue("speed", ent.oldspeed)
ent:Fire("Unlock")
ent:Fire("Unlock")
end
end)
ent:EmitSound("Door.Barge")
return false
end
end)

View file

@ -4,29 +4,32 @@ if game.SinglePlayer() then return end
local maxmsgcount = 100
local netIncoming_old = net.Receive
local netIncoming_detour = function(length, ply)
local tickcount = engine.TickCount()
if tickcount > (ply.NetDelay or 0) then
ply.NetDelayCount = 0
ply.NetDelay = tickcount+ 10
ply.NetDelay = tickcount + 10
end
ply.NetDelayCount = ply.NetDelayCount + 1
if ply.NetDelayCount > maxmsgcount then
ply:Kick("Client sent too much data")
return
end
local i = net.ReadHeader()
local strName = util.NetworkIDToString( i )
if ( !strName ) then return end
local func = net.Receivers[ strName:lower() ]
if ( !func ) then return end
local strName = util.NetworkIDToString(i)
if not strName then return end
local func = net.Receivers[strName:lower()]
if not func then return end
length = length - 16
func( length, ply )
func(length, ply)
end
net.Incoming = netIncoming_detour

View file

@ -4,13 +4,14 @@ function BRProtectedEntity(class, pos, ang)
a:SetAngles(ang)
a:Spawn()
a:SetNW2Bool("BRProtected", true)
return a
end
if file.Exists("beatrun/gamemode/Maps/"..game.GetMap().."_cl.lua", "LUA") then
AddCSLuaFile("beatrun/gamemode/Maps/"..game.GetMap().."_cl.lua")
if file.Exists("beatrun/gamemode/Maps/" .. game.GetMap() .. "_cl.lua", "LUA") then
AddCSLuaFile("beatrun/gamemode/Maps/" .. game.GetMap() .. "_cl.lua")
end
if file.Exists("beatrun/gamemode/Maps/"..game.GetMap()..".lua", "LUA") then
include("beatrun/gamemode/Maps/"..game.GetMap()..".lua")
if file.Exists("beatrun/gamemode/Maps/" .. game.GetMap() .. ".lua", "LUA") then
include("beatrun/gamemode/Maps/" .. game.GetMap() .. ".lua")
end

View file

@ -1,8 +1,10 @@
Beatrun_NPCs = Beatrun_NPCs or {}
local npctbl = Beatrun_NPCs
hook.Add("OnEntityCreated", "NPCTracker", function(ent)
if IsValid(ent) and ent:IsNPC() then
table.insert(Beatrun_NPCs, ent)
ent.OldProficiency = ent:GetCurrentWeaponProficiency()
ent.NextProficiency = 0
end
@ -10,7 +12,7 @@ end)
hook.Add("EntityRemoved", "NPCTracker", function(ent)
for k, npc in ipairs(npctbl) do
if !IsValid(npc) then
if not IsValid(npc) then
table.remove(npctbl, k)
end
end
@ -18,24 +20,25 @@ end)
local updaterate = 0.2
local updatetime = 0
hook.Add("Tick", "NPCBehavior", function()
local CT = CurTime()
if updatetime > CT then return end
for k, npc in ipairs(npctbl) do
if !IsValid(npc) then
continue
end
if not IsValid(npc) then continue end
local enemy = npc:GetEnemy()
if !IsValid(enemy) or !enemy:IsPlayer() then
continue
end
if not IsValid(enemy) or not enemy:IsPlayer() then continue end
if enemy:GetJumpTurn() or enemy:GetSliding() or enemy:GetWallrun() > 0 or enemy:GetVelocity():Length() > 300 then
npc:SetCurrentWeaponProficiency( WEAPON_PROFICIENCY_POOR )
npc:SetCurrentWeaponProficiency(WEAPON_PROFICIENCY_POOR)
npc.NextProficiency = CT + 1
elseif CT > npc.NextProficiency then
npc:SetCurrentWeaponProficiency( npc.OldProficiency or WEAPON_PROFICIENCY_GOOD )
npc:SetCurrentWeaponProficiency(npc.OldProficiency or WEAPON_PROFICIENCY_GOOD)
end
end
updatetime = CT + updaterate
end)

View file

@ -1,7 +1,9 @@
local updatetime = 0
hook.Add("PlayerPostThink", "PacketLossNet", function(ply)
if CurTime() > updatetime then
ply:SetNW2Int("PLoss",ply:PacketLoss())
updatetime = CurTime()+4
ply:SetNW2Int("PLoss", ply:PacketLoss())
updatetime = CurTime() + 4
end
end)

View file

@ -1,33 +1,42 @@
util.AddNetworkString("ReplayRequest")
util.AddNetworkString("ReplayTutorialPos")
net.Receive("ReplayRequest", function(len,ply)
net.Receive("ReplayRequest", function(len, ply)
local stopped = net.ReadBool()
if !stopped and !ply.InReplay and ((Course_Name != "") or TUTORIALMODE) then
if not stopped and not ply.InReplay and ((Course_Name ~= "") or TUTORIALMODE) then
ply.InReplay = true
ply:ResetParkourState()
ply:Spawn()
ply:SetNW2Int("CPNum", -1)
ply:SetLocalVelocity(vector_origin)
ply:SetLaggedMovementValue( 0 )
timer.Simple(0.1, function() ply:SetLaggedMovementValue( 1 ) end)
if !TUTORIALMODE then
ply:SetLaggedMovementValue(0)
timer.Simple(0.1, function()
ply:SetLaggedMovementValue(1)
end)
if not TUTORIALMODE then
ply:SetPos(Course_StartPos)
else
ply:SetPos(net.ReadVector())
end
net.Start("ReplayRequest")
net.Send(ply)
elseif stopped then
ply.InReplay = false
end
hook.Run("PostReplayRequest", ply, stopped)
end)
net.Receive("ReplayTutorialPos", function(len, ply)
if !TUTORIALMODE then return end
if not TUTORIALMODE then return end
local pos = net.ReadVector()
ply:SetPos(pos or ply:GetPos())
ply:SetLocalVelocity(vector_origin)
end)

View file

@ -1,22 +1,15 @@
util.AddNetworkString("ToggleWhitescale")
local skypaint
local skypaintdata = {
Vector(0, 0.34, 0.93),
Vector(0.36, 0.76, 1),
Vector(0.25, 0.1, 0),
Vector(1, 1, 1),
0.44,
0.66,
0.79,
0.5,
7.44
}
local skypaintdata = {Vector(0, 0.34, 0.93), Vector(0.36, 0.76, 1), Vector(0.25, 0.1, 0), Vector(1, 1, 1), 0.44, 0.66, 0.79, 0.5, 7.44}
function WhitescaleOn()
if BlockWhitescaleSkypaint then return end
if !IsValid(skypaint) then
if not IsValid(skypaint) then
skypaint = ents.FindByClass("env_skypaint")[1]
end
if IsValid(skypaint) then
skypaint:SetTopColor(skypaintdata[1])
skypaint:SetBottomColor(skypaintdata[2])
@ -33,9 +26,8 @@ end
net.Receive("ToggleWhitescale", function(len, ply)
local toggle = net.ReadBool()
if toggle then
WhitescaleOn()
else
end
else return end
end)

View file

@ -6,44 +6,55 @@ local function Echo()
end
blinded = false
concommand.Add("toggleblindness", function(ply)
if IsValid(ply) and !ply:IsSuperAdmin() then return end
blinded = !blinded
if IsValid(ply) and not ply:IsSuperAdmin() then return end
blinded = not blinded
net.Start("BlindPlayers")
net.WriteBool(blinded)
net.Broadcast()
if blinded then
for k,v in pairs(ents.FindByClass("env_soundscape")) do
for k, v in pairs(ents.FindByClass("env_soundscape")) do
v:Remove()
end
hook.Add("EntityEmitSound","Echo",Echo)
hook.Add("EntityEmitSound", "Echo", Echo)
else
hook.Remove("EntityEmitSound","Echo")
hook.Remove("EntityEmitSound", "Echo")
end
end)
local red = Color(255,90,90)
local green = Color(90,255,90)
local red = Color(255, 90, 90)
local green = Color(90, 255, 90)
concommand.Add("blindplayer", function(ply, cmd, args)
if IsValid(ply) and !ply:IsSuperAdmin() then return end
if IsValid(ply) and not ply:IsSuperAdmin() then return end
local blinded = tobool(args[2])
local blindedstr = (blinded and "is now blind.\n") or "is no longer blind.\n"
local blindedcol = (blinded and red) or green
local plysearch = args[1]
if !plysearch then
if not plysearch then
MsgC(red, "syntax: blindplayer (player name) (0/1)\n")
return
end
local mply = nil
local mname = ""
local mcount = 0
for k,v in ipairs(player.GetAll()) do
for k, v in ipairs(player.GetAll()) do
local name = v:Nick()
local smatch = string.match(name, plysearch)
if smatch then
local slen = smatch:len()
if slen > mcount then
mply = v
mname = name
@ -51,19 +62,21 @@ concommand.Add("blindplayer", function(ply, cmd, args)
end
end
end
if IsValid(mply) then
MsgC(blindedcol, mname, " ", blindedstr)
else
MsgC(red, "Player not found: ",plysearch)
MsgC(red, "Player not found: ", plysearch)
return
end
net.Start("BlindPlayers")
net.WriteBool(blinded)
net.Send(mply)
end)
hook.Add("OnNPCKilled", "BlindNPCKilled", function(npc,attacker,inflictor)
hook.Add("OnNPCKilled", "BlindNPCKilled", function(npc, attacker, inflictor)
if blinded and attacker:IsPlayer() then
net.Start("BlindNPCKilled")
net.Send(attacker)

View file

@ -1,6 +1,7 @@
DEFINE_BASECLASS( "gamemode_base" )
DEFINE_BASECLASS("gamemode_base")
function GM:PlayerSpawn(ply, transition)
player_manager.SetPlayerClass( ply, "player_beatrun" )
BaseClass.PlayerSpawn( self, ply, transition )
player_manager.SetPlayerClass(ply, "player_beatrun")
BaseClass.PlayerSpawn(self, ply, transition)
end

View file

@ -1,16 +1,24 @@
util.AddNetworkString("DeathStopSound")
hook.Add("EntityTakeDamage", "MEHitSounds", function( ply, dmginfo )
if !ply:IsPlayer() then return end
if ( dmginfo:IsBulletDamage() ) then
--[[Block damage if they're going very fast]]
if ply:GetVelocity():Length() > 400 then return true end
ply:EmitSound("mirrorsedge/Flesh_0"..tostring(math.random(1,9))..".wav")
ply:ViewPunch(Angle(math.Rand(-10,-5),0,math.Rand(0,5)))
elseif ( dmginfo:IsFallDamage() and ply:Health()-dmginfo:GetDamage()<=0 ) and !ply:HasGodMode() and !blinded then
hook.Add("EntityTakeDamage", "MEHitSounds", function(ply, dmginfo)
if not ply:IsPlayer() then return end
if dmginfo:IsBulletDamage() then
--[[Block damage if they're going very fast]]
if ply:GetVelocity():Length() > 400 then return true end
ply:EmitSound("mirrorsedge/Flesh_0" .. tostring(math.random(1, 9)) .. ".wav")
ply:ViewPunch(Angle(math.Rand(-10, -5), 0, math.Rand(0, 5)))
elseif (dmginfo:IsFallDamage() and ply:Health() - dmginfo:GetDamage() <= 0) and not ply:HasGodMode() and not blinded then
net.Start("DeathStopSound")
net.Send(ply)
timer.Simple(0.01,function() if IsValid(ply) then ply:EmitSound("mirrorsedge/DeathFall"..tostring(math.random(1,4))..".wav") end end)
ply:ScreenFade( SCREENFADE.OUT, Color( 0, 0, 0, 255 ), 0.05, 10 )
timer.Simple(0.01, function()
if IsValid(ply) then
ply:EmitSound("mirrorsedge/DeathFall" .. tostring(math.random(1, 4)) .. ".wav")
end
end)
ply:ScreenFade(SCREENFADE.OUT, Color(0, 0, 0, 255), 0.05, 10)
end
end)

View file

@ -1,9 +1,12 @@
function LadderSpawnDebug()
local p=Entity(1):GetEyeTrace()
a=ents.Create('br_ladder')
local p = Entity(1):GetEyeTrace()
a = ents.Create("br_ladder")
a:SetAngles(p.HitNormal:Angle())
a:SetPos(p.HitPos+p.HitNormal*10)
a:SetPos(p.HitPos + p.HitNormal * 10)
a:Spawn()
sk=util.QuickTrace(p.HitPos,Vector(0,0,100000)).HitPos-p.HitNormal*10
a:LadderHeightExact(util.QuickTrace(sk, Vector(0,0,-100000)).HitPos:Distance(a:GetPos())-62)
sk = util.QuickTrace(p.HitPos, Vector(0, 0, 100000)).HitPos - p.HitNormal * 10
a:LadderHeightExact(util.QuickTrace(sk, Vector(0, 0, -100000)).HitPos:Distance(a:GetPos()) - 62)
end