feat: Basic speed limiter when creating a course

This commit is contained in:
Jonny_Bro 2025-03-08 22:57:16 +05:00
parent defaccf399
commit aa25793c10
No known key found for this signature in database
GPG key ID: A18808B38428F7C4
13 changed files with 68 additions and 42 deletions

View file

@ -83,6 +83,7 @@ beatrun.toolsmenu.courses.changeapikey=Change API Key
beatrun.toolsmenu.courses.enterapikey=Enter your API key
beatrun.toolsmenu.courses.savecourse=Save Currently Running Course to a File
beatrun.toolsmenu.courses.savesetspeed=Set speed
beatrun.toolsmenu.courses.namesavecourse=Enter a name for your course
beatrun.toolsmenu.courses.loadcourse=Load a Course from the Online Database

View file

@ -80,6 +80,7 @@ beatrun.toolsmenu.courses.changeapikey=Cambia API Key
beatrun.toolsmenu.courses.enterapikey=Inserisci your API key
beatrun.toolsmenu.courses.savecourse=Salva la corsa attualmente in esecuzione in un file
beatrun.toolsmenu.courses.savesetspeed=Set speed
beatrun.toolsmenu.courses.namesavecourse=Inserisci un nome per la tua corsa
beatrun.toolsmenu.courses.loadcourse=Carica una corsa dal Database Online

View file

@ -83,6 +83,7 @@ beatrun.toolsmenu.courses.changeapikey=Zmień klucz API
beatrun.toolsmenu.courses.enterapikey=Wpisz swój klucz API
beatrun.toolsmenu.courses.savecourse=Zapisz aktualnie biegnięty bieg do pliku
beatrun.toolsmenu.courses.savesetspeed=Set speed
beatrun.toolsmenu.courses.namesavecourse=Wprowadź nazwę biegu
beatrun.toolsmenu.courses.loadcourse=Załaduj bieg z internetowej bazy danych

View file

@ -80,6 +80,7 @@ beatrun.toolsmenu.courses.changeapikey=Mudar chave API
beatrun.toolsmenu.courses.enterapikey=Entre sua chave API
beatrun.toolsmenu.courses.savecourse=Salvar o Percurso Atual para um Arquivo
beatrun.toolsmenu.courses.savesetspeed=Set speed
beatrun.toolsmenu.courses.namesavecourse=Nomeie o seu Percurso
beatrun.toolsmenu.courses.loadcourse=Carregar um Percurso da Database Online

View file

@ -83,6 +83,7 @@ beatrun.toolsmenu.courses.changeapikey=Изменить API Ключ
beatrun.toolsmenu.courses.enterapikey=Введите ваш API ключ
beatrun.toolsmenu.courses.savecourse=Сохранить Текущий Курс в Файл
beatrun.toolsmenu.courses.savesetspeed=Макс. скорость
beatrun.toolsmenu.courses.namesavecourse=Введите название для курса
beatrun.toolsmenu.courses.loadcourse=Загрузить Курс из Базы
@ -133,9 +134,9 @@ beatrun.toolsmenu.hud.floatxpcolor=Цвет Всплывающего XP в HUD
beatrun.toolsmenu.camera.name=Камера
beatrun.toolsmenu.camera.desc=Настройки камеры
beatrun.toolsmenu.camera.stabilization=Стабилизация Покачивания
beatrun.toolsmenu.camera.stabilization=Стабилизация покачивания
beatrun.toolsmenu.camera.stabilizationdesc=Включите чтобы снизить покачивание камеры центрируя её
beatrun.toolsmenu.camera.intensity=Интенсивность Покачивания Камеры
beatrun.toolsmenu.camera.intensity=Интенсивность покачивания камеры
beatrun.toolsmenu.camera.fov=Угол Обзора
beatrun.toolsmenu.camera.fovdesc=Изменяет ваш Угол Обзора

View file

@ -80,6 +80,7 @@ beatrun.toolsmenu.courses.changeapikey=API Anahtarını Değiştir
beatrun.toolsmenu.courses.enterapikey=API anahtarınızı girin
beatrun.toolsmenu.courses.savecourse=Şu Anda Devam Eden Koşuyu Bir Dosyaya Kaydet
beatrun.toolsmenu.courses.savesetspeed=Set speed
beatrun.toolsmenu.courses.namesavecourse=Koşunuz için bir ad girin
beatrun.toolsmenu.courses.loadcourse=Çevrim içi Veritabandan Koşu Yükle

View file

@ -81,6 +81,7 @@ beatrun.toolsmenu.courses.changeapikey=Змінити API Ключ
beatrun.toolsmenu.courses.enterapikey=Введіть ваш API ключ
beatrun.toolsmenu.courses.savecourse=Зберегти Поточний Курс у Файл
beatrun.toolsmenu.courses.savesetspeed=Макс. швидкість
beatrun.toolsmenu.courses.namesavecourse=Введіть назву для курсу
beatrun.toolsmenu.courses.loadcourse=Завантажити Курс з Бази

