Search Unity

Third Party Mirror - Save original player who dropped an item and verify orignal player later

Discussion in 'Multiplayer' started by Olffff, Nov 10, 2022.

  1. Olffff

    Olffff

    Joined:
    Jan 19, 2021
    Posts:
    1
    Hi,

    This is gonna be hard to explain. I am trying to build a game where 2 players can drop their limbs and then later pick them up again. When the limbs are either dropped/thrown, my script instantiates new objects into the scene which are server owned.
    There is a special case where if a limb is thrown out of the world it should return to the orginal player who dropped it. My question is how do i best save and verify the identity of this player when the limb is dropped and later pickedup when it falls out of the world. In short i need away to save the orginal owner of an object and later return this object to the same owner.

    I was thinking of saving the network identity to the script when the limb is instiated and then using that to verify.
    If anyone got any suggestions please reply!

    On Instantiate(on the playerScript):

    Code (CSharp):
    1. newSceneObject = Instantiate(wrapperSceneObject, position, rotation);
    2. SceneObjectScript = newSceneObject.GetComponent<SceneObjectItemManager>();
    3. SceneObjectScript.orignalNetworkIdentity = getComponenet<NetworkIdentity>(); //set the identity here
    4.  
    On fall out of world (inside the cript for the limb/object)

    Code (CSharp):
    1. public void HandleFallOutOfWorld()  {
    2.        if(orignalNetworkIdentity == localplayer.getComponenet<NetworkIdentity>()) //verify the identity here
    3.         {
    4.             itemManager.CmdPickUpLimb(gameObject);
    5.             itemManager.ReturnControllToPlayer();
    6.         }
    7.     }