Joining to others, when the player wants

Posted by mpgame
hey size and others!

At the moment, in vs games like "topdown shooter", which are made by this great extension, the following event is happening:
When we login, the server immediately will be finding another player to match with us...
and according to the following script, we will go to the battle...:

if(gms_vs_ready())
{
gms_team_auto_join();
room_goto(rm_play);
}

but I don't want this event. I want that the player has a decision after login for event of finding another player. For example, I want to set a button that if the login player click on it, the player go to find others. But if the login player don't click on it, the server don't set it in among of ready players for matching to others! Is there a script for this purpose?

thanks...

Replies (39)

Last message on 11 Nov 2016

Size43 (Administrator) on 10 Oct 2016, 18:43:28
Hey,

To add to what's already been said: You'll need to use sessions for this. As far as I'm aware the session limit is 65535 sessions, not 255. There are 255 possible session types, but they don't have to be unique: you can have two or more sessions that have the same type.

One other way to do this is to have all players in the same session, but separate them by faking the room they're in. You can specify a script using gms_script_set_roomid to override the default room IDs. Every two players for whom the script returns the same value will see eachother. When the values differ they won't be able to see eachother.

Hope that helps.
UnderJustin on 12 Oct 2016, 01:08:51
Well, that works, at the start i was having troubles, confusing Id with Type and vice versa, but it's all fine now. Thanks. By now i dont have money, but, depending how much the game sells i will donate maybe every week, month or year (i dont want that :v ).
mpgame (Topicstarter) on 12 Oct 2016, 17:15:35
Size, your guidance can help me. but unfortunately, I don't exactly understand what to do for applying your second way. because, I don't find a practical example for "a script using gms_script_set_roomid to override the default room IDs".

