Search Unity

Third Party Client Authority Problems Mirror

Discussion in 'Multiplayer' started by Opti66, Apr 19, 2021.

  1. Opti66

    Opti66

    Joined:
    Jun 29, 2018
    Posts:
    7
    Hello everyone,

    so I try to create this In Game Shop System. Everything works fine except the Sync for the Weapons you can buy in the Shop.

    So those weapons are defined buy the fitting Weapon Displayers in the scene and get loaded into the shop.
    So now, when buy the weapon everything works fine except the Cmd I try to call on the WeaponDisplayer.

    Code for the Update
    Code (CSharp):
    1. void ChangeObjectsInShopList(List<ObjectsToSyncInShop> old, List<ObjectsToSyncInShop> neu)
    2.     {
    3.         ServerObjectsInShop = neu;
    4.         //Goes trough every object in the shop to check for changes
    5.         foreach (GunInShop shopitem in ObjectsInShop)
    6.         {
    7.             //Searches for the right object in the shop to change
    8.             foreach (ObjectsToSyncInShop ServerItem in ServerObjectsInShop)
    9.             {
    10.                 //If you found the right object
    11.                 if (shopitem.WeaponToPurchase.name == ServerItem.NameOfGunObject)
    12.                 {
    13.                     //Update the State of the Item on the Client
    14.                     shopitem.Verfügbarkeit = ServerItem.CanBuy;
    15.                     //Update weapondisplayer on client, so the weapondisplayers can update on the server
    16.                     CmdChangeBool(shopitem.GunDisplayer);
    17.                     return;
    18.                 }
    19.             }
    20.         }
    21.     }
    22.  
    23. public void CmdChangeBool(GameObject GunDisplayer)
    24.     {
    25.         GunDisplayer.GetComponent<NetworkIdentity>().AssignClientAuthority(Player.GetComponent<NetworkIdentity>().connectionToClient) ;
    26.         GunDisplayer.GetComponent<WeaponDisplayer>().CmdChangeBoolians(true, false);
    27.         GunDisplayer.GetComponent<NetworkIdentity>().RemoveClientAuthority();
    28.     }
    Code on the WeaponDisplayer Object
    Code (CSharp):
    1. [Command]
    2. public void CmdChangeBoolians(bool GD, bool GT)
    3.     {
    4.         DisplayGun = GD;
    5.         GunTaken = GT;
    6.         RpcChangeBool(DisplayGun, GunTaken);
    7.         Debug.Log("CmdChangeBoolians");
    8.     }
    The funny thing is: I call the exact same code from a diffrent script when colliding with the same weapondisplayer and it works just fine.

    Code here:
    Code (CSharp):
    1. private void OnTriggerEnter(Collider col)
    2.     {
    3.         if (col.CompareTag("GunDisplayer"))
    4.         {
    5.             Debug.Log("OnTriggerEnter, PlayerMovementScripts, GunDisplayer");
    6.             WeaponDisplayer dis = col.GetComponent<WeaponDisplayer>();
    7.             if (!dis.GunTaken)
    8.             {
    9.                 if (dis.DisplayGun)
    10.                 {
    11.                     gundisplay.SetCurrentGun(col.GetComponent<WeaponDisplayer>().GunInDisplay, col.gameObject);
    12.                     dis.CmdGotWeapon(this.GetComponentInChildren<GunDisplay>().pistolslot, this.GetComponentInChildren<GunDisplay>().gewehrslot);
    13.                 }
    14.             }
    15.            
    16.             Debug.Log(col.name + " " + col.GetComponent<WeaponDisplayer>().ToString());
    17.     }
    Any help to solve this appreciated!
     
  2. Opti66

    Opti66

    Joined:
    Jun 29, 2018
    Posts:
    7
    Edit: I call a little diffrent command from the movementscript: but anyway should it generate the same error!
     
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    You forgot to mention the specific error you are encountering.