How do I choose a random person in multiplayer?

Get help using Construct 2

Post » Fri Jun 24, 2016 3:03 pm

How do I choose a random player in my game?
Owner of Kdot Development.
https://kdotdevelopment.weebly.com
B
11
S
4
G
1
Posts: 40
Reputation: 1,421

Post » Fri Jun 24, 2016 3:31 pm

Take a random number between 0 and peercount:
Code: Select all
random(Multiplayer.PeerCount)

To get the PeerID of the random picked Player:
Code: Select all
Multiplayer.PeerIDAt(random(Multiplayer.PeerCount))
B
11
S
4
G
5
Posts: 74
Reputation: 3,435

Post » Fri Jun 24, 2016 3:48 pm

How do I see the Username of the player? And the Id of the player is not showing... I made it the text of a text object.
Owner of Kdot Development.
https://kdotdevelopment.weebly.com
B
11
S
4
G
1
Posts: 40
Reputation: 1,421

Post » Fri Jun 24, 2016 4:00 pm

For username just use PeerAlias
Code: Select all
Multiplayer.PeerAliasAt(random(Multiplayer.PeerCount))

Did you read the official 4 Part multiplayer Tutorial provided by Ashlay? Link
This will answer most of your questions.
B
11
S
4
G
5
Posts: 74
Reputation: 3,435

Post » Fri Jun 24, 2016 4:45 pm

Prolly want an int() in there.
Image ImageImage
B
172
S
50
G
183
Posts: 8,443
Reputation: 115,605

Post » Fri Jun 24, 2016 5:02 pm

newt wrote:Prolly want an int() in there.

Oh thats right :lol: i totally forgot :roll:
Code: Select all
Multiplayer.PeerAliasAt(random(int(Multiplayer.PeerCount)))

[EDIT:]
Nop i did not, i tested it, no need for int() :ugeek:
Code: Select all
Multiplayer.PeerAliasAt(random(Multiplayer.PeerCount))
Multiplayer.PeerIDAt(random(Multiplayer.PeerCount))

These are working fine ;)
B
11
S
4
G
5
Posts: 74
Reputation: 3,435

Post » Fri Jun 24, 2016 6:21 pm

int(random()), int(multiplayer.peercount) is googles.
I would imagine it's already set to only deal with whole numbers.
No such thing as a fraction of a peer, still, it's better to be safe than sorry.
Image ImageImage
B
172
S
50
G
183
Posts: 8,443
Reputation: 115,605


Return to How do I....?

Who is online

Users browsing this forum: draiza and 22 guests