0ad/binaries/data/mods/public/maps/scripts/NonVisualTrigger.js
Ralph Sennhauser 60fc382bd8
Fix eslint rule 'prefer-const' in maps/scripts
eslint --no-config-lookup --fix --rule '"prefer-const": 1' \
    binaries/data/mods/public/maps/scripts

Ref: #7812
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-05-09 19:46:31 +02:00

25 lines
859 B
JavaScript

/**
* This will print the statistics at the end of a game.
* In order for this to work, the player's state has to be changed before the event.
*/
Trigger.prototype.EndGameAction = function()
{
if (!this.once || Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager).GetActivePlayers().length)
return;
this.once = false;
for (const player of Engine.GetEntitiesWithInterface(IID_StatisticsTracker))
{
const cmpStatisticsTracker = Engine.QueryInterface(player, IID_StatisticsTracker);
if (cmpStatisticsTracker)
print(cmpStatisticsTracker.GetStatisticsJSON() + "\n");
}
};
{
const cmpTrigger = Engine.QueryInterface(SYSTEM_ENTITY, IID_Trigger);
cmpTrigger.RegisterTrigger("OnPlayerWon", "EndGameAction", { "enabled": true });
cmpTrigger.RegisterTrigger("OnPlayerDefeated", "EndGameAction", { "enabled": true });
cmpTrigger.once = true;
}