Author Topic: [Resource/Tutorial] Client-Sided to Server-Sided  (Read 1456 times)

There are two different connection sides, Server, and Client. Server, which sends and receives information to the clients. And Client, which is your computer sending and receiving information from the server.

The Server defines what a function is like this:
Code: [Select]
function servercmdHELP()
{

}
Where as now, each player on that specific server can now type /HELP . And it will call whatever is in those brackets. Unfortunately when you join another server, and type /HELP that same command won't work. Which is why a server command, is a server command.


The Client defines what a function is like this:
Code: [Select]
function clientcmdMEOW() //Only use "clientcmd" prefix when you are communicating with the server..
{

}
What is different about a Client command, is that your own computer possesses the command. So you can join any server, and it will work.

There are probably a few ways to send and receive information from a server, but I like to use CommandtoServer(); and CommandtoClient(); .


Exercise: So, let's say you had 4 cakes, and you wanted to send to the server that you have 4. You would do this.

SERVER:
Code: [Select]
function servercmdUPDATECAKES(%client,%cakes)
{
$CakeAmount = %cakes;
}

CLIENT:
Code: [Select]
function SendCakes()
{
%cakes = 4;
CommandtoServer('UPDATECAKES',%cakes);
}



Exercise: You are a "Co... Coffee Dealer".. And you want to deal out the right amount of grams to your peeps. So let's send a client some grams..

SERVER:
Code: [Select]
function servercmdSENDGRAMS(%client, %grams, %person)
{
%target = findclientbyname(%person);
CommandtoClient(%target,'RECEIVEGRAMS',%grams);
}

CLIENT:
Code: [Select]
function clientcmdRECEIVEGRAMS(%grams)
{
$CurrentGrams = %grams;
}

One other thing, if you aren't going to be communicating with the server, then don't use "clientcmd" prefix.



I pretty much explained this in my own way, please tell me if you find any mistakes.
« Last Edit: March 22, 2013, 07:16:12 PM by Honorabl3 »

Thanks, looks good. One thing, can you explain somewhere that if you aren't going to be communicating with the server, you don't need the clientCmd prefix on your function names.

Thanks, looks good. One thing, can you explain somewhere that if you aren't going to be communicating with the server, you don't need the clientCmd prefix on your function names.

Alright will do.

Also, can you add me to your resources topic?
« Last Edit: March 20, 2013, 07:39:31 PM by Honorabl3 »