gms_script_set_logout

Usage: gms_script_set_logout ( script_id )

Description

Sets the script that should be executed when a player logs out.

The script should take 1 argument:
argument0: The 'other player' object.

Example

//Sets the script scr_logout to be executed when a new player logs in
gms_script_set_logout(scr_logout)

Replies (6)

Last message on 3 Mar 2016

amkgames on 17 Feb 2016, 10:44:09
I did something like this:
//Step Event of Ally
if !gms_instance_is_owner(id)
{
gms_script_set_logout(scr_logout);
}
//scr_logout script
if !player_id_exists(gms_instance_get_owner(id))
{
    instance_destroy();
}
//player_id_exists script (Your script. :P)
for(n = 0; n < gms_other_count(); n += 1;)
{
    if gms_other_find(n) == argument0
        return true;
}
return false;

But it is not working, I know I am doing everything wrong. xD
Please tell me what am I doing wrong? (Actually, I am doing everything wrong. lol)
Thanks! :)
Size43 (Administrator) on 21 Feb 2016, 21:22:41
Just leave what you had in the step event of the Ally object. Add the call to gms_script_set_logout to a game start event somewhere so it's executed when your game starts.

Try this in the logout script:
[gml]
with Ally
{
if gms_instance_get_owner(id) == argument0.player_id
{
instance_destroy()
}
}
[/gml]
amkgames on 22 Feb 2016, 08:53:31
Now I changed code to this:
//Step
if !gms_instance_is_owner(id)
{
if !player_id_exists(gms_instance_get_owner(id))
{
    instance_destroy();
}
}
//Logout script
with(obj_ally)
{
if gms_instance_get_owner(id) == argument0.player_id
{
instance_destroy();
}
}
//obj_control's game start
gms_script_set_logout(scr_logout);

But not working, is it because gms_settings is being called on create event of obj_control? because Game Start and Create event are very likely executes at once.
Possibly it is like update checking? (like update checking code should be executed some time after gms_settings.)
Size43 (Administrator) on 1 Mar 2016, 10:38:10
It doesn't matter when you execute gms_script_set_logout, as long as it's after gms_init (GM:Studio). Does the ally at least get destroyed when the other player logs out? That's what the code should do.
amkgames on 1 Mar 2016, 10:53:08
It not destroys and starts following player.
Size43 (Administrator) on 3 Mar 2016, 09:49:35
Would you be able to mail me your gmk/gmz at gamemakerserver@outlook.com, so that I can take a look?