One of the player in a game of northgard. Can be both a human or AI player. Any player manage a clan nand own one TownHall and a territory.

Variables

bonuses:Array<PlayerBonus>

List of bonuses that a player have.

read onlycapturedUnits:Array<Unit>

All the units the player own but cannot control, like Sheeps.

clan:ClanKind

[HostOnly] Current clan of the player. Can be set to change the clan. Won't remove clan specific buildings.

read onlycurrentHappiness:Float

The current happiness at the beginning of the regular update. Contrary to getHappiness(), currentHappiness stay consistent during the whole update process.

read onlydiscovered:Array<Zone>

All the zones the player revealed with his scounts.

read onlyfeastCount:Int

The number of time the player used a feast during the game.

freeFeast:Int

[HostOnly] The number of free feasts the player currently have. Can be used to give or take free feasts.

read onlyfreeFeastCount:Int

The number of time the player used a free feast during the game.

read onlyisAI:Bool

Is the player AI controlled.

read onlyname:String

The name of the player

read onlyobjectives:ScriptObjectives

Interface to setup objectives visible in the UI.

read onlyteam:Faction

The team of the player, symbolised by the team leader.

read onlyunits:Array<Unit>

All the units owned by the player, wherever they are.

read onlyzones:Array<Zone>

All the zones the player colonized, including the town hall zone.

Methods

addBonus(data:BonusSave):Void

Add a Conquest bonus for a player. Example : addBonus({id:Bonus.BMineral, resId:Resource.Stone, isAdvanced:true});

Parameters:

data

The bonus data.

@:value({ amount : 1 })addFreeTech(amount:Int = 1):Void

[HostOnly] Add a free tech to choose to the player.

Parameters:

amount

Number of free tech to give.

addMeal(kind:RecipeKind, power:Bool, duration:Bool, ?provider:Player):Void

[HostOnly] Add a meal to the player. Only one meal by provider is allowed, the previous meal is replaced by the new one. The player is his own provider if no provider was specified.

Parameters:

kind
power

Do we enable the power bonus for the meal.

duration

Do we enable the duration bonus for the meal.

provider

[Optional] Who provided the meal, null makes the player his own provider.

addPingFlag(x:Float, y:Float, type:PingFlagType):Void

Add a ping on the map and a flag in the world to notify of a location. Position are in world coordinates.

Parameters:

x
y
type

Choose between InterestPoint or Team. InterestPoint will ping the player only, while Team will ping his whole team. Team pings have a limitation of 10 at a time.

@:value({ produced : true })addResource(kind:ResourceKind, amount:Float, produced:Bool = true):Void

[HostOnly] Immediately give an amount of a specific resource to the player. Doesn't count into the production.

Parameters:

kind
amount
produce

[Optional] true to set this resource as produced.
Produced resources are counted to trigger certain benefits and count into the final statistics.
Defaulted at true.

allowColonize(zone:Zone, b:Bool):Void

Allow or forbid the playze to colonize a specific zone.

Parameters:

zone
b

true to allow, false to forbid.

coverAll(?exceptZone:Zone):Void

[HostOnly] Restore the fog of war for the whole map.

Parameters:

exceptZone

[Optional] A zone to keep discovered.

coverZone(zone:Zone):Void

[HostOnly] Restore the fog of war on the specified zone.

Parameters:

null

zone

customDefeat(loseReason:String):Void

[HostOnly] Instantly make this player lose the game.

Parameters:

null

loseReason

customVictory(winReason:String, loseReason:String):Void

[HostOnly] Instantly make this player and his team win the game.

Parameters:

winReason

The reason the player won.

loseReason

The reason the other players lose.

customVictoryKind(kind:String):Void

[HostOnly] Instantly make this player and his team win the game from the specified kind. This will be displayed as "You achieved a [custom kind] victory !"

Parameters:

kind

The custom victory kind.

defeat():Void

[HostOnly] Instantly make this player lose the game.

discoverAll():Void

[HostOnly] Discover the whole map for the player.

discoverZone(zone:Zone):Bool

[HostOnly] Try to remove the fog of war from the specified zone.

Parameters:

zone

Returns:

Bool true if the zone was successfully discovered, else false.

@:value({ ignoreCooldown : false })equipArrows(arrowKind:AbilityKind, ignoreCooldown:Bool = false):Bool

[HostOnly] Allow to change the type of arrow used by the trackers. Specific to Lynx clan.

Parameters:

arrowKind

Returns:

Bool return false if a wrong ability kind was passed.

genericNotify(text:String, ?target:Entity):Void

Display a custom top left notification to the player.

Parameters:

text
target

A target entity to pan the camera to the player click on the notification.

getActiveArrowType():AbilityKind

Return the type of arrows currently used by the trackers. Specific to Lynx clan.

