Trigger API Reference DCEI Functions Player0 - BLKTower/TestWiki GitHub Wiki

Table of Contents

Trigger API Reference\DCEI Functions\Player {Trigger-API-ReferenceDCEI-FunctionsPlayer}

int GetPlayerCount() {int-GetPlayerCount}

int GetPlayerCount()

Description

Returns the number of players in the game.

Example Usage

local player_count = DCEI.GetPlayerCount()

int GetCurrentPlayerId() {int-GetCurrentPlayerId}

int GetCurrentPlayerId()

Description

Get the current player's id. Only useful in multiplayer.

Example Usage

void SetPlayerTeamId(int playerId, int teamId) {void-SetPlayerTeamIdint-playerId-int-teamId}

void SetPlayerTeamId(int playerId, int teamId)

Description

Used to set a player's team id.

Parameters

  • int playerId the ID of the player to be switched.
  • int teamId the ID of the player's new team.

Example Usage

local player_team_id = DCEI.GetPlayerTeamId(1)
if player_team_id = 1 then
    DCEI.SetPlayerTeamId(1, 2)
end

int GetPlayerTeamId(int playerId) {int-GetPlayerTeamIdint-playerId}

int GetPlayerTeamId(int playerId)

Description

Returns a player's team id.

Parameters

  • int playerId the ID of the player.

Example Usage

local player_team_id = DCEI.GetPlayerTeamId(1)

void AddGold(int playerId, int amount) {void-AddGoldint-playerId-int-amount}

void AddGold(int playerId, int amount)

Description

Adds gold to a player. Maximum gold value for a player is 2,147,483,647 (2^31-1).

Parameters

  • int playerId the ID of the player.
  • int amount the amount of gold to be added. Use negative values to subtract gold.

Example Usage

function OnRegionEnter()
    DCEI.AddGold(1, 10)
end

DCEI.TriggerAddUnitEnterRegionEvent(DCEI.UnitAny, DCEI.RegionAny, OnRegionEnter)

Related

void SetGold(int playerId, int amount) {void-SetGoldint-playerId-int-amount}

void SetGold(int playerId, int amount)

Description

Sets a player's gold value. Maximum gold value for a player is 2,147,483,647 (2^31-1).

Parameters

  • int playerId the ID of the player.
  • int amount the amount of gold to be set.

Example Usage

function OnRegionEnter()
    DCEI.SetGold(1, 10)
end

DCEI.TriggerAddUnitEnterRegionEvent(DCEI.UnitAny, DCEI.RegionAny, OnRegionEnter)

Related

int GetGold(int playerId) {int-GetGoldint-playerId}

int GetGold(int playerId)

Description

Returns a player's gold value.

Parameters

  • int playerId the ID of the player.

Example Usage

function OnRegionEnter()
    local player_gold = DCEI.GetGold(1)
    if (player_gold + 10) > 2147483647 then
        DCEI.SetGold(1, 2147483647)
    else
        DCEI.AddGold(1, 10)
    end
end

DCEI.TriggerAddUnitEnterRegionEvent(DCEI.UnitAny, DCEI.RegionAny, OnRegionEnter)

Related

int GetUnitPlayerId(unit unit) {int-GetUnitPlayerIdunit-unit}

int GetUnitPlayerId(unit unit)

Description

Returns the player ID of the owner of a unit.

Parameters

  • unit unit the unit to return the player ID of.

Example Usage

local region = DCEI.FindRegion("region_0")
local team_id = 1
local player_id = 1
local unit_type = "Standard MeleeUnit"
local x, y = 16, 16
local unit = DCEI.CreateUnit(team_id, player_id, unit_type, x, y)

DCEI.LogMessage("Unit's Player ID: " .. DCEI.GetUnitPlayerId(unit))

int GetUnitTeamId(unit unit) {int-GetUnitTeamIdunit-unit}

int GetUnitTeamId(unit unit)

Description

Returns the team ID of a unit.

Parameters

  • unit unit the unit to return the team ID of.

Example Usage

local region = DCEI.FindRegion("region_0")
local team_id = 1
local player_id = 1
local unit_type = "Standard MeleeUnit"
local x, y = 16, 16
local unit = DCEI.CreateUnit(team_id, player_id, unit_type, x, y)

DCEI.LogMessage("Unit Team ID: " .. DCEI.GetUnitTeamId(unit))

⚠️ **GitHub.com Fallback** ⚠️