View unanswered posts | View active topics It is currently Fri Apr 19, 2024 6:59 am



Reply to topic  [ 2 posts ] 
 Custom game mode help. 
Author Message

Joined: Mon Dec 07, 2009 12:56 am
Posts: 36
Reply with quote
Post Custom game mode help.
Hey guys I'm attempting to make a custom version of the one man army activities. Using Mehman's tank as the player, and giving the enemy some more heavy weapons to deal with it. It spawns the tank, and if it dies the game keeps going, than theres nothing but camera control than, not even the buy menu. Plus enemys no longer spawn, and the survival timer is gone. I suck at Lua and I keep going over the code and can't find anything wrong. If someone would be kind enough to look it over and help me correct it, I would appreciate it. :)

Code:
function TankVSArmy:StartActivity()
   -- Check if we already have a brain assigned
   for player = Activity.PLAYER_1, Activity.MAXPLAYERCOUNT - 1 do
      if self:PlayerActive(player) and self:PlayerHuman(player) then
         if not self:GetPlayerBrain(player) then
            local foundBrain = MovableMan:GetUnassignedBrain(self:GetTeamOfPlayer(player))
            -- If we can't find an unassigned brain in the scene to give the player, then force to go into editing mode to place one
            if not foundBrain then
               foundBrain = CreateACrab("Multi Purpuse Medium Tank")
               foundBrain.Pos = SceneMan:MovePointToGround(Vector(math.random(0, SceneMan.SceneWidth), 0), 0, 0) + Vector(0, -50)
               foundBrain.Team = self:GetTeamOfPlayer(player)
               MovableMan:AddActor(foundBrain)
               -- Set the found brain to be the selected actor at start
               self:SetPlayerBrain(foundBrain, player)
               self:SwitchToActor(foundBrain, player, self:GetTeamOfPlayer(player))
               self:SetLandingZone(self:GetPlayerBrain(player).Pos, player)
               -- Set the observation target to the brain, so that if/when it dies, the view flies to it in observation mode
               self:SetObservationTarget(self:GetPlayerBrain(player).Pos, player)
            else
               -- Set the found brain to be the selected actor at start
               self:SetPlayerBrain(foundBrain, player)
               self:SwitchToActor(foundBrain, player, self:GetTeamOfPlayer(player))
               self:SetLandingZone(self:GetPlayerBrain(player).Pos, player)
               -- Set the observation target to the brain, so that if/when it dies, the view flies to it in observation mode
               self:SetObservationTarget(self:GetPlayerBrain(player).Pos, player)
            end
         end
      end
   end
   
    self.factionA = "Coalition.rte";
    self.factionAActorList = {"Soldier Light", "Soldier Heavy"};
    self.factionACrabList = {"Gatling Drone"};
    self.factionAPrimaryWeaponList = {"Compact Assault Rifle", "Assault Rifle", "Shotgun", "Auto Shotgun", "Breaker-GL", "Gatling Gun", "Sniper Rifle", "Heavy Sniper Rifle", "Flamer", "Auto Cannon", "Revolver Cannon", "Flak Cannon", "Missile Launcher", "Uber Cannon"};
    self.factionASecondaryWeaponList = {"Pistol", "Auto Pistol", "Heavy Pistol"};

    self.factionB = "Dummy.rte";
    self.factionBActorList = {"Dummy"};
    self.factionBCrabList = {"Dreadnought"};
    self.factionBPrimaryWeaponList = {"Blaster", "Nailer Cannon", "Scouting Rifle", "Impulse Cannon", "Repeater", "Destroyer Cannon", "Annihiliator"};
    self.factionBSecondaryWeaponList = {"Nailgun", "Rail Pistol"};

    self.factionC = "Ronin.rte";
    self.factionCActorList = {"Dafred", "Mia", "Dimitri", "Brutus", "Sandra", "Gordon"};
    self.factionCCrabList = {};
    self.factionCPrimaryWeaponList = {"AK-47", "M16", "Shortgun", "Pumpgun", "Spas 12", "Kar98", "M1 Garand", "M60", "Thumper", "RPG-7"};
    self.factionCSecondaryWeaponList = {"Glock", "Desert Eagle", "Peacemaker", "Uzi"};


    self.moduleList = {self.factionA, self.factionB, self.factionC};
    self.actorList = {self.factionAActorList, self.factionBActorList, self.factionCActorList};
    self.crabList = {self.factionACrabList, self.factionBCrabList, self.factionCCrabList};
    self.primaryWeaponList = {self.factionAPrimaryWeaponList, self.factionBPrimaryWeaponList, self.factionCPrimaryWeaponList};
    self.secondaryWeaponList = {self.factionASecondaryWeaponList, self.factionBSecondaryWeaponList, self.factionCSecondaryWeaponList};

   self.ESpawnTimer = Timer()
   self.LZ = SceneMan.Scene:GetArea("LZ Team 1")
   self.EnemyLZ = SceneMan.Scene:GetArea("LZ All")
   self.SurvivalTimer = Timer()
   
   if self.Difficulty <= GameActivity.CAKEDIFFICULTY then
      self.TimeLimit = 60000+5000
      self.timeDisplay = "one minute"
      self.BaseSpawnTime = 6000
      self.RandomSpawnTime = 8000
   elseif self.Difficulty <= GameActivity.EASYDIFFICULTY then
      self.TimeLimit = 1.5*60000+5000
      self.timeDisplay = "one minute and thirty seconds"
      self.BaseSpawnTime = 5500
      self.RandomSpawnTime = 7000
   elseif self.Difficulty <= GameActivity.MEDIUMDIFFICULTY then
      self.TimeLimit = 2*60000+5000
      self.timeDisplay = "two minutes"
      self.BaseSpawnTime = 5000
      self.RandomSpawnTime = 6000
   elseif self.Difficulty <= GameActivity.HARDDIFFICULTY then
      self.TimeLimit = 3*60000+5000
      self.timeDisplay = "three minutes"
      self.BaseSpawnTime = 4500
      self.RandomSpawnTime = 5000
   elseif self.Difficulty <= GameActivity.NUTSDIFFICULTY then
      self.TimeLimit = 5*60000+5000
      self.timeDisplay = "five minutes"
      self.BaseSpawnTime = 4000
      self.RandomSpawnTime = 4500
   elseif self.Difficulty <= GameActivity.MAXDIFFICULTY then
      self.TimeLimit = 10*60000+5000
      self.timeDisplay = "ten minutes"
      self.BaseSpawnTime = 3500
      self.RandomSpawnTime = 4000
   end

   self.StartTimer = Timer()
   ActivityMan:GetActivity():SetTeamFunds(0,Activity.TEAM_1)
   ActivityMan:GetActivity():SetTeamFunds(0,Activity.TEAM_2)
   ActivityMan:GetActivity():SetTeamFunds(0,Activity.TEAM_3)
   ActivityMan:GetActivity():SetTeamFunds(0,Activity.TEAM_4)
   
   self.TimeLeft = self.BaseSpawnTime + math.random(self.RandomSpawnTime)
