Author Topic: A question (Delays) (Solved)  (Read 1590 times)

Hey, I tried looking into some scripts to find out a way to make a slash command.
I tore apart the /me script. I tried to base it off of what I found.

Code: [Select]
function servercmdwoo
{
echo("woo!");
}

The error report came up like this:

function servercmdwoo


{##
#
echo("woo!");
}

What are you trying to say console :/

Anyways, if you're too lazy to tell me how, can you atleast link me to a script that would better explain it then the /me one?

Also, I'm trying to make it so when someone says /woo in chat, it echos woo in the console.
It is serversided.
« Last Edit: July 29, 2013, 07:35:38 PM by Johnny Blockhead »

You need to add parentheses

Like this:
Code: [Select]
function serverCmdWoo()
{
    echo("lern2syntax");
}

:<

Let me test it.

Edit: It worked, thanks.
« Last Edit: July 28, 2013, 07:28:26 PM by Johnny Blockhead »

Here is some more info on client / server commands
I'd say a lot of new scripters want to learn how to make server commands..


Client and Server Commands
Have you ever used commands such as, for example, "/buyDirt 50 500" etc.? Have you wondered how to make "slash commands"?
Before you can learn that, let us recap and discuss what a client and a server is. In Blockland, when someone is hosting a server, the Blockland server running on their computer is the Server. When you join his game, you connect to that server and you are the Client. The client in Blockland does not host the server, but joins a game.

Outside of Blockland, the Server is basically the computer hosting a database, game room, chat server such as Mumble or TeamSpeak, and can be used when multiple computers need to share information. The computers that access the database, join the game room, chat on the chat room, access files from the server are the Clients.

You may have to read this a few times to see what's going on, but if you understand, read on. Now that you know what a Client and a Server is, we can begin.
Let's put this into Blockland perspective. Everytime you chat in a server, CTRL + K, build, fire a weapon, etc. you are communicating with the server.

Communicating Client To Server

When you want to communicate with the server as a Client, you use this command in your script :
commandToServer();

Here's and example of it :

Code: [Select]
commandToServer('kill', %target);

"What is that?" you say? Let me break it down :
-commandToServer(); - This is a function (as you have learned earlier), that communicates with the server.
-'kill' - In these single quotes, I am saying that the command I want to perform is "kill".
-%target - You've learned already that this is a local variable, only usable by the function that it is in. You can think of it as I'm providing the server with extra details on my command. In this case, if I wanted my command to kill someone in the server, logically I would have to explain who should be killed, so I would want to add a variable such as %target in there.

So let's say I made this function :

Code: [Select]
function byebye(%target)
{
   commandToServer('kill', %target);
}

Now if I typed byebye("James"); in my script, it would tell the server to "kill" James.

That's basically how you communicate to the server as a client.

Receiving A Server Command
You know what? If a client uses commandToServer('kill', "fredrick55"); , then the server running default Blockland will probably not at all understand what to do. That's because you have to specify what the server has to do when someone tells it a command.

As the server-side, you must declare a function like this to handle things like that :
Code: [Select]
function serverCmdkill(%client, %target)
{
   findclientbyname(%target).player.kill();
}

In this example, findclientbyname(%target).player.kill(); is not terribly important for learning uses, but I'll break down the rest of it :

function / () / { } - You should be familiar with this, if not, read Functions above.

serverCmd - Alright, so server commands are a special type of function you can declare. If you want the server to respond to "/dig", you would use function serverCmdDig(). If you wanted the server to respond to "/buy", you would use function serverCmdBuy(). The simple idea is to keep "serverCmd" before the name of your command.

