Page 1 of 1

problem scripting short team modus in LUA

Posted: Sat Dec 09, 2017 10:22 am
by HeimSpiel
Hello,

I'm trying to make a 4v4 map. Teams are fixed and tied to positions top vs bottom inside the yaml. That works.

What I'm looking for is a 'Short GTeam Modus' where the whole team loses once one of its members loses. So far, that's what I got:

Code: Select all

MissionSurvive = { }
Gamers = { }

ShortMode = function(player)
	for i = 1,#Gamers do
		if Gamers[i] ~= nil then
			if Gamers[i].IsAlliedWith(player) then
				Media.PlaySpeechNotification(Gamers[i], "Lose")
				Gamers[i].MarkFailedObjective(MissionSurvive[i])
			else
				Media.PlaySpeechNotification(Gamers[i], "Win")
			end
		end
	end
end

WorldLoaded = function()
	Gamers = Player.GetPlayers(nil)
	for i = 1,#Gamers do
		if Gamers[i] ~= nil then
			Trigger.OnPlayerLost(Gamers[i], ShortMode)
			Trigger.OnObjectiveCompleted(Gamers[i], function(p, id)
				Media.DisplayMessage(p.GetObjectiveDescription(id), "You won")
			end)
			Trigger.OnObjectiveFailed(Gamers[i], function(p, id)
				Media.DisplayMessage(p.GetObjectiveDescription(id), "You lost")
			end)
			MissionSurvive[i] = Gamers[i].AddPrimaryObjective("All team members survive")
		end
	end
end
The problem that I have is, that once a player loses, all players lose at the same time, independent of being in his team or not.

I don't really understand why the 'IsAlliedWith' fails here.

Can you help me? Thanks a lot!

Posted: Mon Dec 11, 2017 1:39 am
by abcdefg30
You encluded every player there. Even the "map owned" ones (which caused the failure).
I'd suggest you expand your two if conditions by "and not Gamers.IsNonCombatant", i.e.

Code: Select all

if Gamers[i] ~= nil and not Gamers[i].IsNonCombatant then

Posted: Tue Dec 12, 2017 7:19 pm
by HeimSpiel
Ah, now I see. That did the trick.

Thx!