UnderJustin, it is very good that Size's solution works for you. but I don't correctly know what to do about room IDs :( Can you tell me more perfectly about this way or is it possible for you to send me an example source for applying this item?
my mail: mohsen.designer20@gmail.com

very very thanks...
UnderJustin on 12 Oct 2016, 18:47:01
Sorry, i dont use the "a script using gms_script_set_roomid to override the default room IDs", i use the first way, using same id of session with different type. The second way i found it difficult.
UnderJustin on 12 Oct 2016, 18:50:38
PS: Also i dont understand how to do it in the second way.
mpgame (Topicstarter) on 13 Oct 2016, 11:02:29
Ok thanks,
So I also use first way(sessions)... but I have a problem in implementation of that.
The server put the all login players in one session with type 0 and we can create new session or join to other desired sessions. I put this script in Left Released of a button for this work:

i=1;
while (i<gms_session_count())
{
if (gms_session_exists(gms_session_id(i)) && gms_session_player_count(gms_session_id(i)) == 1)
{
gms_session_join(gms_session_id(i));
a=1;
b=i;
exit;
}
else if !(gms_session_exists(gms_session_id(i)))
break;
i++;
}
if(a==0)
{
gms_session_create(100);
b=i;
a=1;
}
mpgame (Topicstarter) on 13 Oct 2016, 11:05:58
Oh, Sorry... my message sent incomplete. I will send complete message in next reply.
mpgame (Topicstarter) on 13 Oct 2016, 11:18:32
Ok thanks,
So I also use first way(sessions)... but I have a problem in implementation of that.
The server put the all login players in one session with type 0 and we can create new session or join to other desired sessions. I put this script in Left Released of a button for this work:

i=1;
while (i<gms_session_count())
{
if (gms_session_exists(gms_session_id(i)) && gms_session_player_count(gms_session_id(i)) == 1)
{
gms_session_join(gms_session_id(i));
exit;
}
else if !(gms_session_exists(gms_session_id(i)))
break;
i++;
}
gms_session_create(100);


this script for my 1vs1 game works as well. but after several running the game for several minutes, the server put any login players in one session with type 0 and so gms_session_count() show 0. but after several minutes it will be fix again.

do you have this problem? Generally, how do you implementation of that??
Size43 (Administrator) on 23 Oct 2016, 19:10:22
Hey,

I deployed an update to the server yesterday to fix the exact issue you're describing.

Another fix will be rolling out later tonight. Please let me know if you still experience the issue after that.
mpgame (Topicstarter) on 26 Oct 2016, 18:41:33
Hey Size!

Your new update is much better than previous version and my problem is fixed! but unfortunately some issues still exist.

Sometimes I have the following problem:
consider some players are in session with type 0 (lobby session), in that time another players go to login, after than, they may go to a new session with type 0 (new lobby session). therefore, a separation will be created between two groups of players for joining to each other! If this problem is happened just for one player who is in old session with type 0 (old lobby session), then he can't join to anybody at no time! What's your idea about this problem?

Thanks very much for your attention.
Size43 (Administrator) on 28 Oct 2016, 17:26:23
Do you have VS mode enabled? VS mode will limit the number of players that can be in a lobby session to the maximum number of players that you've set.
mpgame (Topicstarter) on 29 Oct 2016, 19:09:22
No, it's disable!
Size43 (Administrator) on 30 Oct 2016, 21:05:22
I've added some additional logging. If it happens again, please let me know the date/time so I can search the logs.
mpgame (Topicstarter) on 31 Oct 2016, 17:29:48
Size! I don't know what did you do but that problem now happens very less than previous! but in some special statuses, separation problem exists for login players.
I tested it in 20 min ago...
Size43 (Administrator) on 10 Nov 2016, 11:30:30
Did the problem with the sessions also occur?
mpgame (Topicstarter) on 10 Nov 2016, 19:36:38
yeah. but less than before.
mpgame (Topicstarter) on 4 Nov 2016, 15:16:02
and a question!
How to use gms_vs_end() or a similar way to do end of a battle in sessions? because gms_vs_end() doesn't work and I don't want to logout the players of a battle...
Size43 (Administrator) on 10 Nov 2016, 11:31:24
If you're not using the vs mode, gms_vs_end will not work.

You'll have to use the p2p messages to send a message to the other clients that the game ended.
mpgame (Topicstarter) on 10 Nov 2016, 19:28:23
My purpose isn't sending message.
My game is 1vs1 battle and I am not using the vs mode.
I want to when a battle ended, both of two player go to lobby session again. or if an player left the game in during battle, other player go to lobby session. This event happens in "vs mode" by gms_vs_end() but in sessions how to happens?
The only way came to my mind is to logout both of two player and login again! but it isn't good.
Size43 (Administrator) on 11 Nov 2016, 12:13:01
I know -- check the documentation for gms_p2p_send, it's not a message as in "chat message", but a message as in "vs mode end"-message. You can use it to notify other clients that something happened (in your case, you'd want to let the other clients know they need to go back to the lobby session). See also this documentation.
mpgame (Topicstarter) on 11 Nov 2016, 16:16:35
thanks... That's right, but my question is how to go back to "lobby session"? because after the player login, he automatically will go to "lobby session" therefor we must logout the player and login again him to going to "lobby session" again. (In addition maybe lobby session changed when the player is in a battle!)
Size43 (Administrator) on 11 Nov 2016, 17:20:31
The lobby session will be any session with type 0. You need to create one if none exists.
mpgame (Topicstarter) on 4 Nov 2016, 18:34:02
Size!!! I'm so sorry for my many problems...
I have a new issue that I don't find solution of that!

How I can give an initial values to textboxes of login part?
my purpose is not "gms_login_set_username ( name )"...
I want to show login part but with this condition: "textboxes of login part have my initial values!" ,Is it possible?

Thanks for your attention :)
Size43 (Administrator) on 10 Nov 2016, 11:36:06
I don't think this is possible. You can set the constants (see the link UnderJustin provided) "txt_username" and "txt_password" to change the placeholder text.
UnderJustin on 4 Nov 2016, 23:50:59
This maybe help you, its for customize the "forms":http://gamemakerserver.com/en/docs/article/custom_screens/
I tried to use it but when i use the import window function dont work, maybe you can discover how to use it.
mpgame (Topicstarter) on 7 Nov 2016, 16:34:23
Thanks UnderJustin! I will read it... but I don't think that it can resolve my problem.
UnderJustin on 14 Oct 2016, 05:35:52
Your code seems to be ok, the problem maybe be in the servers, i dont have this problem because the matches on my game lasts a few minutes, also i dont try stay many minutes, this is my code when i create it and works fine its similar to yours, but i dont know if this help.

