share/hedgewars/Data/Scripts/SimpleMission.lua
changeset 14471 734a7af2dfc2
parent 14469 ead8928a59f8
child 14488 310b167141cc
--- a/share/hedgewars/Data/Scripts/SimpleMission.lua	Tue Dec 18 18:26:13 2018 +0100
+++ b/share/hedgewars/Data/Scripts/SimpleMission.lua	Tue Dec 18 18:37:58 2018 +0100
@@ -504,10 +504,6 @@
 		end
 		if victory then
 			_G.sm.gameEnded = true
-			if not _G.sm.wonVarWritten then
-				SaveMissionVar("Won", "true")
-				_G.sm.wonVarWritten = true
-			end
 		end
 	end
 
@@ -703,9 +699,7 @@
 	_G.onNewTurn = function()
 		_G.sm.gameStarted = true
 
-		if params.customGoals == nil then
-			_G.sm.checkRegularVictory()
-		elseif params.customGoalCheck == "turnStart" then
+		if params.customGoalCheck == "turnStart" then
 			_G.sm.checkRegularVictory()
 			_G.sm.checkWinOrFail()
 		end
@@ -714,14 +708,19 @@
 	_G.onEndTurn = function()
 		_G.sm.gameTurns = _G.sm.gameTurns + 1
 
-		if params.customGoals == nil then
-			_G.sm.checkRegularVictory()
-		elseif params.customGoalCheck == "turnEnd" then
+		if params.customGoalCheck == "turnEnd" then
 			_G.sm.checkRegularVictory()
 			_G.sm.checkWinOrFail()
 		end
 	end
 
+	_G.onGameResult = function(winningClan)
+		if (params.customGoals == nil) and (not _G.sm.wonVarWritten) and (winningClan == _G.sm.playerClan) then
+			SaveMissionVar("Won", "true")
+			_G.sm.wonVarWritten = true
+		end
+	end
+
 	_G.onAmmoStoreInit = function()
 		local ammoTypesDone = {}
 		-- Read script's stated ammo wishes