function ZombieDefense:StartActivity()
	print("Zombie Defense Activity Start");
	AudioMan:PlayMusic("Zombie Offense.rte/Dead_Village.ogg", -1, -1);
	self.FightStage = { NOFIGHT = 0, DEFENDING = 1, ATTACK = 2, FIGHTSTAGECOUNT = 3 };
	self.zspawn1 = Timer();
	self.zspawn2 = Timer();
	self.zspawn3 = Timer();
	self.zspawn4 = Timer();
	self.zspawn5 = Timer();
	self.zspawn6 = Timer();
	self.zspawn7 = Timer();
	self.zspawn8 = Timer();
	self.zspawn9 = Timer();
	self.gametime = Timer();
	self.gametime:SetRealTimeLimitS(30);
	self.gameover = 0;
	self.ztime = 5000;
	self.InterruptTimer = Timer();
	self.Interrupt = 0;
	ActivityMan:GetActivity():SetTeamFunds(0,0);
	playerActor = CreateAHuman("Soldier Heavy")
	playerActor.Health = 150
	playerActor.Pos = Vector(2405,805);
	playerActor.Team = 0;
	playerSep = 4
	playerList = {}
	 for player = 0, self.PlayerCount - 1 do
	 playerActor = nil
	playerActor = CreateAHuman("Soldier Heavy")
	playerActor.Health = 150
	playerActor.Pos = Vector(2405 + (player * playerSep ),805);
	playerActor.Team = 0;
	table.insert(playerList,playerActor)
	self:SetPlayerBrain(playerActor, player);
	self:SetLandingZone(playerActor.Pos, player);
	playerActor:AddInventoryItem(CreateHDFirearm("Luger"));
	MovableMan:AddActor(playerActor);
	self:SwitchToActor(playerActor, player, self:GetTeamOfPlayer(player));
	end
	zlist = {"Spewer Thin","Spewer Medium","Spewer Fat"};
	fblist = {"Doom Overlord"};
	mblist = {"Evil Collossus"};
	wlist = {"Vomit Gun"};
	zombiecount = 0;
	zombiecap = 10;
	killcount = 0;
	zdouble = 0;
	dt = 0;
	tt = 0;
	mb = 0;
	mb2 = 0;
	fb = 0;
	dh = 0;
	pickup1 = 0;
	pickup2 = 0;
	pickup3 = 0;
	pickup4 = 0;
	pickup5 = 0;
	pickup6 = 0;
	pickup7 = 0;
	pickup8 = 0;
end
	
function ZombieDefense:PauseActivity()
	print("Zombie Defense Activity Paused");
end

function ZombieDefense:EndActivity()
	print("Zombie Defense GAME OVER");
	self.gameover = 1;
	if self.WinnerTeam == Activity.TEAM_2 then
        FrameMan:ClearScreenText(Activity.PLAYER_1);
		FrameMan:SetScreenText("The ravenous zombies proved too much for the lone survivor... All hope had been lost...", Activity.PLAYER_1, 0, 5000, false);
	end
end