Returns:

AbilityKind

getAvailableWarchiefs():Array<UnitKind>

Gives all the unit kind used as Warchiefs for this player's clan.

Returns:

Array

getBonus(id:BonusKind, ?unitId:UnitKind, ?buildingId:BuildingKind, ?resId:ResourceKind):PlayerBonus

Return the specified bonus' data.

Parameters:

id
unitId
buildingId
resId

Returns:

PlayerBonus The bonus data if found, else null.

getBuilding(kind:BuildingKind):Building

Get the first instance of a building the player has. Return null if none were found.

Parameters:

kind

The kind of building to get.

Returns:

Building

getBuildings(kind:BuildingKind, ?withConstruction:Bool, ?ignoreCreator:Bool):Array<Building>

Get all the buildings of a certain kind.

Parameters:

kind

The kind of building to get.

withConstruction

Do we include buildings under construction.

ignoreCreator

Do we ignore building exclusive to the player but under enemy control, like relics or the altar of kings.

Returns:

Array

getCooldownHero(kind:UnitKind):Float

Get the time at which the warchief can be hired again.

Parameters:

kind

Returns:

Float

getHappiness():Float

Get the player's happiness at the given time. For a more consistent happiness value during script execution, use currentHappiness

Returns:

Float

getIncomingRivalryFrom(player:Player):TechKind

Get the rivalry the given player is targeting me with.

Parameters:

player

The player targeting me.

Returns:

Bool the rivalry applied to me, else false.

getMax(kind:ResourceKind):Int

Tell the maximum amount of one resource the player can hold.

Parameters:

kind

Returns:

Int

@:value({ atRestOnly : false, withHeroes : false })getMilitaryCount(?zone:Zone, withHeroes:Bool = false, atRestOnly:Bool = false):Int

Count all the player's military units.

Parameters:

zone

[Optional] Count units only in this zone

withHeroes

[Optional] Include the Heroes in the count

atRestOnly

[Optional] Only count military units without orders

Returns:

Int

getResource(kind:ResourceKind):Float

Tell the current amount of resource owned by the player.

Parameters:

kind

Returns:

Float

getRivalryDiffWith(?with:Player, ?kind:TechKind):Int

Get the differential value of the rivalry relative to the player's situation.

Parameters:

with

[Optional] The player we compare our situation with. If unset, use the selected player.

kind

[Optional] The kind of rivalry we compare. If unset, use the selected rivalry.

Returns:

Int The differential between my situation and the selected player's. 0 if no rivalry or target is selected.

getRivalryState(?with:Player, ?kind:TechKind):RivalryState

Get the state of the selected rivalry.

Parameters:

with

[Optional] The player we want the state of the rivalry from. If unset, use the selected player.

kind

[Optional] The kind of rivalry we want the state from. If unset, use the selected rivalry.

Returns:

RivalryState

getScoutingLevel(p:Player):Int

Obtain the scouting level of a player related to me. 0 : Not discovered. 1 : Found at least one of the player's zone. 2 : Found the player's townhall.

Parameters:

p

The player to look at.

Returns:

Int The scouting level.

getSelectedRivalryKind():TechKind

Get the kind of the selected rivalry

getSelectedRivalryTarget():Player

Get the target of the selected rivalry.

getSlaves(?kind:UnitKind, ?zone:Zone):Array<Unit>

Dragon specific, get all the slaves a player has, of a certain kind or in a zone. Return an empty array of none were found.

Parameters:

kind

The job of the slaves to get.

zone

The zone where to get the slaves.

Returns:

Array

getSpyInfo(p:Player):SpyInfo

Retrieve the spy informations obtained from the player or its team.

getTownHall():Building

Get the unit townhall of the player.

Returns:

Building

@:value({ withConstruction : false })getTradingPosts(withConstruction:Bool = false):Array<TradingPost>

Give a list of all the trading posts owned by the player.

Parameters:

withConstruction

Include trading posts being built.

Returns:

Array

getUnit(kind:UnitKind):Unit

Get the first instance of UnitKind under control of a player. Return null if none were found.

Parameters:

kind

Returns:

Unit

getUnits(?kind:UnitKind, ?zone:Zone):Array<Unit>

Get all the units of a player, of a certain kind or in a zone. Return an empty array of none were found.

Parameters:

kind

The kind of units to get.

zone

The zone where to get the units.

Returns:

Array

getWarchief():Unit

Get the first warchief spawned in the player's army.

Returns:

Unit The first warchief, else null.

getWarchiefs():Array<Unit>

Get all the present warchiefs from the player's army. Usefull for multiple warchiefs clans like Horse and Bear.

Returns:

Array

hasActiveRivalry(?with:Player, ?kind:TechKind):Bool

Does the player has an active rivalry. Can specify if it is against another player or with a specific rivalry.

