gms_script_set_p2p

Usage: gms_script_set_p2p ( script_id )

Description

Sets the script that should be executed when receiving a p2p-message.

The script should take 3 arguments:
argument0: P2P-message id
argument1: Sender's player_id
argument2: a ds_list with all values sent.

Example

//Sets the script scr_p2p to be executed when a new p2p-message is received.
gms_script_set_p2p(scr_p2p)

Replies (13)

Last message on 2 Dec 2018

andiprasetyo on 27 Nov 2018, 16:39:46
any example to sent ds_list, and read ds_list from argument2?
Size43 (Administrator) on 2 Dec 2018, 13:52:01
nahuelolivera710 on 5 Oct 2018, 10:35:35
Hi, I have a question. Where do I write gms_script_set_p2p?
Size43 (Administrator) on 21 Oct 2018, 16:48:03
I'd recommend putting it near gms_settings, though any event that's executed at the start of the game will do.
Sunari on 26 Apr 2018, 06:54:40
Do p2p-messages work with data structures other than ds_lists?
Wouldn't buffers be more optimal for network traffic?
Does the extension make buffers of the ds_list and reconstruct it?
Size43 (Administrator) on 10 May 2018, 19:19:34
They use buffers internally.
PvicPlays on 24 Dec 2017, 20:10:22
Hi, I keep getting this error sometimes in my game:
"
ERROR in
action number 1
of Begin Step Event
for object __newobject441:

Received a P2P message, but no script is set to handle P2P messages. gms_script_set_p2p(script) should be called before any P2P messages are received.
"
Do you have any idea of what causes this?
If you want I can link the GMK.
Size43 (Administrator) on 24 Dec 2017, 20:45:42
Are you calling gms_p2p_send anywhere? If so, you need to receive it by setting the script.

If not, an easy way to make the error go away is to add a script that just does this:

var mid = argument0, sender = argument1, data = argument2;
return 0;


And then set that script using gms_script_set_p2p
Dublann on 3 Apr 2017, 20:57:05
Size, is mandatory to have the argument1 defined? I'm figuring out how one player can know it if there are more than 1 player connected.
Size43 (Administrator) on 16 Apr 2017, 16:26:02
You might be better off using gms_other_count to check for this.
RefresherTowel on 29 Sep 2015, 07:05:26
Here is the script itself, scr_p2p_received:

//Seehttp://gamemakerserver.com/help/script/gms_script_set_p2p/ switch(argument0)
{
case p2p_kill:
//Don't forget to actually ADD the statistics on the site!
gms_statistic_set("kills", gms_statistic_get("kills") + 1);
break;
}
RefresherTowel on 29 Sep 2015, 07:04:36
Hey size, I've been trying to get kill tracking working in my game but it keeps throwing up an error. This is the error:

FATAL ERROR in
action number 1
of Step Eventobj_pistol_bullet
for object obj_player:

Push :: Execution Error - Variable Get 100002.p2p_kill(100010, -2147483648)
at gml_Object_obj_player_Collision_1

I've got three different sections in my obj_player object that create the kill tracking.

In my collision event with the obj_pistol_bullet I've got:

if (other.owner != gms_self_playerid()) {
hp -= other.damage;
if (hp <= 0) {
gms_chat("was killed by " + gms_other_get_string(other.owner, "name"), c_red);
gms_p2p_send(p2p_kill, other.owner);
instance_destroy();
}
with (other) {
instance_destroy();
}
}

In the room start event I've got:

gms_script_set_p2p(scr_p2p_received);

And finally, the script itself (scr_p2p_received) which won't fit in this comment, so I'll add another one with it.
Size43 (Administrator) on 2 Oct 2015, 13:19:32
You'll need to add p2p_kill as a constant / macro, and give it a numeric value between 0 and 255. The p2p-type (first argument) is just a number, but it's better to put those numbers in constants so you know what they actually mean. If you really wanted to, you could also replace all p2p_kills with a random number in 0 - 255.