diff --git a/entities/entities/lambda_checkpoint.lua b/entities/entities/lambda_checkpoint.lua index b3fc1980..dcb692ef 100644 --- a/entities/entities/lambda_checkpoint.lua +++ b/entities/entities/lambda_checkpoint.lua @@ -136,14 +136,20 @@ function ENT:Think() end end +-- TODO: Remove all instances, use SetRenderPos function ENT:SetVisiblePos(pos) self:SetNWVector("VisiblePos", pos) end +ENT.SetRenderPos = ENT.SetVisiblePos + +-- TODO: Remove all instances, use GetRenderPos function ENT:GetVisiblePos() return self:GetNWVector("VisiblePos", self:GetPos()) end +ENT.GetRenderPos = ENT.GetVisiblePos + function ENT:SetDynamicCheckpoint(dynamic) self:SetNWBool("DynamicCheckpoint", dynamic) end diff --git a/gamemode/gametypes/hl2ep2/mapscripts/ep2_outland_07.lua b/gamemode/gametypes/hl2ep2/mapscripts/ep2_outland_07.lua index 93191030..ee529ad4 100644 --- a/gamemode/gametypes/hl2ep2/mapscripts/ep2_outland_07.lua +++ b/gamemode/gametypes/hl2ep2/mapscripts/ep2_outland_07.lua @@ -45,6 +45,20 @@ MAPSCRIPT.GlobalStates = { } MAPSCRIPT.Checkpoints = { + { + Pos = Vector(-9988, -10067, 129), + Ang = Angle(0, 0, 0), + RenderPos = Vector(-9846, -10569, 114), + Trigger = { + Pos = Vector(-10506, -11740, 151), + Mins = Vector(-500, -50, 0), + Maxs = Vector(1500, 50, 200) + }, + Vehicle = { + Pos = Vector(-9846, -10604, 118.5), + Ang = Angle(0, -100, 0), + } + }, } function MAPSCRIPT:PostInit() @@ -96,6 +110,8 @@ function MAPSCRIPT:PostInit() -- Resize the trigger and make it wait for all players. ents.WaitForEntityByName("trigger_alyx_start_advisor_scene", function(ent) + ent:Remove() + local ent = ents.Create("trigger_once") ent:SetupTrigger( Vector(-9600, -9708, 125), Angle(0, 0, 0), diff --git a/gamemode/sh_vehicles.lua b/gamemode/sh_vehicles.lua index 92ffa737..f62b80fd 100644 --- a/gamemode/sh_vehicles.lua +++ b/gamemode/sh_vehicles.lua @@ -429,8 +429,7 @@ if SERVER then end function GM:SpawnVehicleAtSpot(vehicle) - local pos = util.StringToType(vehicle["origin"], "Vector") - if self.VehicleCheckpoint ~= nil then pos = self.VehicleCheckpoint.Pos end + local pos = self:GetVehicleSpawnPos() -- Check if there is already one. local nearbyEnts = ents.FindInBox(pos + VEHICLE_SPAWN_MINS, pos + VEHICLE_SPAWN_MAXS) for _, v in pairs(nearbyEnts) do @@ -442,7 +441,7 @@ if SERVER then -- The box is somewhat big, we should deal with players standing directly in the way. end - DbgPrint("Spawning vehicle...") + DbgPrint("Spawning vehicle at spot: " .. tostring(pos)) local newVehicle = ents.CreateFromData(vehicle) if self.VehicleCheckpoint ~= nil then newVehicle:SetPos(self.VehicleCheckpoint.Pos) diff --git a/gamemode/shared.lua b/gamemode/shared.lua index 876c4c62..5bde73c6 100644 --- a/gamemode/shared.lua +++ b/gamemode/shared.lua @@ -185,6 +185,10 @@ function GM:OnReloaded() self:SetGameType(lambda_gametype:GetString()) self:InitSettings() self:InitializeDifficulty() + + if SERVER then + self:ReloadCheckpoints() + end end function GM:Tick() diff --git a/gamemode/sv_checkpoints.lua b/gamemode/sv_checkpoints.lua index c58ef0da..7c18345d 100644 --- a/gamemode/sv_checkpoints.lua +++ b/gamemode/sv_checkpoints.lua @@ -66,6 +66,7 @@ function GM:ResetCheckpoints() self.CurrentCheckpoint = nil self.CurrentCheckpointPos = nil self.NextCheckpointTest = nil + self.CheckpointInstances = {} end function GM:CreatePlayerCheckpoint(data) @@ -112,6 +113,16 @@ local function CreateCheckpointWithTrigger(data) end end + local vehicleData = data.Vehicle + if vehicleData ~= nil then + if vehicleData.Pos == nil then + error("Missing Vehicle.Pos in data") + end + if vehicleData.Ang == nil then + error("Missing Vehicle.Ang in data") + end + end + local triggerData = data.Trigger if triggerData == nil then @@ -131,12 +142,20 @@ local function CreateCheckpointWithTrigger(data) end local checkpoint = GAMEMODE:CreateCheckpoint(data.Pos, data.Ang) + if data.RenderPos ~= nil then + checkpoint:SetRenderPos(data.RenderPos) + end + local checkpointTrigger = ents.Create("trigger_once") checkpointTrigger:SetupTrigger(triggerData.Pos, triggerData.Ang or Angle(0, 0, 0), triggerData.Mins, triggerData.Maxs) checkpointTrigger.OnTrigger = function(_, activator) GAMEMODE:SetPlayerCheckpoint(checkpoint, activator) + if vehicleData ~= nil then + GAMEMODE:SetVehicleCheckpoint(vehicleData.Pos, vehicleData.Ang) + end + local mapscript = GAMEMODE:GetMapScript() if mapscript ~= nil and mapscript.DefaultLoadout ~= nil then local loadoutWeapons = mapscript.DefaultLoadout.Weapons @@ -160,11 +179,41 @@ local function CreateCheckpointWithTrigger(data) end end end + + local checkpointData = { + Checkpoint = checkpoint, + Trigger = checkpointTrigger + } + + return checkpointData end function GM:CreateCheckpointsFromData(data) for _, cp in pairs(data) do - CreateCheckpointWithTrigger(cp) + local instance = CreateCheckpointWithTrigger(cp) + if instance ~= nil then + table.insert(self.CheckpointInstances, instance) + end + end +end + +function GM:ReloadCheckpoints() + local mapScript = self:GetMapScript() + if mapScript == nil then return end + + -- Remove old ones. + self.CheckpointInstances = self.CheckpointInstances or {} + for _, v in pairs(self.CheckpointInstances) do + if IsValid(v.Trigger) then + v.Trigger:Remove() + end + if IsValid(v.Checkpoint) then + v.Checkpoint:Remove() + end + end + + if mapScript.Checkpoints ~= nil then + self:CreateCheckpointsFromData(mapScript.Checkpoints) end end