Parameters:

with

[Optional] The player to look at.

kind

[Optional] The rivalry to look at.

Returns:

Bool true we have a rivalry with the given conditions.

hasBonus(id:BonusKind, ?unitId:UnitKind, ?buildingId:BuildingKind, ?resId:ResourceKind):Bool

Check if a player has a given bonus.

Parameters:

id
unitId
buildingId
resId

Returns:

Bool

hasBuilding(kind:BuildingKind, ?withConstruction:Bool, ?upgraded:Bool, ?withExtension:Bool, ?specialCond:Building ‑> Bool):Bool

Tell if the player possess at least one of the given kind of building.

Parameters:

kind
withConstruction

[Optional] Do we count buildings being built

upgraded

[Optional] Do we count upgraded buildings only

withExtension

[Optional] Do we count buildings with extensions only (Harbour with Lighthouse)

specialCond

[Optional] A callback for more specific test cases.

Returns:

Bool

hasDiscovered(zone:Zone):Bool

Tell if the player already discovered the given zone.

Parameters:

zone

Returns:

Bool

hasDiscoveredOne(zones:Array<Zone>):Bool

Does the player discovered at least one of the given zones.

Parameters:

zones

Returns:

Bool

hasFlag(flag:PlayerFlag):Void

Check if a player has a flag set.

Parameters:

null

flag

hasSelectedRivalry():Bool

Does the player have selected a rivalry, including its target.

Returns:

Bool

hasTech(tech:TechKind):Bool

Tell if the player unlocked the specified tech.

Parameters:

tech

Returns:

Bool

hasTrophy(kind:AbilityKind):Bool

Tells if a hunting trophy has been unlocked. Specific to Lynx clan.

Parameters:

kind

Returns:

Bool

@:value({ refund : false, isFree : false })lockTech(kind:TechKind, isFree:Bool = false, refund:Bool = false):Void

[HostOnly] Toggle a tech off. This ask the player to purchase it again to unlock next techs. Doesn't check for already unlocked blessings or effects.

Parameters:

kind
isFree

Remove the tech from the unlocked free techs.

refund

Give back the spent lore to unlock the tech, or give back a free tech if it was free.

removeBonus(id:BonusKind, ?unitId:UnitKind, ?buildingId:BuildingKind, ?resId:ResourceKind):Bool

Remove a Conquest bonus from a player.

Parameters:

id
unitId
buildingId
resId

Returns:

Bool True if the bonus was removed, else false.

resetRivalry():Bool

[HostOnly] Get the kind of the selected rivalry

setAILevel(level:Int):Bool

[HostOnly] Set the difficulty level of the AI of this player.

Parameters:

level

Returns:

Bool true if the player is an IA.

@:value({ toSet : true })setFlag(flag:PlayerFlag, toSet:Bool = true):Void

[HostOnly] Set or unset a player flag.

Parameters:

flag
null

toSet

setResource(kind:ResourceKind, amount:Float):Void

[HostOnly] Set a resource to a set amount.

setRivalry(with:Player, kind:TechKind, ?force:Bool):Bool

[HostOnly] Set a rilvalry against a player.

Parameters:

with

The target player of the rivalry.

kind

The kind of the rivalry.

force

[Optional] Ignore the validation checks to set a rivalry.

Returns:

Bool false if with or kind is null, or if the rivalry cannot be chosen against the player.

setTech(techs:Array<TechKind>):Void

[Obsolete] Unlock the given techs for the player. This simply toggle the tech on/off and don't trigger effects for certain techs. Obsolete, use unlockTech instead.

Parameters:

techs
isFree

Is the tech added to the price calculation toward the next tech.

@:value({ alert : false })takeControl(zone:Zone, alert:Bool = false):Void

[HostOnly] Immediately take control of the given zone.

Parameters:

zone
alert

[Optional] Do we send an alert to the previous owner of the zone.

triggerVictory(kind:VictoryKind):Void

[HostOnly] Instantly make this player and his team win the game. Use an existing VictoryKind for the victory reason.

Parameters:

null

kind

@:value({ isFree : false })unlockTech(kind:TechKind, isFree:Bool = false):Void

[HostOnly] Unlock a tech and apply any related effect. Check for Blessing unlocks. To use during gameplay.

Parameters:

kind
isFree

Is the tech added to the price calculation toward the next tech.

@:value({ free : false })unlockTrophy(kind:AbilityKind, free:Bool = false):Bool

[HostOnly] Try to unlock a trophy by spending resources, unless it is set as free trophy. Specific to Lynx clan.

Parameters:

kind
null

free

unlockedForFree(kind:TechKind):Bool

Tell if a tech was unlocked for free. Return false if the player don't have the tech at all.

Parameters:

kind

Returns:

Bool