function SoccerMission:StartActivity() timelimit = true --Set to false if you wish to play with only the goal limit timeleft = 999 maxtime = 1200 --20 minutes, Amount of time until the match is over timelimittimer = Timer() goallimit = true --Set to false if you wish to play with only the time limit maxgoals = 40 --Amount of goals until game ends respawntime = 1000 --milliseconds bonustimer = Timer() bonusrespawn = 61000 --61 seconds, Amount of time until bonus is available again p1score = 0 p2score = 0 p1spawnactive = false p2spawnactive = false p1spawntimer = Timer() p2spawntimer = Timer() p1scorearea = SceneMan.Scene:GetArea("P1ScoreArea") p2scorearea = SceneMan.Scene:GetArea("P2ScoreArea") p1spawnarea1 = SceneMan.Scene:GetArea("P1Spawn1") p1spawnarea2 = SceneMan.Scene:GetArea("P1Spawn2") p1spawnarea3 = SceneMan.Scene:GetArea("P1Spawn3") p2spawnarea1 = SceneMan.Scene:GetArea("P2Spawn1") p2spawnarea2 = SceneMan.Scene:GetArea("P2Spawn2") p2spawnarea3 = SceneMan.Scene:GetArea("P2Spawn3") --[[ Required areas: BonusArea P1ScoreArea P1Spawn1 P1Spawn2 P1Spawn3 P1BonusSpawn P1GibZone P2ScoreArea P2Spawn1 P2Spawn2 P2Spawn3 P2BonusSpawn P2GibZone P1GiveWeapon1 P1GiveWeapon2 P1GiveWeapon3 P1GiveWeapon4 P1GiveWeapon5 P1GiveWeapon6 P2GiveWeapon1 P2GiveWeapon2 P2GiveWeapon3 P2GiveWeapon4 P2GiveWeapon5 P2GiveWeapon6 --]] --Need brainz for player = 0, self.PlayerCount - 1 do -- Check if we already have a brain assigned 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 each player, then force to go into editing mode to place one if not foundBrain then self.ActivityState = Activity.EDITING; print("Can't find player brain for tutorial game mode, forcing player to place one manually in edit mode!"); 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 ActivityMan:GetActivity():SetTeamFunds(0,0) ActivityMan:GetActivity():SetTeamFunds(0,1) end function SoccerMission:UpdateActivity() --Check scoring areas and update player count --Single loop through actors means each actor is only accessed once. There shouldn't be any other "for actor in MovableMan" etc. team1count = 0 team2count = 0 for actor in MovableMan.Actors do if(SceneMan.Scene:WithinArea("P1ScoreArea",actor.Pos) and actor.Team == Activity.TEAM_1) then p1score = p1score + 1 actor:GibThis() elseif(SceneMan.Scene:WithinArea("P2ScoreArea",actor.Pos) and actor.Team == Activity.TEAM_2) then p2score = p2score + 1 actor:GibThis() else if(actor.Team == Activity.TEAM_1) then team1count = team1count + 1 elseif(actor.Team == Activity.TEAM_2) then team2count = team2count + 1 end end if(SceneMan.Scene:WithinArea("P1GibZone",actor.Pos) and actor.Team == Activity.TEAM_1) then actor:GibThis() elseif(SceneMan.Scene:WithinArea("P2GibZone",actor.Pos) and actor.Team == Activity.TEAM_2) then actor:GibThis() end if(true or actor:IsInventoryEmpty()) then --Give upgrade weapons if(actor.Team == Activity.TEAM_1) then if(p1score >= 1 and SceneMan.Scene:WithinArea("P1GiveWeapon1",actor.Pos)) and not(actor:HasObject("M1911")) then actor:AddInventoryItem(CreateHDFirearm("M1911","KloneSoccer.rte")) elseif(p1score >= 3 and SceneMan.Scene:WithinArea("P1GiveWeapon2",actor.Pos)) and not(actor:HasObject("Flechette Gun")) then actor:AddInventoryItem(CreateHDFirearm("Flechette Gun","KloneSoccer.rte")) elseif(p1score >= 6 and SceneMan.Scene:WithinArea("P1GiveWeapon3",actor.Pos)) and not(actor:HasObject("Sniper")) then actor:AddInventoryItem(CreateHDFirearm("Sniper","KloneSoccer.rte")) elseif(p1score >= 9 and SceneMan.Scene:WithinArea("P1GiveWeapon4",actor.Pos)) and not(actor:HasObject("M249")) then actor:AddInventoryItem(CreateHDFirearm("M249","KloneSoccer.rte")) elseif(p1score >= 12 and SceneMan.Scene:WithinArea("P1GiveWeapon5",actor.Pos)) and not(actor:HasObject("Autocannon")) then actor:AddInventoryItem(CreateHDFirearm("Autocannon","KloneSoccer.rte")) elseif(p1score >= 20 and SceneMan.Scene:WithinArea("P1GiveWeapon6",actor.Pos)) and not(actor:HasObject("Mortar")) then actor:AddInventoryItem(CreateHDFirearm("Mortar","KloneSoccer.rte")) end elseif(actor.Team == Activity.TEAM_2) then if(p2score >= 1 and SceneMan.Scene:WithinArea("P2GiveWeapon1",actor.Pos)) and not(actor:HasObject("M1911")) then actor:AddInventoryItem(CreateHDFirearm("M1911","KloneSoccer.rte")) elseif(p2score >= 3 and SceneMan.Scene:WithinArea("P2GiveWeapon2",actor.Pos)) and not(actor:HasObject("Flechette Gun")) then actor:AddInventoryItem(CreateHDFirearm("Flechette Gun","KloneSoccer.rte")) elseif(p2score >= 6 and SceneMan.Scene:WithinArea("P2GiveWeapon3",actor.Pos)) and not(actor:HasObject("Sniper")) then actor:AddInventoryItem(CreateHDFirearm("Sniper","KloneSoccer.rte")) elseif(p2score >= 9 and SceneMan.Scene:WithinArea("P2GiveWeapon4",actor.Pos)) and not(actor:HasObject("M249")) then actor:AddInventoryItem(CreateHDFirearm("M249","KloneSoccer.rte")) elseif(p2score >= 12 and SceneMan.Scene:WithinArea("P2GiveWeapon5",actor.Pos)) and not(actor:HasObject("Autocannon")) then actor:AddInventoryItem(CreateHDFirearm("Autocannon","KloneSoccer.rte")) elseif(p2score >= 20 and SceneMan.Scene:WithinArea("P2GiveWeapon6",actor.Pos)) and not(actor:HasObject("Mortar")) then actor:AddInventoryItem(CreateHDFirearm("Mortar","KloneSoccer.rte")) end end end p1area1open = true p1area2open = true p1area3open = true if(SceneMan.Scene:WithinArea("P1Spawn1",actor.Pos)) then p1area1open = false end if(SceneMan.Scene:WithinArea("P1Spawn2",actor.Pos)) then p1area2open = false end if(SceneMan.Scene:WithinArea("P1Spawn3",actor.Pos)) then p1area3open = false end p2area1open = true p2area2open = true p2area3open = true if(SceneMan.Scene:WithinArea("P2Spawn1",actor.Pos)) then p2area1open = false end if(SceneMan.Scene:WithinArea("P2Spawn2",actor.Pos)) then p2area2open = false end if(SceneMan.Scene:WithinArea("P2Spawn3",actor.Pos)) then p2area3open = false end if(bonustimer:IsPastSimMS(bonusrespawn) and SceneMan.Scene:WithinArea("BonusArea",actor.Pos)) then local team = actor.Team if(team == Activity.TEAM_1) then local ship = CreateACRocket("Cannonball") ship.Team = team ship.Pos = SceneMan.Scene:GetArea("P1BonusSpawn"):GetRandomPoint() MovableMan:AddActor(ship) bonustimer:Reset() elseif(team == Activity.TEAM_2) then local ship = CreateACRocket("Cannonball") ship.Team = team ship.Pos = SceneMan.Scene:GetArea("P2BonusSpawn"):GetRandomPoint() MovableMan:AddActor(ship) bonustimer:Reset() end end end --Update player one's spawn if(team1count < 4 and not p1spawnactive) then p1spawnactive = true p1spawntimer:Reset() end if(p1spawnactive and p1spawntimer:IsPastSimMS(respawntime)) then -- AI stuff, by Roon3 p1GiveWeapon1 = SceneMan.Scene:GetArea("P1GiveWeapon1") p1GiveWeapon2 = SceneMan.Scene:GetArea("P1GiveWeapon2") p1GiveWeapon3 = SceneMan.Scene:GetArea("P1GiveWeapon3") p1GiveWeapon4 = SceneMan.Scene:GetArea("P1GiveWeapon4") p1GiveWeapon5 = SceneMan.Scene:GetArea("P1GiveWeapon5") p1GiveWeapon6 = SceneMan.Scene:GetArea("P1GiveWeapon6") local newplayer = CreateAHuman("Soccer Klone") newplayer.Team = Activity.TEAM_1 if(p1score >= 20) then newplayer:AddAISceneWaypoint(p1GiveWeapon6:GetRandomPoint()) newplayer:AddAISceneWaypoint(p1scorearea:GetRandomPoint()) newplayer.AIMODE = 3 elseif(p1score >= 12) then newplayer:AddAISceneWaypoint(p1GiveWeapon5:GetRandomPoint()) newplayer:AddAISceneWaypoint(p1scorearea:GetRandomPoint()) newplayer.AIMODE = 3 elseif(p1score >= 9) then newplayer:AddAISceneWaypoint(p1GiveWeapon4:GetRandomPoint()) newplayer:AddAISceneWaypoint(p1scorearea:GetRandomPoint()) newplayer.AIMODE = 3 elseif(p1score >= 6) then newplayer:AddAISceneWaypoint(p1GiveWeapon3:GetRandomPoint()) newplayer:AddAISceneWaypoint(p1scorearea:GetRandomPoint()) newplayer.AIMODE = 3 elseif(p1score >= 3) then newplayer:AddAISceneWaypoint(p1GiveWeapon2:GetRandomPoint()) newplayer:AddAISceneWaypoint(p1scorearea:GetRandomPoint()) newplayer.AIMODE = 3 elseif(p1score >= 1) then newplayer:AddAISceneWaypoint(p1GiveWeapon1:GetRandomPoint()) newplayer:AddAISceneWaypoint(p1scorearea:GetRandomPoint()) newplayer.AIMODE = 3 elseif(p1score >= 0) then newplayer:AddAISceneWaypoint(p1scorearea:GetRandomPoint()) newplayer.AIMODE = 3 end if(p1area1open) then newplayer.Pos = p1spawnarea1:GetRandomPoint() elseif(p1area2open) then newplayer.Pos = p1spawnarea2:GetRandomPoint() elseif(p1area3open) then newplayer.Pos = p1spawnarea3:GetRandomPoint() else newplayer.Pos = p1spawnarea1:GetRandomPoint() end MovableMan:AddActor(newplayer) p1spawnactive = false end --Update player two's spawn if(team2count < 4 and not p2spawnactive) then p2spawnactive = true p2spawntimer:Reset() end if(p2spawnactive and p2spawntimer:IsPastSimMS(respawntime)) then -- Maor AI Stuff p2GiveWeapon1 = SceneMan.Scene:GetArea("P2GiveWeapon1") p2GiveWeapon2 = SceneMan.Scene:GetArea("P2GiveWeapon2") p2GiveWeapon3 = SceneMan.Scene:GetArea("P2GiveWeapon3") p2GiveWeapon4 = SceneMan.Scene:GetArea("P2GiveWeapon4") p2GiveWeapon5 = SceneMan.Scene:GetArea("P2GiveWeapon5") p2GiveWeapon6 = SceneMan.Scene:GetArea("P2GiveWeapon6") local newplayer = CreateAHuman("Soccer Klone") newplayer.Team = Activity.TEAM_2 if(p1score >= 20) then newplayer:AddAISceneWaypoint(p2GiveWeapon6:GetRandomPoint()) newplayer:AddAISceneWaypoint(p2scorearea:GetRandomPoint()) newplayer.AIMODE = 3 elseif(p1score >= 12) then newplayer:AddAISceneWaypoint(p2GiveWeapon5:GetRandomPoint()) newplayer:AddAISceneWaypoint(p2scorearea:GetRandomPoint()) newplayer.AIMODE = 3 elseif(p1score >= 9) then newplayer:AddAISceneWaypoint(p2GiveWeapon4:GetRandomPoint()) newplayer:AddAISceneWaypoint(p2scorearea:GetRandomPoint()) newplayer.AIMODE = 3 elseif(p1score >= 6) then newplayer:AddAISceneWaypoint(p2GiveWeapon3:GetRandomPoint()) newplayer:AddAISceneWaypoint(p2scorearea:GetRandomPoint()) newplayer.AIMODE = 3 elseif(p1score >= 3) then newplayer:AddAISceneWaypoint(p2GiveWeapon2:GetRandomPoint()) newplayer:AddAISceneWaypoint(p2scorearea:GetRandomPoint()) newplayer.AIMODE = 3 elseif(p1score >= 1) then newplayer:AddAISceneWaypoint(p2GiveWeapon1:GetRandomPoint()) newplayer:AddAISceneWaypoint(p2scorearea:GetRandomPoint()) newplayer.AIMODE = 3 elseif(p1score >= 0) then newplayer:AddAISceneWaypoint(p2scorearea:GetRandomPoint()) newplayer.AIMODE = 3 end if(p2area1open) then newplayer.Pos = p2spawnarea1:GetRandomPoint() elseif(p2area2open) then newplayer.Pos = p2spawnarea2:GetRandomPoint() elseif(p2area3open) then newplayer.Pos = p2spawnarea3:GetRandomPoint() else newplayer.Pos = p2spawnarea1:GetRandomPoint() end MovableMan:AddActor(newplayer) p2spawnactive = false end --End game if(timelimit and timeleft <= 0) then FrameMan:ClearScreenText(0) FrameMan:ClearScreenText(1) FrameMan:SetScreenText("TIME'S UP! Player "..((((p2score-p1score)/math.abs(p2score-p1score))-1)/2+2).." wins with a score of: "..math.max(p1score,p2score),Activity.TEAM_1,0,-1,true) FrameMan:SetScreenText("TIME'S UP! Player "..((((p2score-p1score)/math.abs(p2score-p1score))-1)/2+2).." wins with a score of: "..math.max(p1score,p2score),Activity.TEAM_2,0,-1,true) ActivityMan:EndActivity() elseif(goallimit and (p1score >= maxgoals or p2score >= maxgoals)) then FrameMan:ClearScreenText(0) FrameMan:ClearScreenText(1) FrameMan:SetScreenText("SCORE LIMIT REACHED! Player "..((((p2score-p1score)/math.abs(p2score-p1score))-1)/2+2).." wins with a score of: "..math.max(p1score,p2score),Activity.TEAM_1,0,-1,true) FrameMan:SetScreenText("SCORE LIMIT REACHED! Player "..((((p2score-p1score)/math.abs(p2score-p1score))-1)/2+2).." wins with a score of: "..math.max(p1score,p2score),Activity.TEAM_2,0,-1,true) ActivityMan:EndActivity() else --Update score/timelimit if(timelimit) then timeleft = timelimittimer:LeftTillSimMS(maxtime*1000)/10 FrameMan:ClearScreenText(0) FrameMan:ClearScreenText(1) FrameMan:SetScreenText("P1: "..p1score.." Timeleft: "..(math.floor(timeleft/6000))..":"..(math.floor((timeleft%6000)/100)).." P2: "..p2score.."\nBonus: "..math.max(math.floor(bonustimer:LeftTillSimMS(bonusrespawn)/600),0),Activity.TEAM_1,0,-50,false) FrameMan:SetScreenText("P1: "..p1score.." Timeleft: "..(math.floor(timeleft/6000))..":"..(math.floor((timeleft%6000)/100)).." P2: "..p2score.."\nBonus: "..math.max(math.floor(bonustimer:LeftTillSimMS(bonusrespawn)/600),0),Activity.TEAM_2,0,-50,false) else FrameMan:ClearScreenText(0) FrameMan:ClearScreenText(1) FrameMan:SetScreenText("P1: "..p1score.." P2: "..p2score.."\nBonus: "..math.max(math.floor(bonustimer:LeftTillSimMS(bonusrespawn)/600),0),Activity.TEAM_1,0,-50,false) FrameMan:SetScreenText("P1: "..p1score.." P2: "..p2score.."\nBonus: "..math.max(math.floor(bonustimer:LeftTillSimMS(bonusrespawn)/600),0),Activity.TEAM_2,0,-50,false) end end end function SoccerMission:PauseActivity(pause) end function SoccerMission:EndActivity() end