OnServerData: Difference between revisions
Jump to navigation
Jump to search
(Created page with "<poem style="border: 2px solid #d6d2c5; background-color: #f9f4e6; padding: 1em;"> This function was added in v1.6 beta and will not work on previous versions. </poem>{{Welco...") |
No edit summary |
||
Line 5: | Line 5: | ||
params=<syntaxhighlight lang="lua">( data )</syntaxhighlight> | params=<syntaxhighlight lang="lua">( data )</syntaxhighlight> | ||
<poem>::data : The data the server send as a blob object. | <poem>::data : The data the server send as a blob object. | ||
From blob library of squirrel, blob.readn( type ) | |||
type return description return type | |||
‘i’ 32bits number integer | |||
‘s’ 16bits signed integer integer | |||
‘w’ 16bits unsigned integer integer | |||
‘c’ 8bits signed integer integer | |||
‘b’ 8bits unsigned integer integer | |||
‘f’ 32bits float float | |||
</poem>| | </poem>| | ||
retvals=This function does not return any specific values.| | retvals=This function does not return any specific values.| | ||
Line 33: | Line 41: | ||
for(local i=0;i<_strlen;i++) | for(local i=0;i<_strlen;i++) | ||
string+=format("%c",data.readn('c')); | string+=format("%c",data.readn('c')); | ||
local _float = data.readn('f'); | local _float = data.readn('f'); | ||
printf("Received\n"+_integer+"\n"+_byte+"\n"+string+"\n"+_float+"\n"); | printf("Received\n"+_integer+"\n"+_byte+"\n"+string+"\n"+_float+"\n"); |
Revision as of 17:16, 19 January 2023
This function was added in v1.6 beta and will not work on previous versions.
Description:
This function is when server sends script data( Streams in squirrel04relxx )
Parameters:
( data )
data : The data the server send as a blob object.
From blob library of squirrel, blob.readn( type )
type return description return type
‘i’ 32bits number integer
‘s’ 16bits signed integer integer
‘w’ 16bits unsigned integer integer
‘c’ 8bits signed integer integer
‘b’ 8bits unsigned integer integer
‘f’ 32bits float float
Return Values:
This function does not return any specific values.
Example
Server code
//scripts/main.nut Stream.StartWrite(); Stream.WriteInt(400); Stream.WriteByte(100); Stream.WriteString("hello"); Stream.WriteFloat(28.24); Stream.SendStream(player);
npc code
function OnServerScriptData( data ) { local len=data.readn('i'); len=swap4(len);//because squirrel plugin sends it inverted. local _integer=data.readn('i'); local _byte=data.readn('b'); local _strlen=data.readn('w'); _strlen=swap2(_strlen); local string=""; for(local i=0;i<_strlen;i++) string+=format("%c",data.readn('c')); local _float = data.readn('f'); printf("Received\n"+_integer+"\n"+_byte+"\n"+string+"\n"+_float+"\n"); }
Output in npc window
Received 400 100 hello 28.24