Possible to send p2p messages to only OTHER players?

Posted by jamop
So in my game currently I'm trying to play a sound when the player shoots, and the sound is played on all clients using p2p messages. However, preferably I would prefer the sound to play on the shooting player's client , then having a p2p message sent to all other clients except the shooting client telling these clients to play the shooting sound.


The main reason I wish to do this is due to lag. I live in Australia so, as you can probably imagine, there's a large delay between shooting and hearing the sound on the client which is kinda unusual. Is this possible to do?

Replies (4)

Last message on 19 Aug 2018

Size43 (Administrator) on 19 Aug 2018, 12:13:38
Besides the solution offered below, you could also make the client ignore any p2p messages from itself, which would achieve the same thing (and might be more efficient if you use one of the gms_p2p_all_* constants)
TannerS on 17 Aug 2018, 06:07:32
Every client that logs on to your game has an id
for(var i = 0; i < gms_other_count(); i++) {
    var pid = gms_other_find(i);
    gms_p2p_send(p2p_play_sound, pid)
}

I haven't used GMS in a while, but unless things have changed on me, that sends the message to all other clients in the same session as yourself.
After that, it's as simple as setting up your message handler and playing the sound upon receiving the message.

Hope it helps ;)
Size43 (Administrator) on 19 Aug 2018, 12:12:27
There's also gms_p2p_all_in_room, gms_p2p_all_in_session and gms_p2p_all_in_game, which you can use as PlayerID to send a P2P message to multiple people in a single gms_p2p_send.
jdev on 17 Aug 2018, 15:17:26
Yes, this should work.