Search Unity

[RELEASED] MultiOnline : multiplayer online kit - V3 now available

Discussion in 'Assets and Asset Store' started by VirtuElle, Aug 16, 2013.

  1. VirtuElle

    VirtuElle

    Joined:
    Jan 27, 2013
    Posts:
    458
    I also thought about it, in fact, the player who "played with a prebab" must instantiate it himself (according to my knowledge).
    So if you really want to do that, you should first selected randomly which player will be "the 4th" player, and tell him to instantiate a second prefab.

    You have the list off all the players in MNetwork, (playerList), you can select randomly a player in this list using Random.Range() function.
    -> int key = Random.Range(0, playerList.Count-1);
    With this "key" you can access to the selected player in playerList (-> playerList[key]) , and send a message to this player (using a RPC function) to tell him that he must spawn a new prefab.
     
  2. ostrich160

    ostrich160

    Joined:
    Feb 28, 2012
    Posts:
    679
    I had a few issues with that, but I came up with a different solution. All I need to know now is if there is anyway to randomly swap the spawn locations, if it doesnt already. So the 4th player doesnt always spawn in the same place
     
  3. VirtuElle

    VirtuElle

    Joined:
    Jan 27, 2013
    Posts:
    458
    It's already the case: on your maps, your have a GameObject Spawns which contains many spawn points (you can add spawn points in this Spawns as much you want, it's explain in documentation part 5.2 - page 47).
    And the spawn point of a player is always chosen randomly from these spawn point
     
  4. ReaList

    ReaList

    Joined:
    Mar 27, 2014
    Posts:
    13
    Hi,

    Version 3 will be released when ?
     
  5. VirtuElle

    VirtuElle

    Joined:
    Jan 27, 2013
    Posts:
    458
    As I told before, I cannot give you any date. I hope I'll have time to work on it this summer, but I don't promise anything.
     
    ReaList likes this.
  6. rgomezer

    rgomezer

    Joined:
    Jun 8, 2014
    Posts:
    3
    Hello,

    I am working on a part of a game where the user logs in using your system and then has an option to use a level editor (using the Runtime Level Editor made by Alex Leighton) and then is supposed to push it to a MySQL database using the login information from MOServer.cs. My question is when I transition to another scene, will the login data from MOServer.cs still carry over when I do MOServer server = new MOServer(); when writing a function in the Runtime Level Editor? Because in MPlayerData.cs you check if the user is online and then just call the coroutine using the respective parameters.
    .
     
  7. VirtuElle

    VirtuElle

    Joined:
    Jan 27, 2013
    Posts:
    458
    MOServer doesn't contains any login data (the variables userName, userMail,... of MOServer are only used for output), so that you can create a new MOServer object without any problem.

    If you want to check if the user is well logged, you can take the player data in MPlayerData (which is used to store it during all the game), which has the parameter DontDestroyOnLoad(), so you would still access of all the data in your new scene.
    To check if a player is well logged, it's in php side, using the loginKey, which work like a session Id. Your php script can compare your current loginKey with which one stored in the database to check that your current player is well logged. You can use the function checkUser() which is in MOUser.php for that.
     
  8. kinghack

    kinghack

    Joined:
    Nov 30, 2013
    Posts:
    54
    Iv followed the Documentation and uninstalled it re installed it several times and It says no game found on the view games list.
     
  9. VirtuElle

    VirtuElle

    Joined:
    Jan 27, 2013
    Posts:
    458
    Does you game is well registered in the database or not ? (Check it from PhpMyAdmin, once you have created your game, it must appear in the table "games")
     
  10. kinghack

    kinghack

    Joined:
    Nov 30, 2013
    Posts:
    54
    It appears in the Games table yes. Registers and logs in perfectly.
     
  11. VirtuElle

    VirtuElle

    Joined:
    Jan 27, 2013
    Posts:
    458
    That's strange... But it's maybe just a "logical problem", so first, check these 3 points:
    - Check that you have selected more than 1 player in "maximum players" when you created the game (the full games don't appear in the game list)
    - If you have still started the game, check that the box "Can join started game" is well checked -> Open the scene Menu, click on Menu gameobject,it's in "Global parameter" on the inspector.
    - Check that the player which hosts the game didn't blacklisted your second player: when you put a player in the blackist, he can not more see the games that you host.
    If the problem doesn't come form one of these reason, it may be a technical problem.
    To try to know from where it comes, put this line on MOServer, line 250:
    Code (csharp):
    1.  
    2. string trimText = www.text.Trim();
    3. Debug.Log (trimText);// Add this line
    4. tring[] text = trimText.Split('|');
    5.  
    Build your game, create a new game from your .exe file, and try to join it from the editor play mode.
    Tell me what is written in the console.
     
  12. kinghack

    kinghack

    Joined:
    Nov 30, 2013
    Posts:
    54
    When I refresh it says this.

    ERROR|noGame
    UnityEngine.Debug:Log(Object)
    MultiPlayer.<SearchGames>c__IteratorC:MoveNext() (at Assets/MultiOnline/Scripts/MOServer.cs:250)


    Another thing I noticed is that you can login with the same account details even if another client is logged in with those details. which i'm not sure is meant to happen or not but i'm guessing its not.
     
  13. VirtuElle

    VirtuElle

    Joined:
    Jan 27, 2013
    Posts:
    458
    And does your game is still recorded in the database when you refresh ?
    It's possible that your second player delete himself the game when he get it: your problem can comes from the "call interval". With MultiOnline, the host have to send a message each x seconds to the web server to "confirm" that he still hosting the game.
    When a player takes the game list, he checks the call intervall of the games saved in the database, and if a call is too old, he directly deletes the game. (You can read documentation part 4.5 - page 43 - about it).

    So to konw if the problem is this one, delete or put in comments some lines in the php file MOGame.class.php :

    The line 229 :
    Code (csharp):
    1.  
    2. // If the last call of the game is older than the callInterval
    3. if(mktime($value['lastUpdate_h'], $value['lastUpdate_m'], $value['lastUpdate_s'], $value['lastUpdate_mo'], $value['lastUpdate_d'], $value['lastUpdate_y']) >= time()-$callInterval){  
    4.  
    And lines 245 to 249
    Code (csharp):
    1.  
    2. } else {// Else : delete the game$array = array(':id' => $value['gameId']);$this->prepare_exec('DELETE FROM games WHERE id=:id', $array);
    3. }
    4.  
    So do it, and tell me if your game are still deleted when an other player try to get the games list.

    If the problem is well that, you can then check of the field "lastUpdate" is well updated each 10 seconds (so refresh your phpMyAdmin after a few second to check the the value is well incremented).

    You're right, it shouldn't do that. The player status is checked in php side, and if you try to use the data of a player which is still login you must have an error message.
    When a player is logged, the field "login" of the table users in database must be as "1", can you check that it's well the case ?
    Which web hosting do you use ?
     
  14. kinghack

    kinghack

    Joined:
    Nov 30, 2013
    Posts:
    54
    That worked I can see the game and I can join it. Its no longer deleted,
     
  15. ostrich160

    ostrich160

    Joined:
    Feb 28, 2012
    Posts:
    679
    Thanks for all your help mate, I just thought I may as well check, is it possible to do matchmaking with this, so lets say 2 random people who are playing the game are placed together?
     
  16. dceevp

    dceevp

    Joined:
    Mar 4, 2013
    Posts:
    19
    How i change the GUI by other GUI solutions like NGUI?
    I only change all section of "GUI DISPLAY FUNCTION " and the rest of the code is the same?
     
  17. VirtuElle

    VirtuElle

    Joined:
    Jan 27, 2013
    Posts:
    458
    Ok, than mean your problem comes from the call interval.
    You should try to know why it doesn't work correctly, maybe you webhosting doesn't support the number of call you do, so you can try to put a bigger value as call interval (read documentation part 4.5 - page 43 for more details about it).
     
  18. VirtuElle

    VirtuElle

    Joined:
    Jan 27, 2013
    Posts:
    458
    ... Why not !
    In fact it's difficult for me to answer you about it since I don't really understand what you want to do. I try to imagine what it looks like, but I failed !
     
  19. VirtuElle

    VirtuElle

    Joined:
    Jan 27, 2013
    Posts:
    458
    Yes, that's it, you just have to change the "display functions".
     
  20. ostrich160

    ostrich160

    Joined:
    Feb 28, 2012
    Posts:
    679
    Okay well lets say I go onto the game, I press a certain button, and it matches me with someone else, at random, who pressed that button. Or if I host a server, anyone in the world who is looking for a server can see it.
     
  21. dceevp

    dceevp

    Joined:
    Mar 4, 2013
    Posts:
    19
    hi again!
    Do you think to use good ol' sockets could work MO in mobile platform?
     
  22. VirtuElle

    VirtuElle

    Joined:
    Jan 27, 2013
    Posts:
    458
    Ok, I think I understand.
    Yes, it would be possible, in this case, you must first select the 2 players which will be placed together (randomly if you want). One of them will randomly select the spawn point , and transmit the positions of this spawn point to the second player using a RPC function. And once the two player know the spawn point, you can spawn their prefab in this point.
     
  23. VirtuElle

    VirtuElle

    Joined:
    Jan 27, 2013
    Posts:
    458
    I don't know this asset, but I don't think that it may help MO to work in mobile. According to what I read about this asset, it allows to use .NET sockets without Unity pro. That's probably a great asset, but my assets are not based on .NET sockets, so I don't think that it would resolve anything.
     
  24. kinghack

    kinghack

    Joined:
    Nov 30, 2013
    Posts:
    54
    Hi I know this is allot to ask but i'm trying to make it so player items are loaded from the database
    my items are floats so like private float Apple; private float Sword; ect like that and how would I make it so
    when someone registers a part in the database is created called (PlayersUserName)_items and when you join the server it checks ur username and then its like this kinda private float (PlayersUserName)_items Apple; or something like that.

    I hope I explained that well if you don't understand I'll be more specific Thank you I love the support for this asset :)
     
  25. VirtuElle

    VirtuElle

    Joined:
    Jan 27, 2013
    Posts:
    458
    By "private float Apple; private float Sword", you mean a variable typeof float which represents an Apple or a Sword in game (as an id) ?
    About create "a part in the database called (Players UserName)_items", I don't know if you mean create a table especially for each player named in this way, but if it's that, that's not a good idea, you will complicated the management of your database for nothing.
    You'd better create just one table named (for example) "users_items", which will contains the fields "user_id" and "item_id". In this way you'll can use a foreign key constraint in ""user_id" (with "On delete CASCADE" / "On uptade CASCADE").
    After, to access to these data, you'll need to create a php page and add functions MUser.class.php to access to your items. And also put calls to this page in MOServer.cs to get the data in game.
    But it will work exactly in the same way as the blacklist, so you can look at the scripts which manage the balcklist (in MOServer.cs, and in the php scripts), it must help you to understand how do that.
     
  26. kinghack

    kinghack

    Joined:
    Nov 30, 2013
    Posts:
    54
    By "private float Apple; private float Sword", you mean a variable type of float which represents an Apple or a Sword in game (as an id) ?

    Yea how my inventory works is for every item there is a float and I do this

    if( Apple > 0 )
    DisplayAppleItem = true;
    else
    DisplayAppleItem = false;

    So if you have more than one apple then apple item appears in your inventory. and the quantity depends on the value of the float.

    And about the database part Couldn't I just have a txt file instead of using the db? would that be easy're? and store the player items in a txt?
     
  27. VirtuElle

    VirtuElle

    Joined:
    Jan 27, 2013
    Posts:
    458
    ... Would it not be better to use int instead float (except if you can have "0.5" apple for example) ?

    Of course, you're not obliged to use the database, especially if you are not very comfortable with php and mySQL.
    So yes, you can use a .txt, or an xml file to store your game data. I have never use files to store game datas, so I'll not be able to help you about it, but it's probably easier that using the database.
    But I have also an other idea for you, even easier than using .txt file: you could use the PlayerPrefs which is exactly made for save game data.
    That's very easy to use, here is an example:

    To save data:
    Code (CSharp):
    1. // If you use floats:
    2. PlayerPrefs.SetFloat("Apple", appleVariable);
    3. PlayerPrefs.SetFloat("Sword", swordVariable);
    4.  
    5. // Or if you finally prefer integer:
    6. PlayerPrefs.SetInt("Apple", appleVariable);
    7. PlayerPrefs.SetInt("Sword", swordVariable);
    8.  
    To get data:
    Code (CSharp):
    1. // If you use floats:
    2. appleVariable = PlayerPrefs.GetFloat("Apple");
    3. swordVariable= PlayerPrefs.GetFloat("Sword");
    4.  
    5. // Or if you finally prefer integer:
    6. appleVariable = PlayerPrefs.GetInt("Apple");
    7. swordVariable= PlayerPrefs.GetInt("Sword");
    8.  
    I think it could be the best solution for you.
     
  28. kinghack

    kinghack

    Joined:
    Nov 30, 2013
    Posts:
    54
    That works really well only issue is that all the players I log in with have the same items. But i'll search up tutorials on loading variables from txt files.
     
    Last edited: Jun 17, 2014
  29. VirtuElle

    VirtuElle

    Joined:
    Jan 27, 2013
    Posts:
    458
    Yes, you're right, with my example all players will have the same data, I didn't thought about it !
    You can however use the PlayerPrefs system by define a different key (based on the user) for each data saved, like that for example:

    Code (CSharp):
    1. // Save data:
    2. PlayerPrefs.SetFloat("Apple"+userId, appleVariable);
    3. PlayerPrefs.SetFloat("Sword"+userId, swordVariable);
    4.  
    5. // Get data
    6. appleVariable = PlayerPrefs.GetFloat("Apple"+userId);
    7. swordVariable= PlayerPrefs.GetFloat("Sword"+userId);
    8.  
    In this way each player will have his own data saved, and you'll can access to it when he logs.
    (You can get the userId from MPlayerData, that's the attribut named "id").

    ... That's just an idea I have, so I tell it to you, but use a .txt file system will also work great.

    Note: but with this PlayerPrefs system, all the data are stored locally, that mean that if a player want to player from another computer, he won't have his data.
    So if you want that a player can get his data from any computer, you'll have no other choice than store it in your web server (using the database or a .txt file)
     
    Last edited: Jun 17, 2014
  30. ostrich160

    ostrich160

    Joined:
    Feb 28, 2012
    Posts:
    679
    I think you missed the point :p. What I basically mean is that you are playing with random people, people you dont know, who have just randomly joined your game. Is that possible?
     
  31. kinghack

    kinghack

    Joined:
    Nov 30, 2013
    Posts:
    54


    I checked around and it seems that XML is considered slower and not as reliable i'm pretty keen to do the db idea
    it seems pretty reliable.

    I made a table in the db called items
    CREATE TABLE IF NOT EXISTS `items` (
    `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
    `userName` varchar(100) COLLATE latin1_german1_ci NOT NULL,
    `Apple` varchar(100) COLLATE latin1_german1_ci DEFAULT NULL,
    `M1911` varchar(100) COLLATE latin1_german1_ci DEFAULT NULL,

    PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_german1_ci AUTO_INCREMENT=16 ;

    But to manage it i'm guessing I needa make a php file right?
     
  32. VirtuElle

    VirtuElle

    Joined:
    Jan 27, 2013
    Posts:
    458
    Yes, that's it, you need now a php file which will get the data from the database.
    For the connexion to MySQL you can use the class MODb.class.php (in functions folder) which I made to manage the connexions and query to MySQL, but that's not an obligation.

    About your new table, you show me your script, so I allow myself to give my opinion ;)
    I guess you will do one column for each item. In these column, you will store the number of each item for each player isn't it ? If yes, it would be more logical to make these column as int instead varchar ?
    And something else, to identify the player, you had better put users_id instead userName. Usually, we always use the id to identify something in database.
    In this way, you'll can connect your new table to users table with using a foreign key, and then, add a foreign key constraint to garanty the integrity of you table.
     
  33. VirtuElle

    VirtuElle

    Joined:
    Jan 27, 2013
    Posts:
    458
    You're right, definitely I don't understand !
    But what do you mean by "people who have just randomly joined the game" ?
    They logged from the game menu, and without do anything they are spawned in a game ??
     
  34. ostrich160

    ostrich160

    Joined:
    Feb 28, 2012
    Posts:
    679
    No I mean they are randomly placed in the game. So I set up a server, and they press a button which means they just go to a random server. OR, is there a way to get a list of all the servers?
     
  35. VirtuElle

    VirtuElle

    Joined:
    Jan 27, 2013
    Posts:
    458
    That's already what MultiOnline does ! The game list displays the list all the open game server.
    And when a player joins a game, he is currently placed randomly on the game map.
    So what do you need more ?
     
  36. ostrich160

    ostrich160

    Joined:
    Feb 28, 2012
    Posts:
    679
    I thought that was only servers on your network? Does it display all the servers in the world then?
    Also is this the same with Multilan?
     
  37. VirtuElle

    VirtuElle

    Joined:
    Jan 27, 2013
    Posts:
    458
    MultiOnline displays all the open server, in the whole world: the web server registers all the open game to allow players to join it easily.

    With MultiLan it's different, you can only display the list of the open games on your own network, because contrary to MultiOnline, the data are not centralised. So it's impossible to display the games of the whole world with MultiLan. (That's why I made MultiOnline ;) )
     
  38. ostrich160

    ostrich160

    Joined:
    Feb 28, 2012
    Posts:
    679
    Ah, thought so. I'll make the upgrade later today then, its fair enough since it is a big ask on my part. Do I need to buy a web host as well then?

    Just a quick question, for a win state, how do I detect if everyone apart from a certain person is dead? So for example, is the person who spawned from spawn 1, 2 and 4 have health = 0 or whatever, spawn 3 wins.
     
  39. VirtuElle

    VirtuElle

    Joined:
    Jan 27, 2013
    Posts:
    458
    When a player have health=0 will you exit him from the map ?
    -> you can directly use the function ExitGame() of MNetwork for that, it will disconnect the player from the network, make him load the game menu, and decrement the total player of the game.
    From that, to know if a player is now alone is the map, you can simply check if the total players number == 1 (-> stored in gameTotalPlayer in MNetwork): that will automatically mean than your player is now alone, and thus has win.

    Else, if the dead players stay on game, you'll have to store somewhere a list of dead players, or simple add this parameter in MUser (with a variable "isDead" for example). When a player dies, he will send a RPC to the server to tell him that he is dead, the server will update the playerList, and send this new playerList to the other players using a the RPC function RefreshUserList() which already exists:
    Like that --> networkView.RPC("Refresh UserList", RPCMode.Others, MUser.ListToString(playerList));
    ... and from that you can use this list to know who is dead and who is alive.
    For example when a player tells to the server that he is dead, the server may check the number of alive player, and maybe if the result is 1, he can send a RPC function to this last one player to tell him that he won the game, and also send an other RPC to the others player to tell that the game is finish and that xxx won the game.

    ... That's just some ideas, there are in fact many way to do that.
     
  40. ostrich160

    ostrich160

    Joined:
    Feb 28, 2012
    Posts:
    679
    Cheers mate. I guess all I need to do now is get MultiOnline and find a cheap, or even better free, web hosting service
     
  41. VirtuElle

    VirtuElle

    Joined:
    Jan 27, 2013
    Posts:
    458
    For the web hosting you can use AlwaysData (the free plan), that's free, and I used it for MultiOnline installation tutorial.
     
  42. ostrich160

    ostrich160

    Joined:
    Feb 28, 2012
    Posts:
    679
    Perfect, thanks!
     
  43. dceevp

    dceevp

    Joined:
    Mar 4, 2013
    Posts:
    19
    how can i load different scenes in game? like Diablo 3 : 2 player in "city" and 3 players in "dungeon" but the 5 players in the same game or instance
     
  44. kinghack

    kinghack

    Joined:
    Nov 30, 2013
    Posts:
    54
    I fixed the Table just like you said and I used the Foreign key constraint (INNODB) to link it to " Game . users . id "
    just not sure what I gotta do next in the MOUser.class.php file.
     
  45. VirtuElle

    VirtuElle

    Joined:
    Jan 27, 2013
    Posts:
    458
    You decide which player will be in which scene and you load him on this scene.
    Currently, the scene is load from MNetwork, with StartGame() function, so you can use this function to choose the scene to load.
    But the problem is that by default you will see all the players, even if they are not in the same scene as you. So, when a player is spawned on a scene, he will have to check all the players which are on the map with him, and disables all the players which are actually not in his game scene.
    The function DisabledPlayer() in MNetwork disables all the players, so it can give you an idea about how disabling players.
     
  46. VirtuElle

    VirtuElle

    Joined:
    Jan 27, 2013
    Posts:
    458
    First, you have to create the page from where the game will exchanged data with the web server: it will receive inputs and display outputs. That's not MUser.class.php, that's the page from where you will call functions from MUser.class.php. You can call this page as you want, "itemsManagment.php" or something like that (this page will look like backlistUser.php).

    In MOUser.class.php (for example, because you are not obliged to put your functions there), you can put all your functions to manage your new table -> the functions to add an item, to update data, to delete an item.
    And you will call these functions from your first page ("itemsManagment.php ").

    And in MOServer, you will add some WWW functions to exchange data from this page ("itemsManagment.php "), to get it in game.

    ... Maybe it looks quite complicate, in fact that's maybe quite boring to do, but it's not very difficult.
    I had done a tutorial (pdf) about how add a new field in users table, that's not exactly the same thing as you want to do, but it may help you to understand how make all these things work together... But I don't know how join a file from this new forum system, so if you know, you can tell me, else send me please your e-mail address (by private message if you want) so that I can send you this tutorial.
     
  47. AlanPT

    AlanPT

    Joined:
    Jul 31, 2013
    Posts:
    32
    Sorry if this has already been asked. Where do you go to change the default amount of players?

    On a side note, VirtuElle have you considered more minimal demo examples for both multilan and multionline. Just a username and bam you're in. I am assuming it is what 80% of what new users would want to learn from or use.
     
  48. VirtuElle

    VirtuElle

    Joined:
    Jan 27, 2013
    Posts:
    458
    Directly from the inspector, in Menu scene, on MMenu object: in "Players options". That's explain in documentation part 4.2 - page 37.

    I would love doing much tutorial, the problem is that it takes me a lot of time, because english is not my first language. So doing video with all the subtitles, or write a full tutorial is something pretty difficult for me. So I do it when it's really necessary (as installation or change player), but I can't do it for everything (else, I have no more time to develop my next version of MO).
    But about display the username (I think your talk about it), I understood that many people want this, so that's a feature planned in the V3.
     
  49. AlanPT

    AlanPT

    Joined:
    Jul 31, 2013
    Posts:
    32
    Thanks, but what I mean is having a pre-filled number in the box that isn't 1 (It currently says 1 for me).



    I am suggesting a more basic version of this not a tutorial. One where all it needs is a username to start it. Removing the current complexity. This would be useful for people like me who create virtual worlds instead of multiplayer games. Thanks again for this asset, it has been very useful.
     
  50. VirtuElle

    VirtuElle

    Joined:
    Jan 27, 2013
    Posts:
    458
    Ok, in this case it's directly in MOMenu script, in Start function(), line 291 :
    By default, the variable takes the value of the minimum players, but you can change this value and put what you want.

    Code (CSharp):
    1. // Define min players  
    2. formCreatePlayers = m.minPlayers;    
    Sorry, I totally misunderstood !
    That's an interesting idea, I will think about it, I could for example put the password as an option which could be disabled or enabled from inspector.