Trouble with main rule syntax

Hi you guys,

I want to change the end conditions so that the game ends when a player doesn’t have one of a certain list of ships. There are some ships that have a build queue that shouldn’t keep the player alive and there are some ships that can’t build that should keep the player alive.

I’m pretty sure this script is almost right, and I’ve tried some other setups, but I can’t get it to work. Can somebody please have a look and tell me what’s wrong? Thanks a lot in advace!

mainrule_flag = 1

function mainrule_updating()		
		if mainrule_flag == 1 then
				objectivePrimary = Objective_Add("$3005", OT_Primary)
				Objective_AddDescription(objectivePrimary, "$3006")
				Subtitle_Message_Handler("$3007", 2, "data:sound\\speech\\allships\\emperor\\CHALLENGE_DESTROYMOTHERSHIPS_2", Universe_CurrentPlayer())		
				mainrule_flag = 0
		end

		
		local playerIndex = 0
		local playerCount = Universe_PlayerCount()




		while (playerIndex < playerCount) do

--change to counting ships that keep you alive instead of build queue beacuse some don't have one, and other ships that have one shouldn't keep you alive

		shipcount = 
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "fed_tmp_midway") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "fed_tmp_outpost") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "fed_tmp_excelsior") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "fed_tmp_flagship") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "fed_tmp_ambassador") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "fed_tmp_shipyard") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "fed_tmp_shipyard_s") +

			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "hgn_carrier") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "hgn_dreadnaught") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "hgn_battlecruiser") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "hgn_mothership") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "hgn_shipyard") +


			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "kus_carrier") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "kus_heavycruiser") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "kus_mothership") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "kus_shipyard") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "kus_shipyard2") +

			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "tai_carrier") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "tai_heavycruiser") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "tai_mothership") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "tai_shipyard") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "tai_shipyard2") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "tai_mbdreadnaught") +

			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "vgr_carrier") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "vgr_mr") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "vgr_battlecruiser") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "vgr_mothership") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "vgr_shipyard") +

			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "kpr_sajuuk")

				if (Player_IsAlive(playerIndex) == 1 and shipcount(playerIndex) == 0) then
						Player_Kill(playerIndex)
						if playerIndex ~= Universe_CurrentPlayer() then
--								UI_SetScreenEnabled("PlayerDestroyedScreen", 1)
--								UI_SetScreenVisible("PlayerDestroyedScreen", 1)			
								local playerNameW = Player_GetName(playerIndex)								
--								UI_SetTextLabelTextWF1("PlayerDestroyedScreen", "lblDescription1", "$1231", playerNameW);
								Sound_SpeechPlay("data:sound\\speech\\missions\\m_15\\47100")
								Player_AddLocalChatMessage("$1231", playerNameW);
						end
				end
				playerIndex = playerIndex+1
		end
		local numAlive = 0
		local numEnemies = 0
		local gameOver = 1

--shipyard check
		playerIndex = 0
		while (playerIndex < playerCount) do
			if (Player_HasResearch(playerIndex, "BuildOff") == 0) then
			Player_RestrictBuildOption(playerIndex, "Tai_Shipyard2")
			Player_RestrictBuildOption(playerIndex, "Kus_Shipyard2")
			end
		-- go to next player
		playerIndex = playerIndex+1
		end


--end of shipyard check

		playerIndex = 0
		while (playerIndex < playerCount) do
				if (Player_IsAlive(playerIndex) == 1) then
						local otherPlayerIndex = 0
						while (otherPlayerIndex < playerCount) do
								if (AreAllied(playerIndex, otherPlayerIndex) == 0) then
										if (Player_IsAlive(otherPlayerIndex) == 1) then
												gameOver = 0
										else
												numEnemies = numEnemies + 1
										end
								end
								otherPlayerIndex = otherPlayerIndex + 1
						end
						numAlive = numAlive + 1
				end
				playerIndex = playerIndex + 1
		end
		if (numEnemies == 0 and numAlive > 0) then
				gameOver = 0
		end
		if (gameOver == 1) then
				Rule_Add("waitForEnd")
				Event_Start("endGame")
				Rule_Remove("mainrule_updating")
		end
