SendServerData: Difference between revisions
No edit summary |
No edit summary |
||
Line 45: | Line 45: | ||
[SCRIPT] hello | [SCRIPT] hello | ||
[SCRIPT] 100.789</source>| | [SCRIPT] 100.789</source>| | ||
retvals=true on success, false on failure| | |||
relfuncs=*[[onServerData]] | relfuncs=*[[onServerData]] | ||
}} | }} |
Revision as of 23:16, 20 January 2023
This function was added in v1.6 beta and will not work on previous versions.
Description:
This will send data( results in calling onClientScriptData of squirrel-server )
Parameters:
(data)
data: The blob which needs to be formatted as below.
Inorder for the squirrel-plugin of server to read what is send :
1. The first four bytes should contain the length of the data being send.
2. The first four bytes should be big endian. swap4 function is used here to achieve this.
3. The length of string is written before the string as two bytes.
4. The word written in (3) should be big endian. Here swap2 function can be used (2 bytes-and hence the name)
Return Values:
true on success, false on failure
Example
Input npcscript
local b=blob(); b.writen( swap4(16), 'i' ); b.writen( 1234, 'i' ); b.writen( 10, 'b' ); //b - byte b.writen( swap2(5), 'w' ); //w - word b.writen('h','c'); //c - signed char b.writen('e','c'); b.writen('l','c'); b.writen('l','c'); b.writen('o','c'); b.writen(100.789, 'f'); //f float SendServerData(b);
Output from server
function onClientScriptData(p){ print(Stream.ReadInt());print(Stream.ReadByte()); print(Stream.ReadString());print(Stream.ReadFloat()); } [SCRIPT] 1234 [SCRIPT] 10 [SCRIPT] hello [SCRIPT] 100.789
Related Functions
The following functions may be helpful as they relate to this function in one way or another.