Solved I need help with RPC

Discussion in 'Tech Support' started by Pompeyo, Oct 9, 2018.

  1. Pompeyo
    Offline

    Pompeyo Member Member

    Joined:
    Jan 6, 2018
    Messages:
    54
    Likes Received:
    5
    I'm doing tests to make communications from the server to the client through RPC, I have made a test plugin for it, but for some reason I can not get it to work, when I try to send something to rpc I get this error:

    No receiver found for RPC 'Saludos' at uLinkNetworkView "Player POMPEYO (76561197960761348)" (ViewID 60969)

    Here I leave the complete project, and I will also put the code directly, I need someone to help me find where my error is

    PruebaServer:

    Code (C#):
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    using Fougerite;
    using Fougerite.Events;
    using RustBuster2016Server;
    using UnityEngine;

    namespace PruebaServer
    {
        public class PruebaServer : Fougerite.Module
        {

            private PruebaServerRPC rpc;
            private GameObject myGameObject;

            public const string red = "[color #FF0000]";
            public const string yellow = "[color yellow]";
            public const string green = "[color green]";
            public const string orange = "[color #ffa500]";

            public override string Author
            {
                get { return "Pompeyo"; }
            }

            public override string Name
            {
                get { return "PruebaServer"; }
            }

            public override Version Version
            {
                get { return new Version("1.0"); }
            }

            public override string Description
            {
                get { return "Testing RPC System"; }
            }


            public override void DeInitialize()
            {
               // Hooks.OnPlayerSpawned -= OnPlayerSpawned;
                Hooks.OnCommand -= OnCommand;
                if (myGameObject != null)
                {
                    UnityEngine.Object.Destroy(myGameObject);
                }
            }

            public override void Initialize()
            {
                //Hooks.OnPlayerSpawned += OnPlayerSpawned;
                Hooks.OnCommand += OnCommand;

                myGameObject = new GameObject();
                rpc = myGameObject.AddComponent<PruebaServerRPC>();
                UnityEngine.GameObject.DontDestroyOnLoad(myGameObject);

            }

            public void OnCommand(Fougerite.Player pl, string cmd, string[] args)
            {
                if (cmd == "test")
                {

                        pl.MessageFrom(Name, green + "Probando RPC!!!");

                        rpc.SendMessageToPlayer(pl, "Saludos", true);

                        pl.MessageFrom(Name, red + "Probando RPC!!!");

                }
            }


        }
    }
     
    PruebaServerRPC:

    Code (C#):
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;

    namespace PruebaServer
    {
        public class PruebaServerRPC : UnityEngine.MonoBehaviour
        {

             //2 paso
            public void SendMessageToPlayer(Fougerite.Player pl, string function, bool Inicio)
            {
                if (pl.NetworkPlayer != null && pl.PlayerClient.networkView != null)
                {
                    //Supongo q para enviar Server -> Client
                    //networkView.RPC(function, UnityEngine.RPCMode.Others, Inicio);

                    //Supongo q para enviar Server -> Especific Client
                    uLink.NetworkView.Get(pl.PlayerClient.networkView).RPC(function, pl.NetworkPlayer, Inicio);
                }
            }
       
        }
    }
     
    #1
    Last edited: Oct 10, 2018 at 12:08 AM
  2. Pompeyo
    Offline

    Pompeyo Member Member

    Joined:
    Jan 6, 2018
    Messages:
    54
    Likes Received:
    5
    PruebaClient:

    Code (C#):
    using RustBuster2016.API;
    using RustBuster2016.API.Events;
    using System;
    using System.Collections.Generic;
    using UnityEngine;

    namespace PruebaClient
    {
        public class PruebaClient : RustBusterPlugin
        {

            public static PruebaClient Instance;
            private static GameObject _gameObject;
            public PruebaClientGUI GUI;
            private PruebaClientRPC rpc;
            private CharacterWaiter waiter;


            public override string Name { get { return "PruebaClient"; } }
            public override string Author { get { return "Pompeyo"; } }
            public override Version Version { get { return new Version("1.0"); } }


            public override void DeInitialize()
            {
                if (GUI != null)
                {
                    UnityEngine.Object.DestroyImmediate(GUI);
                }
                if (rpc != null)
                {
                    UnityEngine.Object.DestroyImmediate(rpc);
                }
            }

            public override void Initialize()
            {
                Instance = this;
                if (this.IsConnectedToAServer)
                {

                    _gameObject = new GameObject();
                    waiter = _gameObject.AddComponent<CharacterWaiter>();
                    UnityEngine.Object.DontDestroyOnLoad(waiter);

                }

                UnityEngine.Debug.Log("Cargo plugin de Pruebas RPC!");
            }

            public void StartTest()
            {

                Debug.Log("Test iniciado!");
            }

        }
    }
     
    PruebaClientRPC

    Code (C#):
    using RustBuster2016.API;
    using System.Collections.Generic;
    using UnityEngine;

    namespace PruebaClient
    {
        class PruebaClientRPC : MonoBehaviour
        {

            [RPC]
            public void Saludos(bool Inicio)
            {
                if (Inicio)
                {
                    PruebaClient.Instance.StartTest();
                }
            }

        }
    }
    CharacterWaiter:

    Code (C#):
    using UnityEngine;

    namespace PruebaClient
    {
        public class CharacterWaiter : MonoBehaviour
        {
            public static bool IsPlayerReady = false;

            public void FixedUpdate()
            {
                if (Controllable.localPlayerControllableExists)
                {
                    if (!IsPlayerReady)
                    {
                        Debug.Log("Player Ready");
                        PlayerClient.GetLocalPlayer().gameObject.AddComponent<PruebaClientRPC>();
                        IsPlayerReady = true;
                    }

                }

            }
            public void OnDisable()
            {
                IsPlayerReady = false;
            }
        }
    }
    PruebaClientGUI:


    Code (C#):
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using UnityEngine;

    namespace PruebaClient
    {
        public class PruebaClientGUI : MonoBehaviour
        {

            public static Vector3 PlayerLocation;
            public static GameObject FogGameObject;


            public void Start()
            {
     
            }
            public void Update()
            {

            }

        }
    }
     
    #2
    Last edited: Oct 10, 2018 at 12:04 AM
  3. Pompeyo
    Offline

    Pompeyo Member Member

    Joined:
    Jan 6, 2018
    Messages:
    54
    Likes Received:
    5
    guys finally solved the problem, I leave the code arranged in case it serves as a guide or help to someone else
     
    #3
    • Like Like x 1

Share This Page