View file

@ -228,7 +228,7 @@ local function BuildModeElements()
local obsolete = Material("editor/obsolete")
for k, v in pairs(buildmode_ents) do
for k, _ in pairs(buildmode_ents) do
local img = AEUI:AddImage(propspanel, buildmode_enticons[k] or obsolete, BMPropClick, 64 * row, 64 * col, 64, 64)
img.prop = k
img.hover = buildmode_entnames[k] or scripted_ents.GetMember(k, "PrintName")

View file

@ -63,22 +63,36 @@ hook.Add("PopulateToolMenu", "Beatrun_ToolMenu", function()
saveCourseButton.DoClick = function()
local frame = vgui.Create("DFrame")
frame:SetTitle("#beatrun.toolsmenu.courses.namesavecourse")
frame:SetSize(300, 100)
frame:SetSize(300, 110)
frame:SetDeleteOnClose(true)
frame:Center()
frame:MakePopup()
local TextEntry = vgui.Create("DTextEntry", frame)
TextEntry:Dock(TOP)
local text = vgui.Create("DTextEntry", frame)
text:Dock(TOP)
local checkbox = vgui.Create("DCheckBox", frame)
checkbox:SetPos(5, 55)
checkbox:SetValue(false)
local slider = vgui.Create("DNumSlider", frame)
slider:SetText("#beatrun.toolsmenu.courses.savesetspeed")
slider:SetPos(25, 55)
slider:SetSize(280, 20)
slider:SetDecimals(0)
slider:SetMin(325)
slider:SetMax(1000)
slider:SetValue(325)
local okButton = vgui.Create("DButton", frame)
okButton:SetText("#beatrun.misc.ok")
okButton:SetPos(25, 60)
okButton:SetSize(250, 30)
okButton:SetPos(25, 80)
okButton:SetSize(250, 25)
okButton.DoClick = function()
local name = string.Replace(TextEntry:GetValue(), " ", "_")
local name = string.Replace(text:GetValue(), " ", "_")
local speed = tostring(slider:GetValue())
RunConsoleCommand("Beatrun_SaveCourse", name)
RunConsoleCommand("Beatrun_SaveCourse", name, checkbox:GetChecked() and speed or 0)
frame:Close()
end
end

View file

@ -336,6 +336,7 @@ if SERVER then
net.WriteFloat(Course_StartAng)
net.WriteString(Course_Name)
net.WriteString(Course_ID)
net.WriteInt(Course_Speed, 11)
net.Broadcast()
end
@ -344,6 +345,11 @@ if SERVER then
Course_Name = ""
Course_ID = ""
Course_Speed = 0
for _, plr in ipairs(player.GetAll()) do
plr:ConCommand("Beatrun_SpeedLimit 325")
end
game.CleanUpMap()
Course_Sync()
@ -572,6 +578,8 @@ if SERVER then
local data = util.Decompress(net.ReadData(len))
if not data then return print("[BR] Error while loading a course") end
Beatrun_ReadCourse(data)
end
@ -579,29 +587,21 @@ if SERVER then
local dir = "beatrun/courses/" .. string.Replace(game.GetMap(), " ", "-") .. "/"
local save = file.Read(dir .. id .. ".txt", "DATA")
if not save then
print("NON-EXISTENT SAVE", id)
return
end
if not save then return print("[BR] Non-existent save with id: " .. tostring(id)) end
Course_ID = id
Beatrun_ReadCourse(save)
Beatrun_ReadCourse(save, id)
end
function Beatrun_ReadCourse(data)
function Beatrun_ReadCourse(data, id)
game.CleanUpMap()
local a = util.Decompress(data) or data
local id = util.CRC(a)
local data = util.JSONToTable(a)
local decompress = util.Decompress(data) or data
id = id or util.CRC(decompress)
local courseData = util.JSONToTable(decompress)
local props = data[1]
local cp = data[2]
local pos = data[3]
local ang = data[4]
local name = data[5]
local entities = data[6]
local props, cp, pos, ang, name, entities, speed = unpack(courseData)
for _, v in pairs(props) do
local a = ents.Create("prop_physics")
@ -665,10 +665,15 @@ if SERVER then
Course_StartAng = ang
Course_Name = name
Course_ID = id
Course_Speed = speed
Course_Sync()
for _, v in pairs(player.GetAll()) do
if Course_Speed and Course_Speed ~= 0 then
v:ConCommand("Beatrun_SpeedLimit " .. tostring(Course_Speed))
end
v:SetNW2Float("PBTime", 0)
v:SetNW2Int("CPNum", 1)
v:SetMoveType(MOVETYPE_WALK)
@ -897,21 +902,23 @@ if CLIENT then
playerstart:DrawModel()
end
function CourseData(name)
local save = {{}, {}, Course_StartPos, Course_StartAng, name or os.date("%H:%M:%S - %d/%m/%Y", os.time()), {}}
function CourseData(name, speed)
-- [1] = Props, [2] = Checkpoints, [3] = Starting pos, [4] = Starting ang, [5] = Name, [6] = Entities, [7] = Restricted player's speed (0 = unrestricted)
local save = {{}, {}, Course_StartPos, Course_StartAng, name or os.date("%H:%M:%S - %d/%m/%Y", os.time()), {}, speed or 0}
for _, v in pairs(buildmode_placed) do
if not IsValid(v) then continue end
if v:GetNW2Bool("BRProtected") then
print("ignoring protected ent")
print("[BR] Ignoring protected ent")
else
local class = v:GetClass()
if class == "prop_physics" then
local hr = false
if v:GetMaterial() == "medge/redplainplastervertex" then hr = true end
//if v.buildmode_placed_manually then hr = false end
-- if v.buildmode_placed_manually then hr = false end
table.insert(save[1], {
model = v:GetModel():lower(),
@ -940,21 +947,15 @@ if CLIENT then
return save
end
function SaveCourse(name, compress)
local save = CourseData(name)
function SaveCourse(name, speed)
local save = CourseData(name, speed)
local jsonsave = util.TableToJSON(save)
local id = util.CRC(jsonsave)
local dir = "beatrun/courses/" .. string.Replace(game.GetMap(), " ", "-") .. "/"
if compress == nil then compress = true end
file.CreateDir(dir)
if compress then
file.Write(dir .. id .. ".txt", util.Compress(jsonsave))
else
file.Write(dir .. id .. ".txt", jsonsave)
end
file.Write(dir .. id .. ".txt", util.Compress(jsonsave))
print("Save created: " .. id .. ".txt")
end
@ -962,7 +963,7 @@ if CLIENT then
concommand.Add("Beatrun_SaveCourse", function(ply, cmd, args, argstr)
local name = args[1] or os.date("%H:%M:%S - %d/%m/%Y", os.time())
SaveCourse(name, tobool(args[2]))
SaveCourse(name, args[2] or 0)
end)
function LoadCourse(id)
@ -1032,12 +1033,14 @@ if CLIENT then
local ang = net.ReadFloat()
local name = net.ReadString()
local id = net.ReadString()
local speed = net.ReadInt(11)
Course_StartPos:SetUnpacked(x, y, z)
Course_StartAng = ang
Course_Name = name
Course_ID = id or Course_ID
Course_Speed = speed
end)
buildmodeinputs = {
@ -1319,7 +1322,7 @@ if CLIENT then
end
if BuildModeIndex == 0 then
local svec = gui.ScreenToVector(gui.MouseX(), gui.MouseY()) //util.AimVector(LocalPlayer():EyeAngles(), 133, mousex, mousey, ScrW(), ScrH())
local svec = gui.ScreenToVector(gui.MouseX(), gui.MouseY()) -- util.AimVector(LocalPlayer():EyeAngles(), 133, mousex, mousey, ScrW(), ScrH())
svec:Mul(100000)
local start = LocalPlayer():EyePos()

View file

@ -6,6 +6,7 @@ Course_GoTime = 0
Course_EndTime = 0
Course_ID = Course_ID or ""
Course_Name = Course_Name or ""
Course_Speed = Course_Speed or 0
local cptimes = {}
local lastcptime = 0
local pbtimes = nil

View file

@ -17,6 +17,7 @@ if SERVER then
net.WriteFloat(Course_StartAng)
net.WriteString(Course_Name)
net.WriteString(Course_ID)
net.WriteInt(Course_Speed, 11)
net.Send(ply)
ply.Synced = true

View file

@ -522,7 +522,7 @@ hook.Add("SetupMove", "qslide", function(ply, mv, cmd)
if not slippery and pos.z > ply:GetSlidingLastPos().z + 1 then
ply:SetSlidingTime(ply:GetSlidingTime() - 0.025)
elseif slippery or slidedelta < 1 and pos.z < ply:GetSlidingLastPos().z - 0.25 then
ply:SetSlidingTime(CT + slidetime) --[[ GetConVar("Beatrun_SpeedLimit"):GetInt() ]]
ply:SetSlidingTime(CT + slidetime) --[[ GetConVar("Beatrun_SpeedLimit"):GetInt() ]]
ply:SetSlidingVel(math.min(mv:GetVelocity():Length() * 0.865, 450 * ply:GetOverdriveMult()))
end