Getting Player Client ID

Posted by Shaddovv
Heey size!

I use the id's of the players and put them into a variable named target to make de AI follow that target. Only when i put gms_self_playerid() in it with the object thats actually hitting the AI it gives an error and when i use the normal id it only makes it follow the client_master (client that first logged in) how can i make it so that when the player attacks the AI actually follows the player instead of only the client master?



Thanks for youre time :)

Replies (15)

Last message on 10 Nov 2016

Size43 (Administrator) on 25 Jun 2016, 22:05:04
Note that gms_self_playerid() will not return an id that references a valid instance. You can use something like this:

var stored_player_id;
stored_player_id = target;
with obj_player
{
    if player_id == stored_player_id // player_id is a variable every "other player object" has
    {
        // do something
    }
}
Shaddovv (Topicstarter) on 2 Nov 2016, 05:03:01
Could you give me a more detailed example of this method? What do you mean with Stored_player_id and what should be the player_id that returns?
Size43 (Administrator) on 10 Nov 2016, 11:48:50
stored_player_id should be the player_id of another player. I'm guessing that it's the player_id of the player that's currently targeted by the enemy?
Shaddovv (Topicstarter) on 26 Jun 2016, 00:21:44
When i try to refer to player_id it says the variable doesnt exists?
Size43 (Administrator) on 10 Nov 2016, 11:49:20
The player_id variable only exists in other player objects.

You can use gms_self_playerid() to get the id of the current player.
Size43 (Administrator) on 10 Nov 2016, 11:50:10
Oops, seems like I already replied to this below. You can ignore this post.
Shaddovv (Topicstarter) on 26 Jun 2016, 00:24:04
___________________________________________
############################################################################################
FATAL ERROR in
action number 1
of Step Event2
for object obj_greatsword:

Push :: Execution Error - Variable Get -1.player_id(100039, -2147483648)
at gml_Script_scr_greatsword_basic_attack (line 38) - n.target=player_id
############################################################################################
--------------------------------------------------------------------------------------------
stack frame is
gml_Script_scr_greatsword_basic_attack (line 38)
called from - gml_Object_obj_greatsword_StepEndEvent_1 (line 22) - scr_greatsword_basic_attack()
Size43 (Administrator) on 3 Jul 2016, 22:14:46
player_id only exists on other player objects. It seems like you're trying to get the player_id of an instance of the obj_greatsword object. Without knowing what player you're trying to refer to, I can't give more specific advice.
R1ckx on 2 Jul 2016, 16:58:17
You can use gms_self_playerid() to get your own playerid.

The example above implies that you have a variable named player_id with this value
Shaddovv (Topicstarter) on 2 Jul 2016, 17:03:09
I dont want to get youre own ID i want to get the instance id's of other player_id's wich i cant seem to figure out. :/
R1ckx on 2 Jul 2016, 17:10:30
I know, but that's the solution for your error you pasted above :)

Either way the instance ID's are the same on every client, if I recall correctly
Size43 (Administrator) on 3 Jul 2016, 22:15:51
GameMaker's instance IDs differ, there's no way for the extension to control that. The syncIDs or playerIDs (used in instance synchronisation and player synchronisation respectively) share the same value across multiple clients.
Shaddovv (Topicstarter) on 2 Jul 2016, 17:16:30
I dont think they are actually
R1ckx on 2 Jul 2016, 17:18:59
I'll try to test this in a controlled testproject later today, and tell you the results. Quite curious myself!

For a workaround you can set the id as a custom variable to sync with the instance
Shaddovv (Topicstarter) on 2 Jul 2016, 19:59:34
Yes but that custom variable needs to be in every gms_master client wich can be everyone, and everyone has another set of variables so that means that they will link to different objects, so that doesnt work.