if global.cansearch=0 {exit};
for(self.i = 0; self.i < gms_session_count(); self.i += 1)
{
self.waitt+=1
if self.waitt>=390{
gms_session_create(random_range(1,100));
global.cansearch=0;
self.waitt=0;
exit
}
if gms_session_type(gms_session_id(i))>=1 and gms_session_type(gms_session_id(i))<=100
{
if gms_session_player_count(gms_session_id(i))=0
{exit}
if gms_session_player_count(gms_session_id(i))=1
{
gms_session_join(gms_session_id(i))
global.cansearch=0;
self.waitt=0;
exit
}
}
}
UnderJustin on 14 Oct 2016, 05:37:03
Ignore the first line, cansearch is for the switch to activate the search of session.
UnderJustin on 14 Oct 2016, 05:39:36
PS: I mean similar for functionality of join and create session, obviously out of that is diferently programmed.
mpgame (Topicstarter) on 14 Oct 2016, 10:21:55
Thanks for sending your code ????

I think this problem will exist in using your code as mine. because an empty session will be stopped within a few minutes automatically by server. therefore, when no player is login, server destroy the session with type 0 and for some minutes, none new session with type 0 can be created by server.
This problem can confuse the players!

I hope that Size or others have a solution for this problem...
mpgame (Topicstarter) on 14 Oct 2016, 10:25:42
PS: "????" was an emoji! :)
mpgame (Topicstarter) on 14 Oct 2016, 10:22:27
Thanks for sending your code.

I think this problem will exist in using your code as mine. because an empty session will be stopped within a few minutes automatically by server. therefore, when no player is login, server destroy the session with type 0 and for some minutes, none new session with type 0 can be created by server.
This problem can confuse the players!

I hope that Size or others have a solution for this problem...
UnderJustin on 15 Oct 2016, 00:23:14
I think I'm also experiencing this problem, the command to check how many sessions there returns 0, the session type returns -1, the players in the current session returns -1. I need not even be several minutes playing for the bug appears, but after a few minutes back to normal.
UnderJustin on 3 Oct 2016, 00:44:34
I also want to know that, i think its not possible now, i tried many ways but nothing works, but, securely in the v3 the developer will allow this and more things like game modes (i want that because my game is a serious project, will be for android with microtransactions, not like any generic game).
Shaddovv on 3 Oct 2016, 19:49:01
There is no script for this currrently, but what you could do is make an system yourself, or only check when a certain variable is on "true".

For example, you could make a system that counts the players that are ready and matches them up with them making a selfmade session for them, or just use the session system withotu the vs and code your teams yourself.

info about sessions:http://gamemakerserver.com/en/docs/article/sessions/
If you do not know how to program this after doing some research, make a new project, try out the sessions system yourself and experiment with it to fully understand the things there could be possible and not possible with it.

Remember, coding + testing, will get you through everything.
UnderJustin on 3 Oct 2016, 21:14:42
I dont know if you are answering to me (sure not), but anyway i already think to use sessions, but for my game is not viable due the 255 sessions limit. Also, i dont know if size43 know this, but, the function gms_vs_end() dont work, at least for me not, when you use that function and a client closes the game the other client crashes, this happen with my project and with the example included in the extension, and the example doesnt have the function, maybe size43 already know this issue, this is all. I dont speak english if something is mistraslated.
Shaddovv on 3 Oct 2016, 21:51:26
Yes, i am awnsering to you and yes there is a limit of 255 on the sessions, but i highly doubt you go over that limit currently. But like i said, if you will need something like that, make custom sessions and for example store them in the game_ini and only sync the objects when it is the same value.

also note: "Please keep in mind that using the session-functions while having the VS mode enabled, can cause unexpected effects, since the VS mode uses the session system for it's inner workings to run multiple instances of the game at the same time."

About the game_vs_end() not working, I think your doing something wrong or their may be indeed a bug, last time i used game_vs_end() was about last week and it did its job perfectly.
UnderJustin on 4 Oct 2016, 03:08:23
The game in what im currently working have matchs between 2 players maximum, so the maximum players playing simultanously can be 510, also there will be a Solo Mode and other 1vs1 modes, i dont know how much people can play my game in a future, i will do much as i can to make this game played by many people, then if exceeds 510 players use sessions from now can be a error, later, have to make the changes to vs normal and all will be fastidious, boring, etc...anyway i can wait for the support of multiple vs game modes.
mpgame (Topicstarter) on 4 Oct 2016, 11:08:34
UnderJustin, My problem is exactly like yours... My game is 1vs1 android game and
due to the download number of other my games, I forecast over 50,000 download for this game...

Anyway, I hope that Size can suggest a solution for "Joining to others, when the player wants". I think that a script maybe existed for this item: The server don't show a login player as a ready player.

Finally, thanks to Shaddovv for his guidance...