Getting another player's variables
I want to make a 1v1 lobby and for that I need to get both players health variable to make 2 healthbars (like in a fighting game).
I'm not so sure how to implement this, even if I use gms_other_get I still need to get the player id.
Any idea how can I implement this?
Thanks a bunch!
PS: I just realized that I asked something similar in the past.
I really don't understand how to get information from other players :D
Replies (1)
Last message on 7 Feb 2021
Size43
(Administrator)
on
7 Feb 2021, 14:48:04
You can use
gms_other_count and
gms_other_find to loop over all the players in the current session. The example in
gms_other_count shows how you can loop over all players, get their player ID, and then get their name.
If you're sure there will only be two players in the session at any time, you can simplify the code to:
var other_id;
if gms_other_count() > 1 {
other_id = gms_other_find(0);
} else {
// there's nobody else in this session; you should show an error or return to a lobby
}
// other_id now contains the player ID of the other player in the session