function ZombieDefense:UpdateActivity()
	if MovableMan:IsActor(playerActor) then
		self:SetObservationTarget(playerActor.Pos, Activity.PLAYER_1);
	end
	
	if playerActor.Health == 0 then
		self.WinnerTeam = Activity.TEAM_2;
		ActivityMan:EndActivity();
	end

	if zombiecount < zombiecap then
		if -self.zspawn1:LeftTillSimMS(0) > self.ztime then
			local zombie1 = CreateAHuman(zlist[math.random(#zlist)]);
			zombie1:AddAISceneWaypoint(Vector(3000,playerActor.Pos.Y));
			zombie1.Pos = Vector(400,850);
			zombie1.Team = 1;
			zombie1.AIMode = Actor.AIMODE_GOTO;
			MovableMan:AddActor(zombie1);
			self.zspawn1:Reset();
			zombiecount = zombiecount + 1;
		end
		if -self.zspawn2:LeftTillSimMS(0) > self.ztime then
			local zombie2 = CreateAHuman(zlist[math.random(#zlist)]);
			zombie2:AddAISceneWaypoint(Vector(3000,playerActor.Pos.Y));
			zombie2.Pos = Vector(1200,800);
			zombie2.Team = 1;
			zombie2.AIMode = Actor.AIMODE_GOTO;
			MovableMan:AddActor(zombie2);
			self.zspawn2:Reset();
			zombiecount = zombiecount + 1;
		end
		if -self.zspawn3:LeftTillSimMS(0) > self.ztime then
			local zombie3 = CreateAHuman(zlist[math.random(#zlist)]);
			zombie3:AddAISceneWaypoint(Vector(3000,playerActor.Pos.Y));
			zombie3.Pos = Vector(2000,800);
			zombie3.Team = 1;
			zombie3.AIMode = Actor.AIMODE_GOTO;
			MovableMan:AddActor(zombie3);
			self.zspawn3:Reset();
			zombiecount = zombiecount + 1;
		end
	end
	if zombiecount < zombiecap and zdouble > 0 then
		if -self.zspawn4:LeftTillSimMS(0) > self.ztime then
			local zombie4 = CreateAHuman(zlist[math.random(#zlist)]);
			zombie4:AddAISceneWaypoint(Vector(2475,playerActor.Pos.Y));
			zombie4.Pos = Vector(4900,800);
			zombie4.Team = 1;
			zombie4.AIMode = Actor.AIMODE_GOTO;
			MovableMan:AddActor(zombie4);
			self.zspawn4:Reset();
			zombiecount = zombiecount + 1;
		end
		if -self.zspawn5:LeftTillSimMS(0) > self.ztime then
			local zombie5 = CreateAHuman(zlist[math.random(#zlist)]);
			zombie5:AddAISceneWaypoint(Vector(2475,playerActor.Pos.Y));
			zombie5.Pos = Vector(4100,850);
			zombie5.Team = 1;
			zombie5.AIMode = Actor.AIMODE_GOTO;
			MovableMan:AddActor(zombie5);
			self.zspawn5:Reset();
			zombiecount = zombiecount + 1;
		end
		if -self.zspawn6:LeftTillSimMS(0) > self.ztime then
			local zombie6 = CreateAHuman(zlist[math.random(#zlist)]);
			zombie6:AddAISceneWaypoint(Vector(2475,playerActor.Pos.Y));
			zombie6.Pos = Vector(3300,850);
			zombie6.Team = 1;
			zombie6.AIMode = Actor.AIMODE_GOTO;
			MovableMan:AddActor(zombie6);
			self.zspawn6:Reset();
			zombiecount = zombiecount + 1;
		end
		if -self.zspawn7:LeftTillSimMS(0) > self.ztime and killcount >= 600 then
			local zombie7 = CreateAHuman(zlist[math.random(#zlist)]);
			zombie7:AddAISceneWaypoint(Vector(2497,playerActor.Pos.Y));
			zombie7.Pos = Vector(2475,700);
			zombie7.Team = 1;
			zombie7.AIMode = Actor.AIMODE_GOTO;
			MovableMan:AddActor(zombie7);
			self.zspawn7:Reset();
			zombiecount = zombiecount + 2;
		end
	end
	if killcount >= 400 and mb == 0 then
		if -self.zspawn8:LeftTillSimMS(0) > self.ztime then
			local zombie8 = CreateAHuman(mblist[math.random(#mblist)]);
			zombie8:AddInventoryItem(CreateHDFirearm("Doom Flamer"));
			zombie8:AddAISceneWaypoint(Vector(2475,playerActor.Pos.Y));
			zombie8.Pos = Vector(3300,800);
			zombie8.Team = 1;
			zombie8.AIMode = Actor.AIMODE_GOTO;
			MovableMan:AddActor(zombie8);
			self.zspawn8:Reset();
		end
		if -self.zspawn9:LeftTillSimMS(0) > self.ztime then
			local zombie9 = CreateAHuman(mblist[math.random(#mblist)]);
			zombie9:AddInventoryItem(CreateHDFirearm("Doom Flamer"));
			zombie9:AddAISceneWaypoint(Vector(2475,playerActor.Pos.Y));
			zombie9.Pos = Vector(2000,750);
			zombie9.Team = 1;
			zombie9.AIMode = Actor.AIMODE_GOTO;
			MovableMan:AddActor(zombie9);
			self.zspawn9:Reset();
		end
		mb = 1;
	end
	if killcount >= 900 and mb2 == 0 then
		if -self.zspawn8:LeftTillSimMS(0) > self.ztime then
			local zombie8 = CreateAHuman(mblist[math.random(#mblist)]);
			zombie8:AddInventoryItem(CreateHDFirearm("Doom Flamer"));
			zombie8:AddAISceneWaypoint(Vector(2475,playerActor.Pos.Y));
			zombie8.Pos = Vector(3300,800);
			zombie8.Team = 1;
			zombie8.AIMode = Actor.AIMODE_GOTO;
			MovableMan:AddActor(zombie8);
			self.zspawn8:Reset();
		end
		if -self.zspawn9:LeftTillSimMS(0) > self.ztime then
			local zombie9 = CreateAHuman(mblist[math.random(#mblist)]);
			zombie9:AddInventoryItem(CreateHDFirearm("Doom Flamer"));
			zombie9:AddAISceneWaypoint(Vector(2475,playerActor.Pos.Y));
			zombie9.Pos = Vector(2000,750);
			zombie9.Team = 1;
			zombie9.AIMode = Actor.AIMODE_GOTO;
			MovableMan:AddActor(zombie9);
			self.zspawn9:Reset();
		end
		mb2 = 1;
	end
	if killcount >= 1000 and fb == 0 then
		fb = 1;		
		local finalboss = CreateAHuman(fblist[math.random(#fblist)]);
		finalboss:AddInventoryItem(CreateHDFirearm("Colossal Meteor"));
		finalboss:AddInventoryItem(CreateHDFirearm("Doom Flamer"));
		finalboss:AddAISceneWaypoint(Vector(playerActor.Pos.X,playerActor.Pos.Y));
		finalboss.Pos = Vector(2100,700);
		finalboss.Team = 1;
		finalboss.AIMode = Actor.AIMODE_GOTO;
		finalboss.Health = 1;
		MovableMan:AddActor(finalboss);
	end

	for actor in MovableMan.Actors do
        if SceneMan.Scene:WithinArea("Boundary", actor.Pos) then
			if actor.Team == 0 then
				actor.Vel = actor.Vel * -1;
			end
        end
    end
	
	for item in MovableMan.Items do
		if item.PresetName == "Vomit Gun" then
			item.ToSettle = true;
		end
	end
	
	if killcount == 0 then
		self.Interrupt = 5000;
		self.InterruptTimer:Reset();
		self:ResetMessageTimer(Activity.PLAYER_1);
        FrameMan:ClearScreenText(Activity.PLAYER_1);
		FrameMan:SetScreenText("You are quickly being surrounded. You must kill the zombies in order to survive!", Activity.PLAYER_1, 0, 5000, false);
	end

	if killcount == 1 then
		self.Interrupt = 5000;
		self.InterruptTimer:Reset();
		self:ResetMessageTimer(Activity.PLAYER_1);
        FrameMan:ClearScreenText(Activity.PLAYER_1);
	end

	if killcount >= 25 and pickup1 == 0 then
		i = 1
		while i <= #playerList do 
		playerActor = playerList[i]
		playerActor:AddInventoryItem(CreateHDFirearm("Auto Pistol"));
		playerActor:AddInventoryItem(CreateTDExplosive("Frag Grenade"));
		i = i + 1
		end
		self.Interrupt = 5000;
		self.InterruptTimer:Reset();
		self:ResetMessageTimer(Activity.PLAYER_1);
        FrameMan:ClearScreenText(Activity.PLAYER_1);
		FrameMan:SetScreenText("LEVEL TWO! +1 Frag Grenade! Auto Pistol unlocked!", Activity.PLAYER_1, 0, 5000, false);
		pickup1 = 1;
		zombiecap = 20;
	end

	if killcount >= 50 and pickup2 == 0 then
		i = 1
		while i <= #playerList do 
		playerActor = playerList[i]
		playerActor:AddInventoryItem(CreateHDFirearm("Assault Rifle"));
		i = i + 1
		end
		self.Interrupt = 5000;
		self.InterruptTimer:Reset();
		self:ResetMessageTimer(Activity.PLAYER_1);
        FrameMan:ClearScreenText(Activity.PLAYER_1);
		FrameMan:SetScreenText("LEVEL THREE! Assault Rifle unlocked!", Activity.PLAYER_1, 0, 5000, false);
		pickup2 = 1;
		self.ztime = 4500;
	end
	
	if killcount >= 75 and pickup3 == 0 then
		i = 1
		while i <= #playerList do 
		playerActor = playerList[i]
		playerActor:AddInventoryItem(CreateHDFirearm("Sniper Rifle"));
		playerActor:AddInventoryItem(CreateTDExplosive("Frag Grenade"));
		i = i + 1
		end
		self.Interrupt = 5000;
		self.InterruptTimer:Reset();
		self:ResetMessageTimer(Activity.PLAYER_1);
        FrameMan:ClearScreenText(Activity.PLAYER_1);
		FrameMan:SetScreenText("LEVEL FOUR! +1 Frag Grenades! Sniper Rifle unlocked!", Activity.PLAYER_1, 0, 5000, false);
		pickup3 = 1;
		self.ztime = 4000;
	end
	
	if killcount >= 100 and pickup4 == 0 then
		i = 1
		while i <= #playerList do 
		playerActor = playerList[i]
		playerActor:AddInventoryItem(CreateHeldDevice("Riot Shield"));
		playerActor:AddInventoryItem(CreateHDFirearm("Uzi"));
		i = i + 1
		end
		self.Interrupt = 5000;
		self.InterruptTimer:Reset();
		self:ResetMessageTimer(Activity.PLAYER_1);
        FrameMan:ClearScreenText(Activity.PLAYER_1);
		FrameMan:SetScreenText("LEVEL FIVE! Riot Shield + Uzi unlocked!", Activity.PLAYER_1, 0, 5000, false);
		pickup4 = 1;
		zombiecap = 25;
		self.ztime = 3000;
		if playerActor.Health <= 100 then
			self.Interrupt = 5000;
			self.InterruptTimer:Reset();
			self:ResetMessageTimer(Activity.PLAYER_1);
			FrameMan:ClearScreenText(Activity.PLAYER_1);
			FrameMan:SetScreenText("LEVEL FIVE! Health Bonus! Riot Shield + Uzi unlocked!", Activity.PLAYER_1, 0, 5000, false);
			playerActor.Health = playerActor.Health + 50;
		end
	end
	
	if killcount >= 150 and dt == 0 then
		zdouble = 1;
		self.Interrupt = 5000;
		self.InterruptTimer:Reset();
		self:ResetMessageTimer(Activity.PLAYER_1);
        FrameMan:ClearScreenText(Activity.PLAYER_1);
		FrameMan:SetScreenText("DOUBLE TROUBLE!  ..UH OH! Now they are coming from both sides!! ", Activity.PLAYER_1, 0, 5000, false);
		dt = 1;
	end

	if killcount >= 200 and pickup5 == 0 then
		i = 1
		while i <= #playerList do 
		playerActor = playerList[i]
		playerActor:AddInventoryItem(CreateHDFirearm("Flamer"));
		i = i + 1
		end
		self.Interrupt = 5000;
		self.InterruptTimer:Reset();
		self:ResetMessageTimer(Activity.PLAYER_1);
        FrameMan:ClearScreenText(Activity.PLAYER_1);
		FrameMan:SetScreenText("LEVEL SIX! Flamer unlocked!", Activity.PLAYER_1, 0, 5000, false);
		pickup5 = 1;
		self.ztime = 2500;
	end
	
	if killcount >= 300 and pickup6 == 0 then
		i = 1
		while i <= #playerList do 
		playerActor = playerList[i]
		playerActor:AddInventoryItem(CreateHDFirearm("Spaz1200"));
		playerActor:AddInventoryItem(CreateTDExplosive("Pineapple Grenade"));
		i = i + 1
		end
		self.Interrupt = 5000;
		self.InterruptTimer:Reset();
		self:ResetMessageTimer(Activity.PLAYER_1);
        FrameMan:ClearScreenText(Activity.PLAYER_1);
		FrameMan:SetScreenText("LEVEL SEVEN! +1 Pineapple Grenade! Spaz1200 unlocked!", Activity.PLAYER_1, 0, 5000, false);
		pickup6 = 1;
		zombiecap = 30;
		self.ztime = 2000;
	end

	if killcount == 400 then
		self.Interrupt = 5000;
		self.InterruptTimer:Reset();
		self:ResetMessageTimer(Activity.PLAYER_1);
        FrameMan:ClearScreenText(Activity.PLAYER_1);
		FrameMan:SetScreenText("Uh oh! Stronger zombies are approaching!!", Activity.PLAYER_1, 0, 5000, false);
	end
	
	if killcount >= 500 and pickup7 == 0 then
		i = 1
		while i <= #playerList do 
		playerActor = playerList[i]
		playerActor:AddInventoryItem(CreateHDFirearm("RPC M17"));
		playerActor:AddInventoryItem(CreateTDExplosive("Pineapple Grenade"));
		i = i + 1
		end
		self.Interrupt = 5000;
		self.InterruptTimer:Reset();
		self:ResetMessageTimer(Activity.PLAYER_1);
        FrameMan:ClearScreenText(Activity.PLAYER_1);
		FrameMan:SetScreenText("LEVEL EIGHT! +1 Pineapple Grenade! RPC M17 unlocked!", Activity.PLAYER_1, 0, 5000, false);
		pickup7 = 1;
		self.ztime = 1500;
		i = 1
		while i <= #playerList do 
		playerActor = playerList[i]
		if playerActor.Health <= 100 then
			self.Interrupt = 5000;
			self.InterruptTimer:Reset();
			self:ResetMessageTimer(Activity.PLAYER_1);
			FrameMan:ClearScreenText(Activity.PLAYER_1);
			FrameMan:SetScreenText("LEVEL EIGHT! Health Bonus! +1 Pineapple Grenade! RPC M17 unlocked!", Activity.PLAYER_1, 0, 5000, false);
			playerActor.Health = playerActor.Health + 50;
		end
		i = i + 1
		end
	end
	
	if killcount >= 600 and tt == 0 then
		self.Interrupt = 5000;
		self.InterruptTimer:Reset();
		self:ResetMessageTimer(Activity.PLAYER_1);
        FrameMan:ClearScreenText(Activity.PLAYER_1);
		FrameMan:SetScreenText("Oh no! Now they're coming from everywhere!", Activity.PLAYER_1, 0, 5000, false);
		tt = 1;
	end

	if killcount >= 700 and dh == 0 then
		self.Interrupt = 5000;
		self.InterruptTimer:Reset();
		self:ResetMessageTimer(Activity.PLAYER_1);
        FrameMan:ClearScreenText(Activity.PLAYER_1);
		FrameMan:SetScreenText("POWER UP! D-D-D-DOUBLE HEALTH!", Activity.PLAYER_1, 0, 5000, false);
		i = 1
		while i <= #playerList do 
		playerActor = playerList[i]
		playerActor.Health = playerActor.Health * 2;
		i = i + 1
		end
		dh = 1;
	end

	if killcount >= 800 and pickup8 == 0 then
		i = 1
		while i <= #playerList do 
		playerActor = playerList[i]
		playerActor:AddInventoryItem(CreateHDFirearm("Gatling Gun"));
		playerActor:AddInventoryItem(CreateTDExplosive("Pineapple Grenade"));
		i = i + 1
		end
		self.Interrupt = 5000;
		self.InterruptTimer:Reset();
		self:ResetMessageTimer(Activity.PLAYER_1);
        FrameMan:ClearScreenText(Activity.PLAYER_1);
		FrameMan:SetScreenText("LEVEL NINE! +1 Pineapple Grenade! Gatling gun unlocked!", Activity.PLAYER_1, 0, 5000, false);
		pickup8 = 1;
		self.ztime = 1000;
		zombiecap = 35;
	end

	if killcount == 900 then
		self.Interrupt = 5000;
		self.InterruptTimer:Reset();
		self:ResetMessageTimer(Activity.PLAYER_1);
        FrameMan:ClearScreenText(Activity.PLAYER_1);
		FrameMan:SetScreenText("Uh oh! Stronger zombies are approaching!!", Activity.PLAYER_1, 0, 5000, false);
	end

	if killcount >= 1000 and zombiecap >= 10 then
		self.Interrupt = 5000;
		self.InterruptTimer:Reset();
		self:ResetMessageTimer(Activity.PLAYER_1);
        FrameMan:ClearScreenText(Activity.PLAYER_1);
		FrameMan:SetScreenText("Watch out! You've angered their mother!!", Activity.PLAYER_1, 0, 5000, false);
		zombiecap = 0;
	end

	if finalboss ~= nil and finalboss.Health == 0 then
		self.WinnerTeam = Activity.TEAM_1;
		ActivityMan:EndActivity();
        FrameMan:ClearScreenText(Activity.PLAYER_1);
		FrameMan:SetScreenText("Congrats, you made it to safety! You win!", Activity.PLAYER_1, 0, 5000, false);
	end
		i = 1
		achivementgranted = false
		while i <= #playerList do 
		playerActor = playerList[i]
		if playerActor.Health >= 150 then
		achivementgranted = true
		end
		i = i + 1
		end
	if finalboss ~= nil and finalboss.Health == 0 and achivementgranted then
		self.WinnerTeam = Activity.TEAM_1;
		ActivityMan:EndActivity();
		        FrameMan:ClearScreenText(Activity.PLAYER_1);
		FrameMan:SetScreenText("ACHIEVEMENT UNLOCKED!!!: Piece Of Cake", Activity.PLAYER_1, 0, 5000, false);
	end
end
	