Solved I need help with RPC

Pompeyo

Plugin Developer
Plugin Developer
Jan 6, 2018
87
239
33
44
Cuba
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:

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:

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);
            }
        }
   
    }
}
 
Last edited:
  • Like
Reactions: robah_132

Pompeyo

Plugin Developer
Plugin Developer
Jan 6, 2018
87
239
33
44
Cuba
PruebaClient:

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

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:

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:


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()
        {

        }

    }
}
 
Last edited:

Pompeyo

Plugin Developer
Plugin Developer
Jan 6, 2018
87
239
33
44
Cuba
guys finally solved the problem, I leave the code arranged in case it serves as a guide or help to someone else
 
  • Like
Reactions: DreTaX

Jakkee

Plugin Developer
Plugin Developer
Contributor
Jul 28, 2014
1,465
925
113
Australia
guys finally solved the problem, I leave the code arranged in case it serves as a guide or help to someone else
If we were to create a project with the above it would all work?
If so you could request to add to the wiki