end

function waitForEnd()
		if(Event_IsDone("endGame")) then
				setGameOver()
				Rule_Remove("waitForEnd")
		end
end
		

This one looks like a piece of dog-dook, but it works!

mainrule_flag = 1

function mainrule_updating()		
		if mainrule_flag == 1 then
				objectivePrimary = Objective_Add("$3005", OT_Primary)
				Objective_AddDescription(objectivePrimary, "$3006")
				Subtitle_Message_Handler("$3007", 2, "data:sound\\speech\\allships\\emperor\\CHALLENGE_DESTROYMOTHERSHIPS_2", Universe_CurrentPlayer())		
				mainrule_flag = 0
		end

		
		local playerIndex = 0
		local playerCount = Universe_PlayerCount()
		while (playerIndex < playerCount) do
				if ((Player_IsAlive(playerIndex) == 1) and ((
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "fed_tmp_midway") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "fed_tmp_outpost") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "fed_tmp_excelsior") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "fed_tmp_flagship") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "fed_tmp_ambassador") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "fed_tmp_shipyard") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "fed_tmp_shipyard_s") +

			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "hgn_carrier") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "hgn_dreadnaught") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "hgn_battlecruiser") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "hgn_mothership") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "hgn_shipyard") +


			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "kus_carrier") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "kus_heavycruiser") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "kus_mothership") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "kus_shipyard") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "kus_shipyard2") +

			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "tai_carrier") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "tai_heavycruiser") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "tai_mothership") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "tai_shipyard") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "tai_shipyard2") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "tai_mbdreadnaught") +

			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "vgr_carrier") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "vgr_mr") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "vgr_battlecruiser") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "vgr_mothership") +
			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "vgr_shipyard") +

			Player_GetNumberOfSquadronsOfTypeAwakeOrSleeping(playerIndex, "kpr_sajuuk")

) == 0)) then
						Player_Kill(playerIndex)
						if playerIndex ~= Universe_CurrentPlayer() then
--								UI_SetScreenEnabled("PlayerDestroyedScreen", 1)
--								UI_SetScreenVisible("PlayerDestroyedScreen", 1)			
								local playerNameW = Player_GetName(playerIndex)								
--								UI_SetTextLabelTextWF1("PlayerDestroyedScreen", "lblDescription1", "$1231", playerNameW);
								Sound_SpeechPlay("data:sound\\speech\\missions\\m_15\\47100")
								Player_AddLocalChatMessage("$1231", playerNameW);
						end
				end
				playerIndex = playerIndex+1
		end
		local numAlive = 0
		local numEnemies = 0
		local gameOver = 1

--shipyard check 
		playerIndex = 0
		while (playerIndex < playerCount) do
			if (Player_HasResearch(playerIndex, "BuildOff") == 0) then
			Player_RestrictBuildOption(playerIndex, "Tai_Shipyard2")
			Player_RestrictBuildOption(playerIndex, "Kus_Shipyard2")
			end
		-- go to next player
		playerIndex = playerIndex+1
		end


--end of shipyard check

		playerIndex = 0
		while (playerIndex < playerCount) do
				if (Player_IsAlive(playerIndex) == 1) then
						local otherPlayerIndex = 0
						while (otherPlayerIndex < playerCount) do
								if (AreAllied(playerIndex, otherPlayerIndex) == 0) then
										if (Player_IsAlive(otherPlayerIndex) == 1) then
												gameOver = 0
										else
												numEnemies = numEnemies + 1
										end
								end
								otherPlayerIndex = otherPlayerIndex + 1
						end
						numAlive = numAlive + 1
				end
				playerIndex = playerIndex + 1
		end
		if (numEnemies == 0 and numAlive > 0) then
				gameOver = 0
		end
		if (gameOver == 1) then
				Rule_Add("waitForEnd")
				Event_Start("endGame")
				Rule_Remove("mainrule_updating")
		end
end

function waitForEnd()
		if(Event_IsDone("endGame")) then
				setGameOver()
				Rule_Remove("waitForEnd")
		end
end
		
2 Likes