Function; Universe_CurrentPlayer - HWRM/KarosGraveyard GitHub Wiki

Universe_CurrentPlayer()

Description

Returns the local player's index number on the computer.
Note: this should never be called in MP games, especially when modifying deterministic data.
Note: not sure what the difference is between this function and FE_GetCurrentPlayerIndex. -Mikali

This function is used in plenty of stock files which are run in multiplayer; relics.lua is a fine example.

The common usage is to ensure some code branch only runs for certain players.

Consider the case where two carriers are spawned in a multiplayer match, one belonging to player 0, and the other to player 1. We want to do something when a player spawns a carrier such as toggling a UI element. Since the carrier's spawn-in script will run for both players on both carrier spawns, if we want to avoid toggling another player's UI, we can use Universe_CurrentPlayer to ensure we only do it when the script is being run by the 'current player', which is just whichever player is currently executing the lua scripts. Keep in mind, the scripts will be run by all players.

Example

if SobGroup_OwnedBy("temp1") == Universe_CurrentPlayer() then -- if the local machine's player owns `temp1`, do something
  -- ...
end

Arguments

Nil