end

function OneManArmy:UpdateActivity()
   if self.ActivityState ~= Activity.OVER then
      ActivityMan:GetActivity():SetTeamFunds(0,0)
      for player = Activity.PLAYER_1, Activity.MAXPLAYERCOUNT - 1 do
         if self:PlayerActive(player) and self:PlayerHuman(player) then
            --Display messages.
            if self.StartTimer:IsPastSimMS(3000) then
               FrameMan:SetScreenText(math.floor(self.SurvivalTimer:LeftTillSimMS(self.TimeLimit) / 1000) .. " seconds left", player, 0, 1000, false)
            else
               FrameMan:SetScreenText("Survive for " .. self.timeDisplay .. "!", player, 333, 5000, true)
            end
         
            -- The current player's team
            local team = self:GetTeamOfPlayer(player)
            -- Check if any player's brain is dead
            if not MovableMan:IsActor(self:GetPlayerBrain(player)) then
               self:SetPlayerBrain(nil, player)
               self:ResetMessageTimer(player)
               FrameMan:ClearScreenText(player)
               FrameMan:SetScreenText("Your brain has been destroyed!", player, 333, -1, false)
               -- Now see if all brains of self player's team are dead, and if so, end the game
               if not MovableMan:GetFirstBrainActor(team) then
                  self.WinnerTeam = self:OtherTeam(team)
                  ActivityMan:EndActivity()
               end
            else
               self.HuntPlayer = player
            end
            
            --Check if the player has won.
            if self.SurvivalTimer:IsPastSimMS(self.TimeLimit) then
               self:ResetMessageTimer(player)
               FrameMan:ClearScreenText(player)
               FrameMan:SetScreenText("You survived!", player, 333, -1, false)
               
               self.WinnerTeam = player
               
               --Kill all enemies.
               for actor in MovableMan.Actors do
                  if actor.Team ~= self.WinnerTeam then
                     actor.Health = 0
                  end
               end

               ActivityMan:EndActivity()
            end
         end
      end

      --Spawn the AI.
      if self.HuntPlayer ~= nil and self.ESpawnTimer:LeftTillSimMS(self.TimeLeft) <= 0 and MovableMan:GetMOIDCount() <= 210 then
         local actor = {}
         for x = 0, math.ceil(math.random(3)) do

                local factionPick = math.ceil(math.random()*#self.moduleList);
                if #self.crabList[factionPick] > 0 then
                    if math.random() > 0.05 then
                        actor[x] = CreateAHuman(self.actorList[factionPick][math.ceil(math.random()*#self.actorList[factionPick])],self.moduleList[factionPick]);
                        actor[x]:AddInventoryItem(CreateHDFirearm(  self.primaryWeaponList[factionPick][math.ceil(math.random()*#self.primaryWeaponList[factionPick])]  ,self.moduleList[factionPick]));
                        actor[x]:AddInventoryItem(CreateHDFirearm(  self.secondaryWeaponList[factionPick][math.ceil(math.random()*#self.secondaryWeaponList[factionPick])]  ,self.moduleList[factionPick]));
                        actor[x]:AddInventoryItem(CreateHDFirearm("Medium Digger"));
                        actor[x].AIMode = Actor.AIMODE_BRAINHUNT;
                        actor[x].Team = self.CPUTeam;
                    else
                        actor[x] = CreateACrab(self.crabList[factionPick][math.ceil(math.random()*#self.crabList[factionPick])],self.moduleList[factionPick]);
                        actor[x].AIMode = Actor.AIMODE_BRAINHUNT;
                        actor[x].Team = self.CPUTeam;
                        break;
                    end
                else
                    actor[x] = CreateAHuman(self.actorList[factionPick][math.ceil(math.random()*#self.actorList[factionPick])],self.moduleList[factionPick]);
                    actor[x]:AddInventoryItem(CreateHDFirearm(  self.primaryWeaponList[factionPick][math.ceil(math.random()*#self.primaryWeaponList[factionPick])]  ,self.moduleList[factionPick]));
                    actor[x]:AddInventoryItem(CreateHDFirearm(  self.secondaryWeaponList[factionPick][math.ceil(math.random()*#self.secondaryWeaponList[factionPick])]  ,self.moduleList[factionPick]));
                    actor[x]:AddInventoryItem(CreateHDFirearm("Medium Digger"));
                    actor[x].AIMode = Actor.AIMODE_BRAINHUNT;
                    actor[x].Team = self.CPUTeam;
                end

         end
         local ship = nil
         local z = math.random()

      if z > 0.1 then
         if math.random() > 0.3 then
            ship = CreateACDropShip("Drop Ship MK1","Coalition.rte");
         else
            ship = CreateACDropShip("Drop Ship","Dummy.rte");
         end
      else
         ship = CreateACRocket("Rocket MK2","Coalition.rte");
      end

         for n = 0, #actor do
            ship:AddInventoryItem(actor[n])
         end
         ship.Team = 1
         local w = math.random()
         if w > 0.5 then
            ship.Pos = Vector(self.EnemyLZ:GetRandomPoint().X,-50)
         else
            ship.Pos = Vector(self.LZ:GetRandomPoint().X,-50)
         end
         MovableMan:AddActor(ship)
         self.ESpawnTimer:Reset()
         self.TimeLeft = self.BaseSpawnTime + math.random(self.RandomSpawnTime)
      end
   end
end


Mon Dec 12, 2011 9:12 am
Profile

Joined: Mon Dec 07, 2009 12:56 am
Posts: 36
Reply with quote
Post Re: Custom game mode help.
It's fixed now. In case anyone is wondering here is the correct code.

Code:
function OneManArmy:StartActivity()
   -- Check if we already have a brain assigned
   for player = Activity.PLAYER_1, Activity.MAXPLAYERCOUNT - 1 do
      if self:PlayerActive(player) and self:PlayerHuman(player) then
         if not self:GetPlayerBrain(player) then
            local foundBrain = MovableMan:GetUnassignedBrain(self:GetTeamOfPlayer(player))
            -- If we can't find an unassigned brain in the scene to give the player, then force to go into editing mode to place one
            if not foundBrain then
               foundBrain = CreateACrab("Multi Purpuse Medium Tank" , "Tank.rte")
               foundBrain.Pos = SceneMan:MovePointToGround(Vector(math.random(0, SceneMan.SceneWidth), 0), 0, 0) + Vector(0, -50)
               foundBrain.Team = self:GetTeamOfPlayer(player)
               MovableMan:AddActor(foundBrain)
               -- Set the found brain to be the selected actor at start
               self:SetPlayerBrain(foundBrain, player)
               self:SwitchToActor(foundBrain, player, self:GetTeamOfPlayer(player))
               self:SetLandingZone(self:GetPlayerBrain(player).Pos, player)
               -- Set the observation target to the brain, so that if/when it dies, the view flies to it in observation mode
               self:SetObservationTarget(self:GetPlayerBrain(player).Pos, player)
            else
               -- Set the found brain to be the selected actor at start
               self:SetPlayerBrain(foundBrain, player)
               self:SwitchToActor(foundBrain, player, self:GetTeamOfPlayer(player))
               self:SetLandingZone(self:GetPlayerBrain(player).Pos, player)
               -- Set the observation target to the brain, so that if/when it dies, the view flies to it in observation mode
               self:SetObservationTarget(self:GetPlayerBrain(player).Pos, player)
            end
         end
      end
   end
   
    self.factionA = "Coalition.rte";
    self.factionAActorList = {"Soldier Light", "Soldier Heavy"};
    self.factionACrabList = {"Gatling Drone"};
    self.factionAPrimaryWeaponList = {"Compact Assault Rifle", "Assault Rifle", "Shotgun", "Auto Shotgun", "Breaker-GL", "Gatling Gun", "Sniper Rifle", "Heavy Sniper Rifle", "Flamer", "Auto Cannon", "Revolver Cannon", "Flak Cannon", "Missile Launcher", "Uber Cannon"};
    self.factionASecondaryWeaponList = {"Pistol", "Auto Pistol", "Heavy Pistol"};

    self.factionB = "Dummy.rte";
    self.factionBActorList = {"Dummy"};
    self.factionBCrabList = {"Dreadnought"};
    self.factionBPrimaryWeaponList = {"Blaster", "Nailer Cannon", "Scouting Rifle", "Impulse Cannon", "Repeater", "Destroyer Cannon", "Annihiliator"};
    self.factionBSecondaryWeaponList = {"Nailgun", "Rail Pistol"};

    self.factionC = "Ronin.rte";
    self.factionCActorList = {"Dafred", "Mia", "Dimitri", "Brutus", "Sandra", "Gordon"};
    self.factionCCrabList = {};
    self.factionCPrimaryWeaponList = {"AK-47", "M16", "Shortgun", "Pumpgun", "Spas 12", "Kar98", "M1 Garand", "M60", "Thumper", "RPG-7", "RPC M17"};
    self.factionCSecondaryWeaponList = {"Glock", "Desert Eagle", "Peacemaker", "Uzi"};


    self.moduleList = {self.factionA, self.factionB, self.factionC};
    self.actorList = {self.factionAActorList, self.factionBActorList, self.factionCActorList};
    self.crabList = {self.factionACrabList, self.factionBCrabList, self.factionCCrabList};
    self.primaryWeaponList = {self.factionAPrimaryWeaponList, self.factionBPrimaryWeaponList, self.factionCPrimaryWeaponList};
    self.secondaryWeaponList = {self.factionASecondaryWeaponList, self.factionBSecondaryWeaponList, self.factionCSecondaryWeaponList};

   self.ESpawnTimer = Timer()
   self.LZ = SceneMan.Scene:GetArea("LZ Team 1")
   self.EnemyLZ = SceneMan.Scene:GetArea("LZ All")
   self.SurvivalTimer = Timer()
   
   if self.Difficulty <= GameActivity.CAKEDIFFICULTY then
      self.TimeLimit = 120000+5000
      self.timeDisplay = "two minutes"
      self.BaseSpawnTime = 6000
      self.RandomSpawnTime = 8000
   elseif self.Difficulty <= GameActivity.EASYDIFFICULTY then
      self.TimeLimit = 1.5*120000+5000
      self.timeDisplay = "three minutes"
      self.BaseSpawnTime = 5500
      self.RandomSpawnTime = 7000
   elseif self.Difficulty <= GameActivity.MEDIUMDIFFICULTY then
      self.TimeLimit = 2*120000+5000
      self.timeDisplay = "four minutes"
      self.BaseSpawnTime = 5000
      self.RandomSpawnTime = 6000
   elseif self.Difficulty <= GameActivity.HARDDIFFICULTY then
      self.TimeLimit = 3*120000+5000
      self.timeDisplay = "six minutes"
      self.BaseSpawnTime = 4500
      self.RandomSpawnTime = 5000
   elseif self.Difficulty <= GameActivity.NUTSDIFFICULTY then
      self.TimeLimit = 5*120000+5000
      self.timeDisplay = "ten minutes"
      self.BaseSpawnTime = 4000
      self.RandomSpawnTime = 4500
   elseif self.Difficulty <= GameActivity.MAXDIFFICULTY then
      self.TimeLimit = 10*120000+5000
      self.timeDisplay = "twenty minutes"
      self.BaseSpawnTime = 3500
      self.RandomSpawnTime = 4000
   end

   self.StartTimer = Timer()
   ActivityMan:GetActivity():SetTeamFunds(0,Activity.TEAM_1)
   ActivityMan:GetActivity():SetTeamFunds(0,Activity.TEAM_2)
   ActivityMan:GetActivity():SetTeamFunds(0,Activity.TEAM_3)
   ActivityMan:GetActivity():SetTeamFunds(0,Activity.TEAM_4)
   
   self.TimeLeft = self.BaseSpawnTime + math.random(self.RandomSpawnTime)
end

function OneManArmy:UpdateActivity()
   if self.ActivityState ~= Activity.OVER then
      ActivityMan:GetActivity():SetTeamFunds(0,0)
      for player = Activity.PLAYER_1, Activity.MAXPLAYERCOUNT - 1 do
         if self:PlayerActive(player) and self:PlayerHuman(player) then
            --Display messages.
            if self.StartTimer:IsPastSimMS(3000) then
               FrameMan:SetScreenText(math.floor(self.SurvivalTimer:LeftTillSimMS(self.TimeLimit) / 1000) .. " seconds left", player, 0, 1000, false)
            else
               FrameMan:SetScreenText("Survive for " .. self.timeDisplay .. "!", player, 333, 5000, true)
            end
         
            -- The current player's team
            local team = self:GetTeamOfPlayer(player)
            -- Check if any player's brain is dead
            if not MovableMan:IsActor(self:GetPlayerBrain(player)) then
            --if not MovableMan:IsActor(
               self:SetPlayerBrain(nil, player)
               self:ResetMessageTimer(player)
               FrameMan:ClearScreenText(player)
               FrameMan:SetScreenText("Your brain has been destroyed!", player, 333, -1, false)
               -- Now see if all brains of self player's team are dead, and if so, end the game
               if not MovableMan:GetFirstBrainActor(team) then
                  self.WinnerTeam = self:OtherTeam(team)
                  ActivityMan:EndActivity()
               end
            else
               self.HuntPlayer = player
            end
            
            --Check if the player has won.
            if self.SurvivalTimer:IsPastSimMS(self.TimeLimit) then
               self:ResetMessageTimer(player)
               FrameMan:ClearScreenText(player)
               FrameMan:SetScreenText("You survived!", player, 333, -1, false)
               
               self.WinnerTeam = player
               
               --Kill all enemies.
               for actor in MovableMan.Actors do
                  if actor.Team ~= self.WinnerTeam then
                     actor.Health = 0
                  end
               end

               ActivityMan:EndActivity()
            end
         end
      end

      --Spawn the AI.
      if self.HuntPlayer ~= nil and self.ESpawnTimer:LeftTillSimMS(self.TimeLeft) <= 0 and MovableMan:GetMOIDCount() <= 210 then
         local actor = {}
         for x = 0, math.ceil(math.random(3)) do

                local factionPick = math.ceil(math.random()*#self.moduleList);
                if #self.crabList[factionPick] > 0 then
                    if math.random() > 0.05 then
                        actor[x] = CreateAHuman(self.actorList[factionPick][math.ceil(math.random()*#self.actorList[factionPick])],self.moduleList[factionPick]);
                        actor[x]:AddInventoryItem(CreateHDFirearm(  self.primaryWeaponList[factionPick][math.ceil(math.random()*#self.primaryWeaponList[factionPick])]  ,self.moduleList[factionPick]));
                        actor[x]:AddInventoryItem(CreateHDFirearm(  self.secondaryWeaponList[factionPick][math.ceil(math.random()*#self.secondaryWeaponList[factionPick])]  ,self.moduleList[factionPick]));
                        actor[x]:AddInventoryItem(CreateHDFirearm("Medium Digger"));
                        actor[x].AIMode = Actor.AIMODE_BRAINHUNT;
                        actor[x].Team = self.CPUTeam;
                    else
                        actor[x] = CreateACrab(self.crabList[factionPick][math.ceil(math.random()*#self.crabList[factionPick])],self.moduleList[factionPick]);
                        actor[x].AIMode = Actor.AIMODE_BRAINHUNT;
                        actor[x].Team = self.CPUTeam;
                        break;
                    end
                else
                    actor[x] = CreateAHuman(self.actorList[factionPick][math.ceil(math.random()*#self.actorList[factionPick])],self.moduleList[factionPick]);
                    actor[x]:AddInventoryItem(CreateHDFirearm(  self.primaryWeaponList[factionPick][math.ceil(math.random()*#self.primaryWeaponList[factionPick])]  ,self.moduleList[factionPick]));
                    actor[x]:AddInventoryItem(CreateHDFirearm(  self.secondaryWeaponList[factionPick][math.ceil(math.random()*#self.secondaryWeaponList[factionPick])]  ,self.moduleList[factionPick]));
                    actor[x]:AddInventoryItem(CreateHDFirearm("Medium Digger"));
                    actor[x].AIMode = Actor.AIMODE_BRAINHUNT;
                    actor[x].Team = self.CPUTeam;
                end

         end
         local ship = nil
         local z = math.random()

      if z > 0.1 then
         if math.random() > 0.3 then
            ship = CreateACDropShip("Drop Ship MK1","Coalition.rte");
         else
            ship = CreateACDropShip("Drop Ship","Dummy.rte");
         end
      else
         ship = CreateACRocket("Rocket MK2","Coalition.rte");
      end

         for n = 0, #actor do
            ship:AddInventoryItem(actor[n])
         end
         ship.Team = 1
         local w = math.random()
         if w > 0.5 then
            ship.Pos = Vector(self.EnemyLZ:GetRandomPoint().X,-50)
         else
            ship.Pos = Vector(self.LZ:GetRandomPoint().X,-50)
         end
         MovableMan:AddActor(ship)
         self.ESpawnTimer:Reset()
         self.TimeLeft = self.BaseSpawnTime + math.random(self.RandomSpawnTime)
      end
   end
end


Wed Jan 04, 2012 10:05 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.110s | 15 Queries | GZIP : Off ]