General Idea/Concept on Masterobject that controls playerindepent variables in FPS Game?

Hey,

So Im currently trying myself on Photon and made some great progress and learned a lot.
But I stumbled upon the Problem, that I dont have one script that knows playerindependet variables like team money or time and stuff.

My first attempt was to just give everyone a master script and that destroys itself, when the player is no the master. Problem is, if the player dies and respawn, the master script is freshly added with all variables set to 0. So I think, in shortterm i might save the variables in the PlayerPrefs, but if i want to add later some respawndelay after dying, that will not work either cause the script doesnt exist in this time.

My other Idea was, that the master spawns a gameobject (or it exists and everybody else destroys it) that sends RPCs out, but this will not work either (i think, havnt tried it yet), because the RPCs Methods must be on the same Gameobject, where they are called from.

So I tried reading myself into Photon Events but Im not 100% sure if its the right thing, and before I try way to long I wanted to ask some of you, if you know a smart way of fixing this problem.

Btw, I have a PlayerManager Script, that Instantiated the PlayerController, and if the Player (Controller) dies the Controller tells the corresponding Manager that he died and the Manager respawns the Controller. Because the Manager doesnt get destroyed I thought about just doing the first thing (giving the PlayerManager the Master script) but then the RPC calls didnt work on the Controller, because there is the ui I need to update. Maybe the PlayerManager can have all variables and the Controller asks him what these are, but I dont think this is the best solution.

Thanks for reading this and have a wonderful day

Best Answer

  • Tobias
    Tobias admin
    Answer ✓
    I would say it makes sense to put most of those values either in Room Properties or Player Properties. This way they are known to everyone and stored, no matter who leaves.

    It makes sense to have some GameManager to run as long as the client is in some room. You could write it in a way that only the Master Client updates values.

    To prevent hacking (to a degree) it might even make sense to try to verify whatever the Master Client sets as values (hits, scores, whatever).

    I think this is not an uncommon pattern.

Answers

  • Tobias
    Tobias admin
    Answer ✓
    I would say it makes sense to put most of those values either in Room Properties or Player Properties. This way they are known to everyone and stored, no matter who leaves.

    It makes sense to have some GameManager to run as long as the client is in some room. You could write it in a way that only the Master Client updates values.

    To prevent hacking (to a degree) it might even make sense to try to verify whatever the Master Client sets as values (hits, scores, whatever).

    I think this is not an uncommon pattern.
  • Hey Tobias,

    Im fairly new to Photon and didnt even know about Room Properties but they seem like they are exactly what I wanted.

    Thank you so much♥