function UNSCLeaveRideableTurret(self) self.Sharpness = 1; end function UNSCDetachRideableTurret(self) self.Sharpness = 2; end require("Actors/AI/NativeCrabAI") function Create(self) --Stuff for making the entry area for the pilot self.PreviousFlip = self.HFlipped; --The previous hflipped, saves a bit of resources in the update self.PreviousPos = Vector(self.Pos.X, self.Pos.Y); --The previous position, saves a bit of resources in the update --Note about previouspos: Setting it to equal self.Pos makes it keep updating. Wtf? self.FlipNumber = 1; --A numerical value for HFlipped self.EntryAreaSize = 80; --The size of the box in each direction self.EntryArea = Box(Vector(self.Pos.X - (self.EntryAreaSize*self.FlipNumber), self.Pos.Y - self.EntryAreaSize) , Vector(self.Pos.X - (10*self.FlipNumber), self.Pos.Y + self.EntryAreaSize/2)); --Stuff for finding and setting the pilot self.PilotFindTimer = Timer(); --set up a delay so it's not too system heavy self.TapTimer1 = Timer(); --Two timers for double tapping self.TapTimer2 = Timer(); --i.e. tap down then up self.Pilot = nil; --The actual pilot --Stuff for when we have the pilot self.POffset = 10; --The amount we offset the pilot from the turret when he exists self.OffsetPos = Vector(0,0); --A vector with the desired offset position, for convenience self.PilotHere = false; --A flag for if the pilot is actually at the turret or not self.AI = NativeCrabAI:Create(self) --Timer for pie button objective arrows self.PieTimer = Timer(); end function UpdateAI(self) self.AI:Update(self) end function Update(self) if UInputMan:KeyPressed(3) then self:ReloadScripts() PresetMan:ReloadAllScripts(); print ("turret scripts reloaded"); end if UInputMan:KeyPressed(2) then if self.Pilot ~= nil and MovableMan:IsActor(self.Pilot) then self.Pilot:GibThis(); end end if UInputMan:KeyPressed(26) then self.Health = 20; end --If we're spinning ridiculously or dead/don't exist, the pilot falls out if math.abs(self.AngularVel) > 7 or not MovableMan:IsActor(self) or self.Health <= 0 then self.Pilot = nil; self.PilotHere = false; end --If the hflipped or position changes if self.HFlipped ~= self.PreviousFlip or self.PreviousPos.X ~= self.Pos.X or self.PreviousPos.Y ~= self.Pos.Y then --Change the flip number if self.HFlipped == true then self.FlipNumber = -1; elseif self.HFlipped == false then self.FlipNumber = 1; end --Change the box direction self.EntryArea = Box(Vector(self.Pos.X - (self.EntryAreaSize*self.FlipNumber), self.Pos.Y - self.EntryAreaSize) , Vector(self.Pos.X - (10*self.FlipNumber), self.Pos.Y + self.EntryAreaSize/2)); --Set previous flip to be hflipped and the previous pos to be self.pos self.PreviousFlip = self.HFlipped; self.PreviousPos = Vector(self.Pos.X, self.Pos.Y); end --Do a large variety of things every 10 MS to cut down a bit on potential lag if self.PilotFindTimer:IsPastSimMS(10) and self ~= nil and MovableMan:IsActor(self) then --If we have no pilot if self.Pilot == nil then --Right the turret if it's tipped, but only if it's not spinning rapidly if math.abs(self.RotAngle) > 0 and math.abs(self.AngularVel) > 0 and math.abs(self.AngularVel) < 6 then if self.RotAngle < -5 then self.AngularVel = 5; elseif self.RotAngle > 5 then self.AngularVel = -5; elseif self.RotAngle >= -5 and self.RotAngle <= 5 then self.RotAngle = 0; self.AngularVel = 0; end end --Disable the turret's controller and ai and make it unselectable if self:GetController().InputMode ~= Controller.CIM_DISABLED then self:SetControllerMode(Controller.CIM_DISABLED , self:GetController().Player); self.AIMode = Actor.AIMODE_NONE; end --Swap from turret if it's selected if MovableMan:IsActor(self) and self ~= nil then local selected = ToGameActivity(ActivityMan:GetActivity()):GetControlledActor(self.Team).ID; if selected == self.ID then if self:GetController():IsState(Controller.ACTOR_NEXT) then ToGameActivity(ActivityMan:GetActivity()):SwitchToNextActor(self:GetController().Player, self.Team, self); elseif self:GetController():IsState(Controller.ACTOR_PREV) then ToGameActivity(ActivityMan:GetActivity()):SwitchToPrevActor(self:GetController().Player, self.Team, self); else ToGameActivity(ActivityMan:GetActivity()):SwitchToPrevActor(self:GetController().Player, self.Team, self); end end end --Make the turret aim down self:SetAimAngle(-math.pi/8); --Look for a pilot and set any actor that is close enough and holds crouch as pilot. Also, add ai actors if they're in sentry mode and are close enough for actor in MovableMan.Actors do if actor.ClassName == "AHuman" and actor.AIMode ~= Actor.AIMODE_GOLDDIG and actor.AIMode ~= Actor.AIMODE_NONE and actor.Team == self.Team and self.EntryArea:WithinBox(actor.Pos) then ToGameActivity(ActivityMan:GetActivity()):AddObjectivePoint("Available pilot, hold down to take control.", actor.AboveHUDPos, self.Team, GameActivity.ARROWDOWN); --[[if actor:GetController():IsState(Controller.HOLD_DOWN) then self.TapTimer1:Reset(); end if not self.TapTimer1:IsPastSimMS(20) then if not actor:GetController():IsState(Controller.HOLD_DOWN) then self.TapTimer2:Reset() end end if not self.TapTimer2:IsPastSimMS(100) then if actor:GetController():IsState(Controller.HOLD_UP) then--]] --Changed from tap down then up to hold down for 1 second if actor:IsPlayerControlled() then if not actor:GetController():IsState(Controller.HOLD_DOWN) then self.TapTimer1:Reset(); elseif actor:GetController():IsState(Controller.HOLD_DOWN) then if self.TapTimer1:IsPastSimMS(500) then --Set the actor to be the pilot self.Pilot = actor; --Set the turret to aim straight forwards when it activates self:SetAimAngle(0); end end else --Set any sentry mode actors in the area who aren't using more expensive weapons than its gun if actor.AIMode == Actor.AIMODE_SENTRY and (actor:GetTotalValue(0, 3) - actor:GetGoldValue(0, 3) < 220) then --Set the actor to be the pilot self.Pilot = actor; --Set the turret to aim straight forwards when it activates self:SetAimAngle(0); end end end end --If we have a pilot elseif self.Pilot ~= nil then --If he's alive, do stuff if MovableMan:IsActor(self.Pilot) and self.Pilot.Health > 0 then --If the pilot is far away, have him walk close and if he's close keep him there. self.OffsetPos = Vector(self.Pos.X - self.POffset*self.FlipNumber, self.Pos.Y); if self.PilotHere == false then --Set the pilot to golddig mode, to make sure only one turret can claim him (hopefully). --TODO come up with a more elegant solution self.Pilot.AIMode = Actor.AIMODE_GOLDDIG; --Too far left if self.Pilot.Pos.X < self.OffsetPos.X - 3 then self.Pilot:GetController():SetState(Controller.MOVE_RIGHT, true); self.Pilot:GetController():SetState(Controller.MOVE_LEFT, false); --Too far right elseif self.Pilot.Pos.X > self.OffsetPos.X + 3 then self.Pilot:GetController():SetState(Controller.MOVE_LEFT, true); self.Pilot:GetController():SetState(Controller.MOVE_RIGHT, false); --Perfect elseif self.Pilot.Pos.X >= self.OffsetPos.X - 3 then --Switch to the turret ToGameActivity(ActivityMan:GetActivity()):SwitchToActor(ToActor(MovableMan:GetMOFromID(self.ID)), self.Pilot:GetController().Player, self.Pilot.Team); self.PilotHere = true; end end --If the pilot is in position if self.PilotHere == true then --Keep him here and face him the right way self.Pilot.Pos = self.OffsetPos; self.Pilot.Vel = self.Vel; self.Pilot.HFlipped = self.HFlipped; --Disable his controller and ai if self.Pilot:GetController().InputMode ~= Controller.CIM_DISABLED or self.Pilot.AIMode ~= Actor.AIMODE_NONE then self.Pilot:SetControllerMode(Controller.CIM_DISABLED , self.Pilot:GetController().Player); self.Pilot.AIMode = Actor.AIMODE_NONE; end --Set the turret to be controllable and go to sentry ai if self:GetController().InputMode == Controller.CIM_DISABLED or self.AIMode == Actor.AIMODE_NONE then self:SetControllerMode(Controller.CIM_PLAYER , self:GetController().Player); self.AIMode = Actor.AIMODE_SENTRY; end --Swap onwards if the pilot is selected, depending on which direction it's selected from local selected = ToGameActivity(ActivityMan:GetActivity()):GetControlledActor(self.Team).ID; if selected == self.Pilot.ID then if self.Pilot:GetController():IsState(Controller.ACTOR_NEXT) then ToGameActivity(ActivityMan:GetActivity()):SwitchToNextActor(self.Pilot:GetController().Player, self.Pilot.Team, self.Pilot); elseif self.Pilot:GetController():IsState(Controller.ACTOR_PREV) then ToGameActivity(ActivityMan:GetActivity()):SwitchToPrevActor(self.Pilot:GetController().Player, self.Pilot.Team, self.Pilot); --else -- ToGameActivity(ActivityMan:GetActivity()):SwitchToActor(ToActor(MovableMan:GetMOFromID(self.ID)), self.Pilot:GetController().Player, self.Pilot.Team); end end --Remove the pilot when there's no gun and break the turret when it's low health if (self.FirearmIsReady == true or self.FirearmIsEmpty == true) and self.Health <= 5 then self.Sharpness = 2; --Break the gun elseif self.FirearmIsReady == false and self.FirearmIsEmpty == false then self.Sharpness = 1; --Leave the turret end end --If he's not alive set to nil elseif not MovableMan:IsActor(self.Pilot) or self.Pilot.Health <= 0 then self.Pilot = nil; self.PilotHere = false; end end self.PilotFindTimer:Reset(); end --Pie button stuff --Remove pilot and disable turret if self.Sharpness == 0 then self.PieTimer:Reset(); elseif self.Sharpness == 1 then if self.Pilot ~= nil and MovableMan:IsActor(self.Pilot) and self ~= nil and MovableMan:IsActor(self) then self.Pilot:SetControllerMode(Controller.CIM_PLAYER , self.Pilot:GetController().Player); self.Pilot.AIMode = Actor.AIMODE_SENTRY; ToGameActivity(ActivityMan:GetActivity()):SwitchToActor(self.Pilot, self:GetController().Player, self.Team); self.Pilot = nil; self.PilotHere = false; if self.FirearmNeedsReload then self:ReloadFirearm(); end self.Sharpness = 0; elseif (self.Pilot == nil or not MovableMan:IsActor(self.Pilot)) and self ~= nil and MovableMan:IsActor(self) then ToGameActivity(ActivityMan:GetActivity()):AddObjectivePoint("No pilot to remove", self.AboveHUDPos, self.Team, GameActivity.ARROWDOWN); if self.PieTimer:IsPastSimMS(1000) then self.Sharpness = 0; end end --Break turret and remove gun elseif self.Sharpness == 2 then if self.Pilot ~= nil and MovableMan:IsActor(self.Pilot) and self ~= nil and MovableMan:IsActor(self) then if self.PilotHere == true then if self.FirearmIsReady or self.FirearmIsEmpty then self.Pilot:SetControllerMode(Controller.CIM_PLAYER , self.Pilot:GetController().Player); self.Pilot.AIMode = Actor.AIMODE_SENTRY; ToGameActivity(ActivityMan:GetActivity()):SwitchToActor(self.Pilot, self:GetController().Player, self.Team); self.Pilot:AddInventoryItem(CreateHDFirearm("M247H HMG- Machine Gun" , "UNSC.rte")); self.Pilot = nil; self.PilotHere = false; self:GibThis(); self = nil; elseif self.FirearmIsReady == false and self.FirearmIsEmpty == false then ToGameActivity(ActivityMan:GetActivity()):AddObjectivePoint("There is no gun to detach.", self.AboveHUDPos, self.Team, GameActivity.ARROWDOWN); if self.PieTimer:IsPastSimMS(1000) then self.Sharpness = 0; end end elseif self.PilotHere == false and self.Pilot ~= nil then ToGameActivity(ActivityMan:GetActivity()):AddObjectivePoint("The pilot is not close enough to break off the gun.", self.AboveHUDPos, self.Team, GameActivity.ARROWDOWN); if self.PieTimer:IsPastSimMS(1000) then self.Sharpness = 0; end end elseif (self.Pilot == nil or not MovableMan:IsActor(self.Pilot)) and self ~= nil and MovableMan:IsActor(self) then ToGameActivity(ActivityMan:GetActivity()):AddObjectivePoint("No pilot available to break off gun.", self.AboveHUDPos, self.Team, GameActivity.ARROWDOWN); if self.PieTimer:IsPastSimMS(1000) then self.Sharpness = 0; end end end end function Destroy(self) end