I’m trying to send an RPC back to the original sender like lets take for example.
player1 sends an RPC to player2 telling player2 to loose health. How do I make player2 identify who the RPC came from and send it back to player1?
I’ve already tried getting the networkView of player1 and sending it along with the first RPC but what I ended up doing was
(This is not my exact code it was just something I wrote to give a general Idea on how I did it)
but I get a parameter error. What am I doing wrong?
You can't send networkView objects via RPC calls. Instead, use this:
hit.RPC("LoseHP", RPCMode.All, sender.networkView.viewID);
NetworkView view = NetworkView.Find(id);
this will allow you to refer to specific networkViews remotely, without sending the actual object itself.
To do this, you need to define the NetworkMessageInfo parameter in your first RPC method like here:
Then inside this RPC method you get the sender object from the NetworkMessageInfo and use it to call a RPC-method on the original sender. For this you use the second type of RPC call described here (the one that uses NetworkPlayer as a target):
I hope it works.
Your code looks like it’s a mixture of C# and UnityScript.
function looshp(sender : NetworkView)
or if you want to use C# it should look like this:
void looshp(NetworkView sender)
Is it possible to send rpc to everyone except the original sender? Like the sender client wants to broadcast a chat message, sends it to server and then server sends the message to every other client?