Vice City: Multiplayer

Server Development => Scripting and Server Management => Client Scripting => Topic started by: Sebastian on Feb 25, 2017, 11:02 PM

Title: [SNIPPET] Server Echo ( ... )
Post by: Sebastian on Feb 25, 2017, 11:02 PM
It is a basic thing, but some still might not be aware of it. (like me)
It was done by @happymint in order to help me, but we concluded to share it.

With this function you will be able to print messages into server's console.
:)
Usage: ServerEcho(" test ");


SERVER's NUT
1. Place this in the top
enum StreamType {
    StringEcho = 0xFA
}
2. And this in onClientScriptData( player )
    if (Stream.GetReadSize() < 1) {
        return;
    }
    switch (Stream.ReadByte())
    {
        case StreamType.StringEcho: {
            print(Stream.ReadString());
        } break;
    }


server/store/script/main.nut
3. Place this in client.nut
enum StreamType {
    StringEcho = 0xFA
}

function ServerEcho(...) {
    local m;
    if( vargv.len() <= 0 ) {
        Console.Print( "- ServerEcho() Error - Please specify a message!" );
        return;
    }
    else if (vargv.len() == 1) {
        m = typeof(vargv[0]) == "string" ? vargv[0] : vargv[0].tostring();
    } else {
        vargv.insert(0, this);
        m = format.acall(vargv);
    }
    local s = Stream();
    s.WriteByte(StreamType.StringEcho);
    s.WriteString(m);
    Server.SendData(s);
}

PS: If the param will be simply numbers, they will be auto-convert.
(so ServerEcho(353) will result into "353")
Title: Re: [Basic] Server Echo ( ... )
Post by: kennedyarz on Feb 26, 2017, 12:27 AM
The truth is that I do not see a necessary use, but good "that we will do" anyway good work: P
Title: Re: [Basic] Server Echo ( ... )
Post by: jWeb on Feb 26, 2017, 12:31 AM
Quote from: kennedyarz on Feb 26, 2017, 12:27 AMThe truth is that I do not see a necessary use

Actually it may be quicker to notice an error message on the server console instead of having to constantly look in the debuglog.txt whenever it's updated.

Sure it doesn't protect you from compile-time errors but run-time errors can do just fines.
Title: Re: [Basic] Server Echo ( ... )
Post by: Sebastian on Feb 26, 2017, 12:58 AM
Quote from: jWeb on Feb 26, 2017, 12:31 AMActually it may be quicker to notice an error message on the server console

That's exactly what I needed it for. :)
Title: Re: [SNIPPET] Server Echo ( ... )
Post by: rulk on Feb 26, 2017, 01:40 AM
very handy indeed, I preferred using the console even back in the 0.3z squirrel days, very kind of you to share.
Title: Re: [SNIPPET] Server Echo ( ... )
Post by: Sebastian on Feb 26, 2017, 11:54 AM
First topic was updated with the fixed version.
There was Server::SendData(s);, while it had to be Server.SendData(s);