send_skill(var* skill, var mode)
send_skill_to(ENTITY*, var* skill, var mode)
send_skill_id(var client_id, var* skill, var mode)
Sends the given entity parameter - for instance, a skill or skill vector - to the server, or from a server to the creator of the entity (send_skill), to a client that has created another entity (send_skill_to), or to a client with a certain id number (send_skill_id). The skill or skill vector is updated on the same entity instance on the target machine.
Parameters:
skill |
Entity parameter to be sent. |
ENTITY* |
Receiver of the parameter, or NULL for sending to all clients. LC |
client_id |
Receiver of the parameter. LC |
mode |
either 0 or a combination of the following flags:
SEND_ALL |
send the skill to all clients (server only). |
SEND_VEC |
send also the two following skills, when 3 skills represent a vector. |
SEND_STRING |
send a string when the skill was set to a STRING* pointer. LC |
SEND_UNRELIABLE |
send in unreliable mode. Otherwise it's sent in reliable mode. |
SEND_RATE |
send only every n-th frame, with n = dplay_entrate/time_step. |
|
Returns:
0 |
Parameter not sent due to SEND_RATE or for other reasons. |
!= 0 |
Parameter sent . |
Remarks:
- Triggers EVENT_RECEIVE on the target entity.
- Send most entity parameters, like user input, in unreliable mode. Only important entity status changes like shooting or opening a door should be send in reliable mode. Reliable messages won't expire, which could result in a buffer overflow and falling out of sync on slow connections when many reliable messages are sent.
-
After creating the entity, it can take up to 0.5 seconds until it is copied to all connected PCs. During that time, client_id is 0 and entity skills can not be sent to other PCs. The client_id parameter can be polled until the entity is ready: while
(my.client_id != dplay_id) wait(1); .
Examples (see also the multiplayer tutorial):
// send a skill when it was changed
var skill1_old = -1; // local variable to backup skill1
if (my.skill1 != skill1_old) { // send only if changed
skill1_old = my.skill1; // store change
if (my.skill1 == 0) { // send important values in reliable mode
send_skill(my.skill1,SEND_ALL);
} else {
send_skill(my.skill1,SEND_ALL|SEND_UNRELIABLE);
}
}
...
// send a string from the server to the clients
my.skill80 = str_create("Avatar"); // create a string on clients and server. Make sure to remove it when removing the entity.
if (connection & CONNECT_SERVER) { // running on the server?
str_for_id((STRING*)my.skill80,my.client_id); // set the string to the client name
send_skill(my.skill80,SEND_ALL|SEND_STRING); // send the name to all clients
}
See also:
EVENT_RECEIVE, send_var, skill1..skill100
► latest version online