get Player By Index
Get a Player from the multiplayer game list using an index value.
mp.getPlayerByIndex(0)
You can get a Player object from the multiplayer using an index value for a location in the list. Index values start at 0
for the first list location and range to the maximum number of players minus 1
(currently 4
players maximum so, the maximum list index is 4 - 1
= 3
).
Parameters
- index: a number that is the index of the Player in the multiplayer list.
Returns
- the Player in the multiplayer list at location index.
Example
Find all the players that have a score greater than 20
and give them a bonus of 5
points.
let player: mp.Player = null
for (let index = 0; index <= 3; index++) {
player = mp.getPlayerByIndex(index)
if (mp.getPlayerState(player, MultiplayerState.score) > 20) {
mp.changePlayerStateBy(player, MultiplayerState.score, 5)
}
}
See also
player selector, get player by number
multiplayer