Big problem with loading saved data

Options
Hey there,
i'm really messing arround with some stuff already alot of days now and my head starts burning!

Maybe you can help me.

When a player joins the server i want to load his gold, level and exp points and sync it over the network so that the stats are visible for everyone.

Im using an RPC for this but every player who joins the game just get my own stats. When i'm level 15 with 100 gold, everyone is level 15 with 100 gold out of my perspective.

Take a look:

Call the RPC (script is laying on player prefab):

GetComponent<PhotonView>().RPC("LoadSafedPlayerData", PhotonTargets.AllBufferedViaServer);

Run the RPC (same script) includes some database stuff but should not matter here:
 [PunRPC]
    void LoadSafedPlayerData()
    {
        new GameSparks.Api.Requests.LogEventRequest() // Database Stuff
                .SetEventKey("LOAD_PLAYER") // Database Stuff
                .Send((response) => // Database Stuff
                {
                    if (!response.HasErrors) // Database Stuff
                    {
                        GSData data = response.ScriptData.GetGSData("player_Data"); // Database Stuff

                        level = int.Parse(data.GetString("playerLevel")); // here it starts to set the amounts
                        gold = int.Parse(data.GetString("playerGold"));
                        exp = int.Parse(data.GetString("playerXP"));
                        weaponLv = int.Parse(data.GetString("weaponLevel"));
                        playerName = data.GetString("playerName");
                });
    }
So how can i say that only the rpc's caller set his own values an not the ones of the other. I can simply call it withouth an rpc but than it's not synchronized over the network.

Thank you guys!

Sorry for my english, german is my native language and i'm really in rage mode at the moment.

Hope you can help me :)

Comments

  • JohnTube
    JohnTube ✭✭✭✭✭
    edited October 2016
    Options
    Hi @JannickL,

    My guess is that you are using GameSparks to load player data of the local player (authenticated GameSparks user) in all players' PhotonViews on every player join. So the local player will see his data in all others. The "LoadSafedPlayerData" should be called for local player only (maybe use photonView.isMine) and then broadcast result to others. Currently I think last call to "LoadSafedPlayerData" overrides all, so you should see values of last joined player in all players.

    You should load the player data from GameSparks cache it and then send it or call "LoadSafedPlayerData" when local player joins only.

    Try this:
    PhotonView photonView = GetComponent<PhotonView>();
    if (photonView.isMine) {
        photonView.RPC("LoadSafedPlayerData", PhotonTargets.AllBufferedViaServer);
    }
  • JannickL
    Options
    Thank you @JohnTube. Do you have a example for broadcasting the results to other?

    I will try this out later :)
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Maybe you can try another PunRPC that sends actorNr and respective data but it would be better to just use actor properties in the first place and even get rid of "LoadSafedPlayerData".
  • JannickL
    Options
    What do you mean with actor properties, is it photons player custom properties?

    Thank you :)
  • JohnTube
    JohnTube ✭✭✭✭✭
    Options
    Yes exactly.