Usage: gms_script_set_p2p ( script_id )


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.


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

Replies (7)

Last message on 24 Dec 2017

PvicPlays on 24 Dec 2017, 20:10:22
Hi, I keep getting this error sometimes in my game:
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:

//See 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);
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:

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);
with (other) {

In the room start event I've got:


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.