%client - Whenever you code what the server should do when it receives a certain command, you should always keep "%client" as the first argument after the first ( in the set of parentheses. The %client is a local variable you can use in the function which is basically the person who commanded the server to do something. %client is the client object but NOT the player.

%target - I skipped a comma, but whenever you have multiple arguments in a function, you insert a comma between them. Anyway, %target is an extra variable I'm using since logically I need to specify who should be killed.

When you type something like /kill Blake1, whatever spaces you type and whatever you type after a space is a new argument.

Using /kill Blake1 50 No (Let's just say the %target, %score [that i get], %displayKillMessage for example) I would be sending "kill" to the server with three arguments.

You now know how to make a client communicate with the server and specify how the server receives it.


Let's put your client / server command knowledge together so far :

Say this is my client side script :

Code: [Select]
function goodbye(%target)
{
   commandToServer('kill', %target);
}

Now say this is my server side script :

Code: [Select]
function serverCmdkill(%client, %target)
{
   if(%client.isAdmin) //By the way, these two slashes I put here are comments. Comments don't affect the script at all. This checks if the client is an admin.
   {
      findclientbyname(%target).player.kill();
   }
}

Now on the server, if I am an admin and there is a player on it called "BasonMason"..

Doing EITHER
Code: [Select]
commandToServer('kill', "BasonMason");

OR

Typing /kill BasonMason

Will do the same thing. That's right, typing a /slash command in your chat uses commandToServer(). They do the same thing.


Server to Client Commands
Alright, here I am, I'm the big old server and I want to tell the client to 'spinAround'.

So if client -> server is "commandToServer();", can you guess what server -> client is?

It's the function "commandToClient();", and it works in a similar way! Let's say I'm the server side in this script :
Code: [Select]
$Client = findclientbyname("Pacnet2013");
commandToClient($Client, 'spin');

The first argument you use in commandToClient is always the client object itself, most commonly named inside a function as "%client".
I then use the single quotes after that, simply to specify the command I want that client to perform.


Receiving a Command from the Server as a Client
Above, I used commandtoclient($client, 'spin', 1); as an example.
My client usually won't know what the heck the server wants it to do, so you also have to declare what happens in a client command declaration. It's very similar to serverCmd declarations.
This is my client side :

Code: [Select]
function clientCmdspin(%onOroff)
{
   turnleft(%onOroff); //Just a function that makes you turn around fast.
}

My argument is either 1 or 0 declared by the server, to spin or to stop spinning.


You should now know how to use client to server and server to client commands. They are a key part of Blockland. Good luck!



-snip-

Thanks, it will be useful. Where did you copy that from?

anyways, tried doing some code.

Code: [Select]
package Report {
function servercmdreport()

{
echo("Someone is breaking the rules. An admin should investigate.");
}
};
activatepackage(Report);

It says it loaded, no errors or anything.
When I go /report it doesn't work.

Thanks, it will be useful. Where did you copy that from?
You can usually click the top of a quote to find the source.

You don't need to package it unless it's overwriting/editing an existing function

Here, you need %this (or some variable at the start to define it as a client of a server command)
Since you don't want people the spam the crap out of the command, lets make a timeout.

Code: [Select]
function servercmdReport(%this)
{
if(getSimTime() - %this.lastReport > 5000)
{
echo(%this.getName() SPC "has reported that someone is breaking the rules. An admin should check.");
%this.lastReport = getSimTime();
messageClient(%this,'',"You have made a report. It will be reviewed soon.");
}
}
I haven't tested this, but I am sure it should work.

You don't need to package it unless it's overwriting/editing an existing function
« Last Edit: July 29, 2013, 01:56:46 AM by Advanced Bot »

I tried doing  a little showy thing just to test some functions or whatever you call them.

Code: [Select]

function Point(%this) {
// Now lets start the brick movement magic.

commandToServer('instantUseBrick', "brick1x3x5Data");
commandToServer('instantUseBrick', "brick8x8Data");
commandToServer('instantUseBrick', "brick2x2Data");
commandToServer('instantUseBrick', "brick6x6Data");
commandToServer('instantUseBrick', "brick8x6Data");
commandToServer('instantUseBrick', "brick8x2Data");
commandToServer('instantUseBrick', "brick8x4Data");
commandToServer('instantUseBrick', "brick2x2Data");
commandToServer('instantUseBrick', "brick3x3Data");
commandToServer('instantUseBrick', "brick2x2Data");

}

It works perfectly, or almost. It scrolls through the bricks too fast, not allowing me to see them. Is there any way to delay them?

Use schedules

schedule(500, 0, commandToServer, 'instantUseBrick', "brickname");
schedule(1000, 0, commandToServer, ... );

etc.

First arg is time in milliseconds, second is object?, third is function name and the rest are args for that function.

Use schedules

schedule(500, 0, commandToServer, 'instantUseBrick', "brickname");
schedule(1000, 0, commandToServer, ... );

etc.

first arg is time in milliseconds, second is object?, third is function name and the rest are args.

Thought that only worked in chat. Thanks.

Let me test it.
It fixed.
« Last Edit: July 29, 2013, 07:35:28 PM by Johnny Blockhead »