- Home /
Simple example of an RPC message?
Hey, I am at the point where I need to think about what the user sees when he/she is connected to a server.
If I could get some info on maybe how to just get it to spit out "john" connected. then I could figure the rest out, the doc's are a tad hard to understand for a beginner. (John is a saved PlayerPref) (This Doc)
Cheers,Tim.
I know it's @RPC..something something heheh
What do you really want to do ?
Do you need a client to tell the server its name ? Or something else ?
Well when someone connects, they just connect. I want the server to to tell everyone that "kira" connected. Or if theres a few people on, I want them to be able to distinguish between "kira, the person who doesnt crash everyone" and "bob,the person who crashes everyone.
Once I figure out that..I plan to display peoples name along with their ping. And some other things. Perhaps for clan na$$anonymous$$g as well.
The nickname must be picked before the user can get online, once the name is picked it's saved in a playerpref. And then the user can get online. But no one sees their name.
Hope I explained it better (:
Answer by KiraSensei · Nov 26, 2013 at 03:08 PM
So first you need your client to tell the server who he is :
function OnConnectedToServer ()
{
var name:String = PlayerPrefs.GetString("Player Name");
networkView.RPC("TellNameToServer", RPCMode.Server, name, Network.player);
}
Then you need your server to handle the info (stock it locally if you want for example in a list of players) and tell every client who just connected :
@RPC
function TellNameToServer(name:String, thisPlayer:NetworkPlayer) {
networkView.RPC("DisplayName", RPCMode.AllBuffered, name);
}
And after that you need every player to handle this info (like stock it too, or display it in your case) :
@RPC
function DisplayName(name:String) {
// Here you display the name, I don't know how you plan to do that, so you're on your own :)
}
All these functions are in the same script, every player must have it.
Your answer
Follow this Question
Related Questions
How to get NetworkPlayer? 2 Answers
Does the position change need state synchronization? 2 Answers
Serialize a LineRenderer 2 Answers
NetworkMessageInfo sender.guid set to empty string "" or "0"? 1 Answer