Sending an RPC back to its original sender

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

  hit.RPC("loosehp",RPCMode.All, sender.networkView);
@RPC
looshp(NetworkView sender)
{
sender.RPC("addkill",RPCMode.All);
}

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

[RPC]
LoseHP(NetworkViewID id)
{
    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:
http://unity3d.com/support/documentation/Components/net-RPCDetails.html

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):
http://unity3d.com/support/documentation/ScriptReference/NetworkView.RPC.html

I hope it works. :slight_smile:

Your code looks like it’s a mixture of C# and UnityScript.

I guess you want to use UnityScript (Unity’s Javascript):

hit.RPC("loosehp",RPCMode.All, sender.networkView);

@RPC
function looshp(sender : NetworkView)
{
    sender.RPC("addkill",RPCMode.All);
}

or if you want to use C# it should look like this:

hit.RPC("loosehp",RPCMode.All, sender.networkView);

[RPC]
void looshp(NetworkView sender)
{
    sender.RPC("addkill",RPCMode.All);
}

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?