diff --git a/changelog.md b/changelog.md index 2f2f8450..8d9786a3 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,7 @@ - Improved: ep1_citadel_00: Fixed T-pose on vortigaunt and remove leftover chapter messages. - Improved: d3_breen_01: Get the functionality closer to the original. - Improved: Add a button in the settings menu to revert colors. +- Improved: ep1_c17_05: Escorting the NPCs should be a bit more reliable now. - Fixed: Transitioning doors have sometimes the wrong rotation. - Fixed: HUD is now hidden when point_viewcontrol takes control. - Fixed: Triggers not firing outputs when they are disabled and then enabled again while entities are touching it. diff --git a/entities/entities/lambda_player_follow.lua b/entities/entities/lambda_player_follow.lua deleted file mode 100644 index bc4ce992..00000000 --- a/entities/entities/lambda_player_follow.lua +++ /dev/null @@ -1,136 +0,0 @@ -local DbgPrint = GetLogging("PlayerFollow") -local DESTINATION_DISTANCE_TOLERANCE = 94 -local DISTANCE_RUN_THRESHOLD = 256 - ---- -ENT.Base = "lambda_entity" -ENT.Type = "point" -DEFINE_BASECLASS("lambda_entity") ---- -function ENT:PreInitialize() - DbgPrint(self, "PreInitialize") - BaseClass.PreInitialize(self) - self:SetInputFunction("Enable", self.EnableInput) - self:SetInputFunction("Disable", self.DisableInput) - self:SetupNWVar( - "Disabled", - "bool", - { - Default = false, - KeyValue = "StartDisabled" - } - ) -end - -function ENT:Initialize() - BaseClass.Initialize(self) - DbgPrint(self, "Initialize") -end - -function ENT:KeyValue(key, val) - BaseClass.KeyValue(self, key, val) - if key:iequals("actor") then - self.Actor = val - end -end - -local function GetClosestPlayer(pos) - local players = player.GetAll() - local closest = nil - local closestDist = 999999 - for _, v in pairs(players) do - local dist = v:GetPos():Distance(pos) - if dist < closestDist then - closest = v - closestDist = dist - end - end - - return closest -end - -local function FollowEntity(ent, entToFollow) - -- Set the goal position infront of the player. - local currentPos = ent:GetPos() - local targetPos = entToFollow:GetPos() - local distance = targetPos:Distance(currentPos) - if distance > DISTANCE_RUN_THRESHOLD then - -- Set target pos to the actual entity position. - targetPos = entToFollow:GetPos() - else - -- See if the entity is moving. - local vel = entToFollow:GetVelocity() - if vel:Length() > 0 then - -- Set target pos to the actual entity position. - targetPos = entToFollow:GetPos() - else - -- Set target pos to the actual entity position. - targetPos = entToFollow:GetPos() + (entToFollow:GetForward() * DESTINATION_DISTANCE_TOLERANCE) - end - end - - -- Entity might be in the air, so we need to adjust the target position. - local tr = util.TraceLine({ - start = targetPos, - endpos = targetPos - Vector(0, 0, 256), - mask = MASK_SOLID_BRUSHONLY, - filter = ent - }) - if tr.Hit then - targetPos = tr.HitPos - end - - if distance < DESTINATION_DISTANCE_TOLERANCE then return end - ent:SetLastPosition(targetPos) - local currentSchedule = ent:GetCurrentSchedule() - if currentSchedule == SCHED_FORCED_GO then - -- Check if we should start running. - if distance > DISTANCE_RUN_THRESHOLD then - ent:SetSchedule(SCHED_FORCED_GO_RUN) - end - elseif currentSchedule == SCHED_FORCED_GO_RUN then - -- Check if we should start walking. - if distance < DISTANCE_RUN_THRESHOLD then - ent:SetSchedule(SCHED_FORCED_GO) - end - elseif currentSchedule == SCHED_IDLE_STAND or currentSchedule == SCHED_ALERT_STAND or currentSchedule == SCHED_FAIL then - -- We are idle, we should start going. - if distance > DISTANCE_RUN_THRESHOLD then - ent:SetSchedule(SCHED_FORCED_GO_RUN) - else - ent:SetSchedule(SCHED_FORCED_GO) - end - end -end - -function ENT:Think() - if self:GetNWVar("Disabled", false) == true then - self:NextThink(CurTime() + 0.5) - - return true - end - - local actors = ents.FindByName(self.Actor) - if #actors == 0 then return end - -- Make all actors follow the closest player. - for _, v in pairs(actors) do - if not v:IsNPC() then continue end - local currentPos = v:GetPos() - local closestPly = GetClosestPlayer(currentPos) - if closestPly == nil then continue end - FollowEntity(v, closestPly) - end - - self:NextThink(CurTime() + 0.5) - - return true -end - -function ENT:EnableInput() - self:SetDisabled(false) - self:NextThink(CurTime()) -end - -function ENT:DisableInput() - self:SetDisabled(true) -end \ No newline at end of file diff --git a/gamemode/gametypes/hl2ep1/mapscripts/ep1_c17_05.lua b/gamemode/gametypes/hl2ep1/mapscripts/ep1_c17_05.lua index 2f22e852..1a3cc5b8 100644 --- a/gamemode/gametypes/hl2ep1/mapscripts/ep1_c17_05.lua +++ b/gamemode/gametypes/hl2ep1/mapscripts/ep1_c17_05.lua @@ -44,11 +44,21 @@ MAPSCRIPT.Checkpoints = {} function MAPSCRIPT:PostInit() -- Force the NPCs to follow the player. Squads in Garry's Mod are a bit broken, the replacement -- lambda_player_follow entity is a bit more reliable but also quite hacky. - local playerFollow = ents.Create("lambda_player_follow") + local playerFollow = ents.Create("ai_goal_follow") playerFollow:SetName("lambda_follow_player") playerFollow:SetKeyValue("actor", "citizen_refugees*") + playerFollow:SetKeyValue("goal", "!player") + playerFollow:SetKeyValue("Formation", "0") + playerFollow:SetKeyValue("MaximumState", "1") + playerFollow:SetKeyValue("StartActive", "0") + playerFollow:SetKeyValue("SearchType", "0") playerFollow:Spawn() - playerFollow:Activate() + + ents.WaitForEntityByName("relay_pickup_citizens", function(ent) + ent:Fire("AddOutput", "OnTrigger lambda_follow_player,Deactivate,,0,-1") + ent:Fire("AddOutput", "OnTrigger lambda_follow_player,Activate,,0.01,-1") + end) + -- Alyx should wait for everyone at the end before closing ents.WaitForEntityByName( "counter_everyone_in_place_for_barney_goodbye", @@ -69,7 +79,7 @@ function MAPSCRIPT:PostInit() ents.WaitForEntityByName( "rallypoint_barney_lasttrain", function(ent) - ent:Fire("AddOutput", "OnArrival lambda_close_doors,Enable,,0,-1", "0.0") + ent:Fire("AddOutput", "OnArrival lambda_close_doors,Enable,,0,-1") end )