Search Unity

Third Party Photon Unity Networking

Discussion in 'Multiplayer' started by tobiass, Aug 23, 2011.

  1. StarGamess

    StarGamess

    Joined:
    Jul 21, 2014
    Posts:
    179
    Hey yea i fixed it. It had something to do with my script were it wouldn't want to spawn new players after a new scene was loaded fiixed it now and it works great tx!
     
  2. TooManySugar

    TooManySugar

    Joined:
    Aug 2, 2015
    Posts:
    864
    [QUOTE="It might be to combine Photon with Unity Analytics. What do you think?[/QUOTE]
    That could be a blast. Analytics offers such a ton of data. Even with the main stats you get a nice profile interested in your game. Basically I like the region, Age and the time they stay browsing.

    What I miss more at this game development phase is how long the players have been testing the game and how many of the existing players return to play it.. This could allow to evaluate how the new versions are welcome by the player mass.

    I'm at the gates of my new demo release so have no time for deep seeking but there was something like "heatmaps" that painted witch areas the player did run across and depending on the number of passes it did get a more contrasted color.

    But this last thing is probably in another level of complexity.
     
  3. jonkuze

    jonkuze

    Joined:
    Aug 19, 2012
    Posts:
    1,709
    @tobiass Currently I am using Photon Cloud with US, Europe, and Asia Regions. So far from what I see network performance and latency is pretty good with my game. Although i'm concerned that maybe say there are US players on the US Region, but someone from another Region decides to join US Region and becomes the Master Client. This would cause some latency issues between the US clients and a Master Client in another Region. There is no way to really solve this problem except for forcing all players to stay within their region.

    I don't really want to limit the players to a certain region especially if the player base in a certain region is lower than others. So allowing them to jump into other regions would make sense so we don't lose players overall.

    Now, my idea is to host 3 dedicated VPS Servers, one in each region. Each of these servers will say be responsible for hosting an X number of instances for that region. I would execute say 10 headless Master Clients on each server to start.

    The Master Clients would run persistently so that players can join and leave the game as they wish without any Ownership transfer ever happening. This would probably yield better performance overall because the Master Clients hosting the games in a certain region would never change. The hosting Master Client would remain in the respective region on our dedicated VPS. This would solve the latency or performance issue that could result from transferring Master Client responsibility to a client with poor bandwidth.

    Now I have two questions...

    1. Is this even possible? Can I actually run multiple headless clients (unity instances) on say a Linux VPS that auto connects to Photon Cloud and Creates (hosts) Rooms persistently?

    2. If this is possible, from your experience would you say this is a good investment and would it yield greater performance for my multiplayer game vs just using Photon Cloud with Region select and allowing players to handle Master Client responsibilities?

    I think it would improve performance by eliminating Master Client / Ownership transfer to clients with poor bandwidth but by how much? I have no way to really know if the performance gain is truly significant. Have you seen anyone with a similar setup? I really don't want to use an Authoritative Server. Although ideally I would use an Authoritative Dedicated Server to manage everything if I could afford it that is. So this my indie work around idea for setting up a dedicated server environment for my game. Could it work? Please share your thoughts.
     
  4. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    Hehe. Most of this is quite a bit of work, if someone wants to present the data in a meaningful way.
    As you want all this data, take a look at Unity Analytics. Afaik, even the heatmaps are planned (or already there). It's what you need and what you can use right now.
    If you can make a modular package which pushes PUN "events" to Analytics, you might have something really nice for the Asset Store, too :)
     
  5. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    Sure it's possible. You can host a bunch of clients and monitor then to make sure they keep running. They can create new games every now and then to adjust to demand and run as long as you like. Any real client could be restricted to joining and only creating another room if every other room is full..

    If it makes a big difference, is another question. One I can't answer, actually. If you want to know how much better things might be, you could try it out with a simpler test solution and measure things.
    It might make a some sessions better. As there is only limited supply of those master clients, players might notice other games (not running on them) being sluggish instead. It's quite some work.

    I would probably try other solutions first.
    Games have a tradition of cheating the user, so you can fake a lot of stuff if synchronization is not perfect. At least, if it's not a competitive game for money prices.
    You can send AI updates as "target positions" and "actions" or "state of mind", if you will. Instead of moving the AI and sending positions, you can send some target location and a time when they have to arrive. This way, clients can move the AI without new input for a while.
    Clients that use another region should never create games. The latest versions of PUN and the Photon Cloud support Server-Side Master Client switching. If someone's ping is bad, assign a new Master Client. You could measure how long a player is usually playing and prefer those with long sessions and good ping.

    Don't get me wrong: I'm not saying those changes will fix the issue completely. They will just hide the problem to some degree. I just think the alternative is really complex, too.
     
  6. jonkuze

    jonkuze

    Joined:
    Aug 19, 2012
    Posts:
    1,709
    Thanks for reply! So this Server-Side Master Client switching, this is working already in latest version of PUN and Photon Cloud service? If so do I need to do anything special to enable this, or it just works? This is probably a better solution to the issue I'm trying to address. It would be great then if Master Client switches over to the person with the best Ping, that would be ideal. Please Let me know more about how to use this or point me to the instructions on how to set it up if there is any setup required that is.
     
  7. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    You don't need setup for the Master Client switching but the clients have to do the logic when to switch and who becomes the new Master Client. Then call: PhotonNetwork.SetMasterClient(PhotonPlayer nextMaster).
    Per player, you might want to set the ping as player property. I would also measure how long the sessions of the user are and set the average of that as another property. Based on that, the client logic can trigger a switch when the current Master Client doesn't do the job well.
     
    jonkuze likes this.
  8. Dimitrije

    Dimitrije

    Joined:
    Nov 7, 2013
    Posts:
    1
    I have question about Photon and does he have support for sport manager type of games.

    This type of games have large database, with lots of teams, players, statistics,...
    Server needs to calculate game results daily (so thats not realtime game, more is turn base).
    Its more like browser game.

    Is it smart to use Photon for this type of games or use traditional server with MySQL, php,...
     
  9. EmreB05

    EmreB05

    Joined:
    Aug 9, 2015
    Posts:
    13
    Photon doesnt stores permanent data so you cant use it as Database.
    What you can do is;
    Rather than going with Photon Cloud, go for Photon Server and use sqlLite as your server side database to handle all that stuff.
    Or, keep photon and database separate.

    Btw i dont think that you need a server to make this game since everything going to be stored at databases and actually as you mentioned nothing is realtime. If you are going to move players and make them see eachother during the matches and all that stuff, so yeah you need a server.
     
    Dimitrije likes this.
  10. CplMulder

    CplMulder

    Joined:
    May 12, 2014
    Posts:
    52
    I am just trying to understand this..... I bought the PUN+ version from the asset store because it seemed a good deal after reading the description it said "easily add multiplayer to your games and launch them globally with the included 100 concurrent user Photon Cloud life-time plan" (please note the word "games", plural) - however when setting up a realtime game up in the portal it defaults to free plan, to upgrade you have to either pay or redeem a PUN+ purchase by entering an invoice number etc. - here it however clearly states.... "apply once and for one app only"

    So am I understanding this correctly? - the PUN+ "lifetime plan" really is for one application only? you cannot split the 100ccu's over more than one app?

    Also if this is the case, we would not want to redeem the 100ccu lifetime coupon on any game until we are absolutely sure it is ready for production, this may be some time after development starts, so does the PUN+ purchase coupon expire at all?

    Please clarify

    Thanks.
     
  11. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    @CplMulder: Thanks for buying PUN+.
    I am sorry you are surprised by the way we handle the subscription for this package. It's not meant to be a scam but we never stumbled over the wording issue you point out.

    The idea was this: You can use the PUN+ package for any number of games you want to build. This part applies to "any number of games". For Unity 4, there is a clear benefit of this package, because it can export to Android and iOS without Unity Pro licenses. Unity 5 changed the licensing and technically you don't need the PUN+ package anymore in Unity 5.

    The included 100 CCU lifetime plan can only be applied to one subscription, yes. Technically, we can't split those 100 CCU into any number of games. But: You don't have to define (in our system) which game runs on a AppId, so you could switch any of your builds to use it. The 100 CCU plan stacks to whatever subscription you select on top.

    As you pointed out, the plural in "games" is not clear. We wrote that at Unity 4 times, when it made more sense.

    We want to enable your games, not to bother or hinder you. If you are unhappy about which AppId has the 100 CCU, get in touch by mail. Let us know what happened and how we could help. In the forum, you should not post your AppId though. Get in touch: developer@exitgames.com

    Hope that explains things. I will point the colleagues to this discussion. We'll see what they will come up with.
     
  12. MrGky93

    MrGky93

    Joined:
    Feb 27, 2014
    Posts:
    281
    how dificult is it to use it in a complete single player game to make a multiplayer game ??
     
  13. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    @Rayleigh2116: Totally depends on you and your game. There is no way to answer that in general, sorry.
     
  14. CplMulder

    CplMulder

    Joined:
    May 12, 2014
    Posts:
    52
    Thanks for your reply Tobiass,

    Apologies, did not mean to suggest it was in any way a scam :) - was just making sure I understand how it works, I do not want to waste my one free app on a test app. If we can use the same appid over many apps that is great we can test and production develop using that same id and the CCUs will in effect be shared. If this works I am a happy customer as I can in fact have more than one application using PUN+ and that was my main concern.
     
  15. mentolatux

    mentolatux

    Joined:
    Nov 2, 2014
    Posts:
    240
    i just update my game fps kit 2.0 with pun+ and im geting this error
    Illegal view ID:0 method: networkAddMessage GO:__Room
    UnityEngine.Debug:LogError(Object)
     

    Attached Files:

  16. sovalopivia

    sovalopivia

    Joined:
    Jul 25, 2010
    Posts:
    2
    I have set players in my game to be subscribed to particular groups using

    Code (CSharp):
    1.  
    2. PhotonNetwork.SetSendingEnabled(enabledGroups, disabledGroups);
    3. PhotonNetwork.SetReceivingEnabled(enabledGroups, disabledGroups);
    4.  
    After then joining the room with a number of players I call raiseEvent on one, with some Options set.

    Code (CSharp):
    1.  
    2. var opts = RaiseEventOptions.Default;
    3. opts.InterestGroup = (byte)_pv.group;
    4. opts.CachingOption = EventCaching.AddToRoomCacheGlobal;
    5. opts.Receivers = ReceiverGroup.All;
    6. PhotonNetwork.RaiseEvent(b, content,true, opts);
    7.  
    Note that I have use the group field on the instantiated player's PhotonView to store which group they should be sending RaiseEvents to.

    When I run this test, and fire off events, they successfully trigger for the right other players, and excluding those subscribed to the other group. However, the one sending the event doesnt receive the event. For a while I did not have Receivers set to all, but even after adding that, the local player will not receive the event.

    Interestingly if i send an event on the global 0 Interestgroup, the event will trigger on the local player as well as others.

    Is there something obviously wrong that I am missing with this setup? What I want to achieve is the player can send RaiseEvent to their allocated InterestGroup and also receive the event themselves.

    EDIT:

    I read in the code documentation that using CachingOption disables most of the other options, and commented it out as a test, but the results are still the same.

    Code (CSharp):
    1.  
    2. var opts = RaiseEventOptions.Default;
    3. opts.InterestGroup = (byte)_pv.group;
    4. opts.Receivers = ReceiverGroup.All;
    5. PhotonNetwork.RaiseEvent(b, content,true, opts);
    6.  

    I am running
    Unity 5.1.0f3
    PUN 1.51
     
    Last edited: Aug 19, 2015
  17. yumianhuli1

    yumianhuli1

    Joined:
    Mar 14, 2015
    Posts:
    92
    Can I use PUN(free) to replace Unity Network class for client C/S ?By changing Hosting setting (From Photon cloud to self hosted) that I can use it in my server without thinking about Pcloud and ccu?
     
    Last edited: Aug 19, 2015
  18. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    Yes, you can turn your "old Unity Networking" project into a PUN project relatively easy.

    When using PUN, you need some Photon Server. You can buy a license for it and host it yourself, or you can let us manage the servers and just pay for the CCU you actually need. Neither is completely free. If you have a server running or a good hosting deal, get a "One Off" license for Photon Server.
     
  19. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    Does FPS Kit support Photon Networking out of the box?
    If you get this error, some PhotonView did not get a viewID (0 being the default). You should use PhotonNetwork.Instantiate() to instantiate characters (anything with a PhotonView) or you can add the GO to the scene (then the Editor assigns a viewID > 0).
     
  20. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    You can use the AppId for one game or another and you can re-assign the ID for your games. While technically possible, you should not share the CCU across all your games.
    Durind development, use 20 CCU subscriptions for free. If you need CCUs to showcase a game, get in touch: developer@photonengine.com.
     
    CplMulder likes this.
  21. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    I checked the case and it seems to be not working at the moment. I would expect this to work, too and will check if this is a problem we can fix server side. Please send me a private message or mail me, so I could keep you up to date about progress. Mail: developer@photonengine.com and refer to this post please.
     
  22. sovalopivia

    sovalopivia

    Joined:
    Jul 25, 2010
    Posts:
    2
    HI Tobias, thanks for the reply I have followed this up with an email. :)

    Since posting I have also encountered a similar issue with RaiseEvents, and InterestGroups.

    I have a basic test setup allowing players to join rooms, be partitioned in to groups, and RaiseEvents targeted at other players in the same group. Players can trigger events with InterestGroup set to their own group or 0, and both types are set to AddToRoomCache.

    After adding some players, sending events I join with some more players. Because the raised events are all cached I would expect them to receive all the relevant events, however newly joined players only receive the events sent to InterestGroup 0, not ones that match their interest group.

    Below is the code for this test setup.


    Code (CSharp):
    1. public class NetworkConnectTest : MonoBehaviour
    2. {
    3.     void Start ()
    4.     {
    5.         PhotonNetwork.ConnectUsingSettings("0.1");
    6.     }
    7.  
    8.     void OnJoinedLobby()
    9.     {
    10.         PhotonNetwork.JoinOrCreateRoom("RoomName", new RoomOptions(), TypedLobby.Default);
    11.     }
    12.  
    13.     void OnJoinedRoom()
    14.     {
    15.         var group = PhotonNetwork.player.ID % 2 == 0 ? 1 : 2;
    16.         var enabledGroups = new[] { group };
    17.         var disabledGroups = new[] { 3, 4 };
    18.         PhotonNetwork.SetSendingEnabled(enabledGroups, disabledGroups);
    19.         PhotonNetwork.SetReceivingEnabled(enabledGroups, disabledGroups);
    20.  
    21.         var go = PhotonNetwork.Instantiate("MultiPlayer", Vector3.zero, Quaternion.identity, group);
    22.     }
    23. }
    Code (CSharp):
    1. public class RaiseEventTest : MonoBehaviour
    2. {
    3.     private PhotonView _pv;
    4.  
    5.     void Awake()
    6.     {
    7.         _pv = GetComponent<PhotonView>();
    8.  
    9.         SetGroup();
    10.     }
    11.  
    12.     void Update()
    13.     {
    14.         if (Input.GetKeyDown(KeyCode.E))
    15.         {
    16.             RaiseEventGroup();
    17.         }
    18.  
    19.         if (Input.GetKeyDown(KeyCode.R))
    20.         {
    21.             RaiseEventAll();
    22.         }
    23.     }
    24.  
    25.  
    26.     public void SetGroup()
    27.     {
    28.         if (!_pv) _pv = GetComponent<PhotonView>();
    29.         if (!_pv.isMine) return;
    30.         PhotonNetwork.OnEventCall += OnEventRaised;
    31.  
    32.         var group = PhotonNetwork.player.ID % 2 == 0 ? 1 : 2;
    33.         _pv.group = group;
    34.     }
    35.  
    36.     public void RaiseEventGroup()
    37.     {
    38.         if (!_pv.isMine) return;
    39.  
    40.         var group = (byte)_pv.group;
    41.  
    42.         var opts            = RaiseEventOptions.Default;
    43.         opts.InterestGroup  = group;
    44.         opts.CachingOption  = EventCaching.AddToRoomCache;
    45.         opts.Receivers      = ReceiverGroup.All;
    46.  
    47.         // For some reason InterestGroup > 0 means the event isnt called on the local player,
    48.         // and must be done manually
    49.         PhotonNetwork.RaiseEvent(   NetworkEventCode.Group, null, true, opts);
    50.         PhotonNetwork.OnEventCall(NetworkEventCode.Group, null, PhotonNetwork.player.ID);
    51.     }
    52.     public void RaiseEventAll()
    53.     {
    54.         if (!_pv.isMine) return;
    55.  
    56.  
    57.         var opts            = RaiseEventOptions.Default;
    58.         opts.CachingOption  = EventCaching.AddToRoomCache;
    59.         opts.Receivers      = ReceiverGroup.All;
    60.  
    61.         PhotonNetwork.RaiseEvent(NetworkEventCode.All, null, true, opts);
    62.     }
    63.  
    64.     private void OnEventRaised(byte eventcode, object content, int senderid)
    65.     {
    66.         if (!_pv.isMine) return;
    67.         Debug.LogError(string.Format("{0} sent event: {1}", senderid, eventcode));
    68.     }
    69. }
     
    Last edited: Aug 20, 2015
  23. MrGky93

    MrGky93

    Joined:
    Feb 27, 2014
    Posts:
    281
    has somone tuts ??
    On youtube ?? ´How to using it
     
  24. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    We implemented this some time ago, so I don't know this out of my head: I have to check if the InterestGroup overrides the caching or the other way round. Only one works.
    Let's continue by mail (for me, this is too complex for this thread). I think I can touch base tomorrow.
     
  25. mentolatux

    mentolatux

    Joined:
    Nov 2, 2014
    Posts:
    240
    i have this problem when i chat and sent mesage plzz help
     

    Attached Files:

  26. yumianhuli1

    yumianhuli1

    Joined:
    Mar 14, 2015
    Posts:
    92
    Thank U tobiass!When I set up my own server and use One-ff license,I need set up photon software to simulate photon cloud enviroment?
     
  27. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    @mentolatux: That is a UI issue which is not directly related to PUN. Better look for help in a scripting or UI forum.

    @yumianhuli1: The Photon Server SDK comes with a "LoadBalancing App". This is a replacement for the Photon Cloud logic, so it's compatible with PUN. Read this How to start a Photon Server here.
     
  28. StarGamess

    StarGamess

    Joined:
    Jul 21, 2014
    Posts:
    179
    Hey can anybody tell me how many active monthly users 100CCU will be able to handle. This is my first game to use multiplayer so i have no idea how many people play at the same time. My last game had about 2000 downloads every month. Will 100CCU be enough for that?
     
  29. bertelmonster2k

    bertelmonster2k

    Joined:
    Apr 3, 2009
    Posts:
    78
    based on our experience the following formula applies:
    CCU: Concurrent users
    DAU: Dail Active = 20 * CCU
    MAU: Monthly Active = 20 * DAU

    So 2,000 downloads (assuming ALL play multiplayer) will lead to 100 DAU and 5 CCU. Sorry I guess you liked to hear much more ;). But the good news is that you may even get along with the free pan. But you are in the save side with 100CCU (= ~2,000 DAU = ~40,000 MAU).
     
  30. StarGamess

    StarGamess

    Joined:
    Jul 21, 2014
    Posts:
    179
    Ah well that great that means i can release it for free ;D if needed i can still by photon + which has a 100CCU right? Also I really dont care how many people play it. As long as they really like it for me its worth putting time in. I make these games in my spare time and rarely spent more then a 100$ dollars in a project. So i dont need to make money of them i just like to make good games that people like. My biggest request for my last game was to add co-op, i always like photon so i figuared i would give it a shot and try. Only thing i was worried about was that servers would be to expensive. Good thing that isnt a problem any more.
     
  31. RC_Number_1

    RC_Number_1

    Joined:
    Aug 23, 2015
    Posts:
    4
    I am new to unity, and programing in general and I was able to find a tutorial for PUN free on youtube and I could connect to the servers fine.(a month or two ago). I dont know what version I had used. I now tried that code today, and it won't work. the code looked like this...

    using UnityEngine;
    using System.Collections;

    public class NetworkManager : MonoBehaviour
    {
    void Start ()
    {
    Connect ();
    }

    void Connect ()
    {
    PhotonNetwork.ConnectUsingSettings ("MultiFPS v001");
    }

    void OnGUI ()
    {
    Debug.Log ("GUI");
    GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString ());
    }

    void OnJoinedLobby ()
    {
    Debug.Log ("OnJoinedLobby");
    PhotonNetwork.JoinRandomRoom ();
    }

    void OnPhotonNetworkRandomJoinFailed ()
    {
    Debug.Log ("OnPhotonNetworkRandomJoinFailed");
    PhotonNetwork.CreateRoom (null);
    }
    void OnJoinedRoom()
    {
    Debug.Log ("OnJoinedRoom");
    }


    }





    I was wondering if the update made this code outdated, and if so what is the code that would work, or where can I find it?
    What this is supposed to do is
    connect it to the cloud
    joins the lobby
    joins a room
    creates a room if none are present, then joins it

    what it is doing is only connecting to the servers.

    what I get in Unity is this...

    upload_2015-8-23_15-18-4.png


    If you dont know what I am talking about, is there any way to install an earlier version of PUN free?
     
    Last edited: Aug 23, 2015
  32. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
  33. RC_Number_1

    RC_Number_1

    Joined:
    Aug 23, 2015
    Posts:
    4
    Thanks! It worked
     
    tobiass likes this.
  34. RC_Number_1

    RC_Number_1

    Joined:
    Aug 23, 2015
    Posts:
    4
    so, I got past that part, but thats as far as it will go. It is supposed to now supposed to join a random room, and if it fails, it creates and joins a room automatically. It wont do that though. It worked for the guy on youtube where I found it. And again, it was all working a few months ago. I am confused again. Is there another setting I need to change?

    this is now what I get.

    upload_2015-8-24_10-1-29.png




    with this script...


    ------------------------------------------------------------------------------------------------------------------------------------------------------------
    using UnityEngine;
    using System.Collections;

    public class NetworkManager : MonoBehaviour
    {

    // Use this for initialization
    void Start ()
    {
    Connect ();
    }

    void Connect ()
    {
    Debug.Log ("Connected");
    PhotonNetwork.ConnectUsingSettings ("MultiFPS V001");
    }

    void OnGUI ()
    {
    Debug.Log ("GUI");
    GUILayout.Label (PhotonNetwork.connectionStateDetailed.ToString ());
    }

    void OnJoinedLobby ()
    {
    Debug.Log ("JoinedLobby");
    PhotonNetwork.JoinRandomRoom ();
    }

    void OnPhotonRandomJoinedFailed ()
    {
    Debug.Log ("RandomJoinFailed");
    PhotonNetwork.CreateRoom (null);
    }

    void OnJoinedRoom()
    {
    Debug.Log ("JoinedRoom");
    }

    }
    ------------------------------------------------------------------------------------------------------------------------------------------------------------
     
  35. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    That's not a setting, but part of the code you got.
    You probably should do the Marco Polo Tutorial, before you continue. It should explain the basics and what callbacks there are and how you can use them.
    Actually code the steps. Try to make it work. Then you will see where / how rooms get created.
     
  36. RC_Number_1

    RC_Number_1

    Joined:
    Aug 23, 2015
    Posts:
    4
    ok. thanks
     
  37. Demonith88

    Demonith88

    Joined:
    Jun 30, 2014
    Posts:
    216
    Plz help i use MFPS with photon and i have this errors
     
  38. mentolatux

    mentolatux

    Joined:
    Nov 2, 2014
    Posts:
    240
    delete folder plugin and photon network and update again from assets store
     
  39. yumianhuli1

    yumianhuli1

    Joined:
    Mar 14, 2015
    Posts:
    92
    Who create room ,so who is the host of client-server now.But,can I select the client-server randomly or designated
    by using PUN?A example?
     
  40. Shears

    Shears

    Joined:
    Jul 7, 2015
    Posts:
    24
    Im trying to get the enemys to sync on all players screen when they spawn but im coming across an error. I fully understand the error and why it is happening im just not sure how to fix it.

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. public class ZombieSpawn : Photon.MonoBehaviour {
    4.    private float minRepeatRate = 1f;        //Lowest Random Spawn Rate (Keep at 1 for best results)
    5.    private float maxRepeatRate = 1000f;    //Highest Random Spawn Rate (Will increase random spawning time if decreased and will decrease random spawning time if inscreased)
    6.    public float spawnTime = 15;            //Time Before Enemies Spawn
    7.    public float repeatRate;                //
    8.    private float furthestDistance = 0.0f;    //Finds Furthest Distance from player
    9.    private float distance = 0.0f;            //Find all Disrances from player
    10.    public Transform[] SpawnPoints;            //Holds All Spawn Location information
    11.    private Transform furthestSpawnPoint;    //Holds Position of the current Furthest Spawn Location
    12.    private Transform PlayerTransform;        //Holds Players position
    13.    public GameObject[] Zombie;            //Array of Enemies to spawn, Add as many different enemies you want to spawn in the Inspector area.
    14.    void Update ()
    15.    {
    16.         repeatRate = Random.Range (minRepeatRate, maxRepeatRate);    //Randomizes Repeat rates
    17.        if (repeatRate <= 1.74)                                   // Increase This To Spawn Enemys Faster
    18.        {
    19.            Invoke ("SpawnEnemy", spawnTime);                        // Spawn Enemy
    20.        }
    21.    }
    22.    [PunRPC]
    23.    void SpawnEnemy()
    24.    {
    25.         PlayerTransform = GameObject.FindWithTag("Player").transform;    // Gets Current Players Transform
    26.        foreach(Transform point in SpawnPoints)                           // Stores Distances from player to spawnpoints
    27.        {
    28.             distance = Vector3.Distance(PlayerTransform.position, point.position);
    29.            if (distance > furthestDistance)
    30.            {
    31.                 furthestDistance = distance;
    32.                 furthestSpawnPoint = point;
    33.            }
    34.        }
    35.        int enemyIndex = Random.Range (0, Zombie.Length);                // Picks a random Enemy
    36.         PhotonNetwork.Instantiate (Zombie[enemyIndex], furthestSpawnPoint.position, furthestSpawnPoint.rotation, 3); // Spawns a Random Enemy at a Random SpawnSpot
    37.  
    38.    }
    39. }

    The Error I get is:

    Code (CSharp):
    1. /Scripts/ZombieSpawn.cs(45,31): error CS1503: Argument `#1' cannot convert `UnityEngine.GameObject' expression to type `string'
    The error is appearing because "Zombie[enemyIndex]" is a Game object. And im guessing it needs to be a string.

    and With how I have THIS particular script where I cannot just use the prefab name for a string.
    because it grabs a random enemy prefab from the enemyIndex(array) line above the instantiate line.

    There must be some type of work around here, unfortunatly I have not learned this yet..

    Any help is appreciated once again. thanks
     
  41. superluigi

    superluigi

    Joined:
    Feb 6, 2013
    Posts:
    38
    I'm trying to have a waiting room where every player is assigned to the same player slot across all clients. So if player1(masterclient) has tobiass as player 2, superluigi as player3, and photonUser123 as player 4 I want tobiass, superluigi, and photonUser123 to have them in that same order as well. I'm trying to make everyone's list match the masterclient's.


    var p2 : boolean = false;
    var player2 : PhotonPlayer;

    function OnPhotonPlayerConnected( other : PhotonPlayer )
    {
    if(PhotonNetwork.isMasterClient)
    {
    if(!p2)
    {
    p2 = true;
    player2 = other;
    photonView.RPC("AssignPlayer2", PhotonTargets.AllBuffered);
    print(player2.name);
    }
    }
    }

    @RPC
    function AssignPlayer2()
    {
    // player2 = player2;
    //I though this would work by sending the RPC to have their player2 match my player2
    //but then I realized that this would make their player2 match their player2 (which is null)
    }
     
  42. superluigi

    superluigi

    Joined:
    Feb 6, 2013
    Posts:
    38
    @yumianhuli1 Whoever creates the room is the Master Client. I guess you can see the Master Client as the host. If the Master Client leaves then someone else needs to become the Master Client. When you create a room Pun creates it in the servers and people join the room as long as there is room, it is open, and visible. If you don't give the room a name when you create it then PUN will make up a name randomly. Sorry if this doesn't really answer your question. I had trouble understanding what you were trying to ask.
     
  43. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    @Shears: I replied in your other thread just now.
    @superluigi: Each client in the room has a number which is the same across all clients. The PhotonPlayer.ID can be used for ordering the players. The sequence of IDs can have gaps, because player might leave anytime but you can store your own playernumber in a custom property, so you have slots 1..4 assigned (e.g.).
    To store this, you can turn it around: In a room, you could store the players "p1".."p4" as Custom RoomProperty and the value for each contains a PhotonPlayer.ID. That defines which player ID uses which player number in an accessible, easy way.
     
  44. superluigi

    superluigi

    Joined:
    Feb 6, 2013
    Posts:
    38
    @tobiass When I first read your answer I was confused, but of course I tried to solve it myself first with some testing. After some testing I figured out what you meant by "The sequence of IDs can have gaps". I noticed that if PhotonPlayer.ID2 leaves and rejoins, suddenly he is PhotonPlayer.ID3 meaning that PhotonPlayer.ID2 does not ever get reused, photon just keeps adding and adding numbers.
     
  45. yumianhuli1

    yumianhuli1

    Joined:
    Mar 14, 2015
    Posts:
    92
    Although it is not the purpose of my question,but thanks !
     
  46. superluigi

    superluigi

    Joined:
    Feb 6, 2013
    Posts:
    38
    @yumianhuli1 What is your question again? It confused me a little, try re writing it again. We are all glad to help if we can.
     
  47. superluigi

    superluigi

    Joined:
    Feb 6, 2013
    Posts:
    38
    what is the difference between SetCustoomProperties and customRoomProperties? I've been trying to use SetCustomProperties for the past 2 days but i haven't been able to get it to work. I've asked questions on unity answers and the photon forums but nobody answers. Now I tried using customRoomProperties for roomOptions and so far no errors. I don't know if I'll be able to get it to work but at least I can move forward. I used
    roomOptions.customRoomProperties = new ExitGames.Client.Photon.Hashtable();.
    I have never seen ExitGames.Client.Photon.Hashtable() mentioned at all in the API. Where do we find this information?
     
  48. superluigi

    superluigi

    Joined:
    Feb 6, 2013
    Posts:
    38
    Is there a way for me to Debug.Log(customProperties of this room).
     
  49. MT3

    MT3

    Joined:
    Nov 14, 2013
    Posts:
    12
  50. jprocha101

    jprocha101

    Joined:
    Apr 8, 2015
    Posts:
    134
    @tobiass
    Hi - I am creating a turn based game. 2 players per match, a player can have multiple matches at once. The players will send some type of media back and forth (small audio or image file one at a time per match). I want the sending player to be able to send while the receiving player is offline. Once online the receiving player would get the media and at that point it would be stored on the player's device.

    Would the free photon plan work for that or would I also need the paid server plan?

    Or possibly store on the sending player's device until the receiving player is online?

    Thanks!