problem scripting short team modus in LUA

Information and discussion for custom maps and mods.
Post Reply
HeimSpiel
Posts: 10
Joined: Mon Jul 27, 2015 2:55 pm

problem scripting short team modus in LUA

Post 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!

abcdefg30
Posts: 643
Joined: Mon Aug 18, 2014 6:00 pm

Post 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

HeimSpiel
Posts: 10
Joined: Mon Jul 27, 2015 2:55 pm

Post by HeimSpiel »

Ah, now I see. That did the trick.

Thx!

Post Reply