Manually add new PhotonPlayer

Hi all,

I am new here! Doing our first multiplayer project. Quick question.

Is it possible to 'manually'/locally add new PhotonPlayers?

Something like:

PhotonPlayer newPlayer new PhotonPlayer(false, 1, "AIPlayer");
PhotonNetwork.Add(newPlayer)?

Pretty pseudo, but I am looking into having my AI characters be more like real players without the controls.
In this case have a photonplayer class as well (so I can easily sync properties).

Thanks,
Pieter

Comments

  • Hi,

    no you can't do this like that, but what you can do is creating Scene Instances, and that actually does what you want, npc and AI characters. They will be controlled by the MasterClient, it's a special client assigned the role of the "server" in a way, and so if the computer who is currently the masterClient gets disconnected, another player takes on the role of masterClient, and SceneObjects are not lost.

    If you need more details, let me know.

    Bye,

    Jean
  • Thanks for the reply, I was heading in a different direction but your reply has put be right back.

    Can you help me with 'manually' creating scene objects? I can't rely on InstantiateSceneObject for this project.

    What do I have to set besides the viewID to make it a scene object?

    Thanks,
    Pieter
  • Hi,

    that's what I meant, using InstantiateSceneObject. Can you explain why it's not suitable?

    Bye,

    Jean
  • Thanks for your reply! Much appreciated!
    I fixed it by using AllocateSceneViewID(). I can't believe i missed this... sorry for the confusion.
    Everything is almost working as expected. WHen master leaves all ai created by the master persist for other players.

    However, when the old master rejoins the AI opponents aren't recreated. Almost as the buffered RPCs are removed. I am using AllBuferedViaServer.

    Any ideas?

    Cheers,
    Pieter
  • Hi,

    I am not sure I understands :)

    -- the concept of "old master": there is only one masterClient, and if that player leaves the room, another master is assigned, but it doesn't keep track of the previous master.

    -- if objects persists, why are you saying objects are not recreated? I am confused here too.

    Maybe you can detail more of the process? Thanks.

    Bye,

    Jean
  • My apologies for the late reply - deadlines were looming so I had to put a lock on the functionality I had.
    Nevertheless, it might still be a good idea to figure this out (for future reference as well)

    Let's go back to the beginning ;)

    I need(ed) an AI management system - meaning I would fill up the room with AI until we have as much players as would be allowed when playing with real people. If someone joins I would delete an AI, when someone leaves I would add one.

    Normally I would create an AI (technically) as close to a real player as possible. Not necessarily its behavior but structure and setup. Only its 'controller' would be different - that is where my original question (using new local PhotonPlayers) came from. A bit confusing - I know - but my AI characters are a 'PhotonPlayer' as well. Long story short no issues here.

    Then I ran into the issue on scene objects (being new to this all). AIs were removed when the masterclient left if they didn't have a sceneview allocated. Stupid of me - fixed this too ;)

    Then everything seem to work fine. However when the masterclient left the it would take all the RPCs with him. I created my AIs with the AllBuffered target. For each new player joined the AIs would be created for him. All AIs would also still be there when the masterclient left and the room was still alive. However new or returning players would not have the AIs created since the RPCs are gone.

    If fixed this by implementing the AllGlobalBuffered as described in this post

    So now I kinda had what I was looking for, but my intention was/is that an AI should be created/removed when a player leaves/joins. I cannot find a way to 'edit' or remove those RPCs when globally buffered.
    For example when PlayerXXX joins I remove AI01 and its RPC. I don't know how to do this. Is this possible at all? So with this setup I would only be able to add new AIs but not remove them - unless I would RPC their removal globally buffered as well. I am sure you understand I am not going that way ;)

    At the moment I implemented a different approach since the final deadline is looming. I store some basic AI data in the roomproperties. When a new user joins the masterclient removes an AI and updates the roomproperties. The new user uses the roomproperties to build and sync the AIs available.
    It is working and I think it is production-worthy but it feels as a bit of a hack.

    I hope you understand it all ;) and maybe can shed some light on:
    - why isn't allglobalbuffered and othersglobalbuffered not implemented by default in PUN?
    - can you (manually) remove specific RPCs that are globally buffered?
    - any ideas/tips on the above?
    -
    Thanks!
    Pieter


  • Hi,

    no, unfortunatly, you can't edit buffered rpc. It's something hot in internal discussions to be able to edit a particular buffered RPC, so we are aware of this, but no solution yet unfortunatly.

    using the room properties make a lot of sense, it's indeed the most reliable source of data for newcomers, so I would indeed go down that way too.

    Bye,

    Jean