So one of my friends has just kept asking for that I helped him a bit with scripting, and so I did. A small conversation going through a little script I made which has some few of BlockBot's features in-game. I thought that this might help some people alot, so here the conversation is:
Bauklotz says:
We start defining package.
Bauklotz says:
with the keyword package followed by the package name.
Bauklotz says:
Now, we have a starting bracket. Here the package begins. A starting bracket must always have a ending bracket.
Haskar says:
That I definatly know
Bauklotz says:
Okay.
Bauklotz says:
To create functions, we use the 'function' keyword.
Haskar says:
You can skip {} lines if you want
Bauklotz says:
The syntax for function is the following:
Bauklotz says:
function function_name(argument_list)
Bauklotz says:
function_name is the name of the function.
Example: function lol would be called as lol(arguments)
Bauklotz says:
argument_list is a list of all th earguments the function takes.
Bauklotz says:
These must use % (local variables that are deleted at the end of the function)
Bauklotz says:
The syntax for those is: %argument_name_1,%argument_name_bla,%argument_name_lol and so on
Bauklotz says:
Example if a function takes 2 arguments that are passed into %abc and %xyz:
function function_name(%abc,%xyz)
Haskar says:
kk
Bauklotz says:
Now we just have a command.
Bauklotz says:
The built-in engine function commandToServer() tells the server to execute the command.
Bauklotz says:
Example: If the server had serverCmdExplode, commandToServer('Explode'); would call the following on the host console: serverCmdExplode(client_id);
Haskar says:
ok
Bauklotz says:
serverCmdMessageSent is the server command for when someone speaks.
Bauklotz says:
So this triggers serverCmdMessageSent(client_id,"BlockBot: "@argument %msg passed);
Bauklotz says:
" is the basic marker for all normal strings.
Haskar says:
so serverCmdxxx, from what I know are stuff that can be executed with a /xxx in the server and you can use them in commandToServer(xxx) cmds?
Bauklotz says:
' is a marker for networked strings. commandToServer's first argument, the command, must use '
Bauklotz says:
yeah true
Bauklotz says:
The following things work the same way:
Bauklotz says:
/light
commandToServer('Light');
Bauklotz says:
Now we begin declaring clientCmdChatMessage which is a function triggered by the SERVER.
Haskar says:
So what /light actually does is commandToServer('Light'); but it's easier for a client than using the console?
Bauklotz says:
Yes.
Bauklotz says:
NMH_Type.send is the / command handler.
Bauklotz says:
A server can issue commandToClient(client_id,'command',argument_list); to trigger the following on the client:
clientCmdCommand(argument_list);
Haskar says:
NMH_Type.send?
Bauklotz says:
Yes.
Bauklotz says:
NMH_Type is the object which displays SAY: or TEAM: followed by user input.
Haskar says:
oh
Bauklotz says:
Send is a function inherited by it.
Bauklotz says:
There is also NMH_Type.type which is every time the user input changes.
Bauklotz says:
This can for example to be used to avoid the blue name appearing above chat showing (typing ):
Bauklotz says:
package noBlue
{
function NMH_Type::type(%this)
{
Parent::type(%this);
commandToServer('StopTalking');
}
};
activatePackage(noBlue);
Bauklotz says:
There we go.
Haskar says:
So basicly, what that does, is send a command StopTalking to server when you are typing?
Bauklotz says:
Example:
Bauklotz says:
Press T
Bauklotz says:
Type h
Bauklotz says:
stopTalking
Bauklotz says:
Press backspace
Bauklotz says:
stopTalking
Bauklotz says:
Press enter
Bauklotz says:
NMH_Type.send
Bauklotz says:
It checks if the message it is sending is empty, and if it is, then return;'s
Bauklotz says:
Small thing:
Bauklotz says:
Parent is used for calling the original function content.
Bauklotz says:
example
Bauklotz says:
lol content is echo("lol!");
Bauklotz says:
(package)
function lol()
{
Parent::lol();
echo("Another LOL!");
}
Bauklotz says:
When executed if the package is active, it will echo lol!, then Another LOL!
Haskar says:
So if I wanted to completly override the lol function, I could remove Parent::lol();?
Bauklotz says:
Yes.
Haskar says:
oooh, finnaly I got what that does
Bauklotz says:
brb, 5 min.
Haskar says:
Damn.
Haskar says:
nudge me when back
Bauklotz says:
back
You have just sent a nudge.
Haskar says:
kk
Bauklotz says:
Did you try the noBlue thingy?
Haskar says:
I can understand it
Bauklotz says:
Okay.
Bauklotz says:
serverCmdStopTalking commands to all clients that they should HIDE that name.
Bauklotz says:
serverCmdStartTalking the same just UNHIDE.
Haskar says:
ok
Haskar says:
So I could make some flashing stuff if I did a loop of that?
Bauklotz says:
Yeah.
Bauklotz says:
I did that once.
Haskar says:
Wait, it's client-side?
Bauklotz says:
What.
Bauklotz says:
What is client-side?
Haskar says:
noBlue?
Bauklotz says:
Yes.
Bauklotz says:
Server-side GUI != possible
Bauklotz says:
Client-Side GUI + commandToClient controls $= possible
Bauklotz says:
k?
Haskar says:
Kk
Bauklotz says:
back on subject
Bauklotz says:
start overwriting clientCmdChatMessage
Haskar says:
(%client,%b,%c,%taggedString,%preTag,%name,%postTag,%message,%x) what are those args?
Bauklotz says:
telling
Bauklotz says:
%client is the id on the player list
Bauklotz says:
0 = first player
Haskar says:
ok
Haskar says:
What about stuff like %b?
Bauklotz says:
%b and %c are empty.
Bauklotz says:
IDK what they are for.
Bauklotz says:
But %taggedString is useful.
Bauklotz says:
Example if LOLHEAD says Pie. taggedString would be this:
Bauklotz says:
something i dont remember{TAB}LOLHEAD: Pie.
Bauklotz says:
So you could change taggedString so it would use your own format
Bauklotz says:
My chat appears like <Name> Message.
Bauklotz says:
Okay?
Haskar says:
Ok
Bauklotz says:
%preTag is clan prefix
Bauklotz says:
%postTag is clan suffix
Bauklotz says:
%name is name of sender
Bauklotz says:
%message is self-saying
Bauklotz says:
%x is unknown
Bauklotz says:
I'm going to give example arguments
Bauklotz says:
Name: Bauklotz
Bauklotz says:
Message: lol
Bauklotz says:
Clan prefix: a
Bauklotz says:
Clan suffix: b
Bauklotz says:
first player on server
Bauklotz says:
clientCmdChatMessage(0,"","","something" TAB "aBauklotzb: lol","a","Bauklotz","b","lol","")
Haskar says:
okay, got it
Bauklotz says:
Next we just Parent.
Bauklotz says:
Then, we use the if keyword.
Bauklotz says:
if keyword syntax:
if(expression) { if expression true do this }
Haskar says:
Okay, seems easy
Bauklotz says:
Now here's some basic expression stuff.
Haskar says:
$= is for strings?
Bauklotz says:
If there is a exclamation mark (!) in front of the expression, it is true if this is NOT true.
Bauklotz says:
exclamation mark = NOT
Haskar says:
kk
Bauklotz says:
Then, we have what we want to check
Haskar says:
I know pretty much everything as I know C++
Bauklotz says:
This could be anything. A variable, a string
Bauklotz says:
Example:
Bauklotz says:
if(1 == 0) { echo("TorqueScript engine fail!"); }
Bauklotz says:
So
Bauklotz says:
Here's a example ( [ and ] means you CAN put it. ):
Bauklotz says:
if([!][$][%]is_this_name [!]check_operator is_first_statement_this_name)
Bauklotz says:
If you were to check if global variable lol was NOT 1 you could do this
Bauklotz says:
if(!$lol $= 1)
Bauklotz says:
if($lol !$= 1)
Bauklotz says:
if($lol != 1)
Bauklotz says:
But if you do not specify a check operator and what is should be, it checks for 1 or 0
Bauklotz says:
You could also use
Bauklotz says:
if(!$lol) { if $lol is not 1 )
Haskar says:
So if I did if(!$lol != 1) it would be NOT NOT meaning YES?
Bauklotz says:
Yes.
Haskar says:
ok
Haskar says:
Got everything so far
Bauklotz says:
So the script checks if the senders name is me.
Bauklotz says:
"Bauklotz"
Bauklotz says:
If it is, it uses the RETURN keyword.
Bauklotz says:
This is used for giving back strings.
Bauklotz says:
Example:
Haskar says:
May I make an example
Bauklotz says:
function get()
{
return "Rocketlauncher pie";
}
echo(get());
Output: echos to console: Rocketlauncher pie
Bauklotz says:
Make a example.
Bauklotz says:
NOTICE: If you RETURN a string, this will end the function.
Haskar says:
function (%msg)
{
%msg="string";
return %msg;
}
function lol(%client)
{
echo ("do I need to put args here or not?");
}
Bauklotz says:
wrong
Haskar says:
xD got removed.
Bauklotz says:
not echo (args);
Bauklotz says:
echo(function(args));
Haskar says:
ok
Bauklotz says:
But haskar
Bauklotz says:
If you are going to use a variable you dont need to have it on argument list
Bauklotz says:
The following example is valid:
Bauklotz says:
function nothing()
{
%string = "pie";
}
Haskar says:
ok
Bauklotz says:
And if you use return, it ends the function.
Bauklotz says:
Example:
Bauklotz says:
echo("Bai!");
return;
echo("wtf?");
Bauklotz says:
It will NOT echo wtf? because it ends when return is used.
Haskar says:
right
Bauklotz says:
Okay.
Bauklotz says:
Now we check if the global variable LastMessage[%name] is the message.
Bauklotz says:
TorqueScript sadly doesn't have arrays.
Bauklotz says:
But it has something that can be used for it.
Bauklotz says:
$MyVar[1] = pie;
Bauklotz says:
$MyVar[0] = non;
Bauklotz says:
echo($MyVar[1]); will echo pie
Bauklotz says:
echo($MyVar[0]); will echo non
Bauklotz says:
very useful
Bauklotz says:
It can have multiple dimensions
Haskar says:
So basicly, they are not arrays, but they are normal vars that look like arrays?
Bauklotz says:
$MyVar[1,"pie"] = nothing;
Bauklotz says:
$MyVar[1,"non"] = wtf;
Bauklotz says:
Yeah, sorta. $MyVar[1] can be accessed as $MyVar1 too.
Haskar says:
So we could make $MyVar( a string, then by user input 1 or 0 and then ) as a string and it would work?
Bauklotz says:
It doesn't have to be 0 or 1.
Bauklotz says:
And a goody thing about TorqueScript is that it will not return a error if the string doesn't exist, it will just return NULL
Bauklotz says:
(a blank string)
Bauklotz says:
Yeah hask, but it's $MyVar[stuff], not $MyVar(stuff)
Haskar says:
ok
Haskar says:
[], not ()
Haskar says:
ok
Bauklotz says:
now
Haskar says:
So
Bauklotz says:
if global var LastMessage's variable for that persons name is the SAME as what it said
Haskar says:
$LastMessage stores the last messages of everyone on the server?
Bauklotz says:
that means that this message is the same as the previous from that name
Bauklotz says:
yes hask
Haskar says:
And you can use it as $LastMessage[%name]
Haskar says:
to retrieve the last message of %name
Bauklotz says:
So the script sees if the same message was said twice in 2 diffirent messages
Bauklotz says:
yes
Haskar says:
Seems simple after explaining
Bauklotz says:
then it triggers BBotSay("Don't spam, "@%name);
Bauklotz says:
And that appears in chat as BlockBot: Don't spam, personthatsaidit.
Haskar says:
So if the last message is equal to the "current message" it says that
Bauklotz says:
yes
Haskar says:
ok
Haskar says:
That cleared me up
Bauklotz says:
then after the check it updates the variable.
Bauklotz says:
$LastMessage[%name] = %message;
Haskar says:
Oh
Bauklotz says:
If it updated before, it would always be true
Haskar says:
So $LastMessage is made by Blockbot
Bauklotz says:
Yes.
Haskar says:
ok
Bauklotz says:
Now heres a little advanced thing
Bauklotz says:
striPos(hay,needle) returns the first found case insensitive needle in hay.
Bauklotz says:
If "needle" isn't inside "hay", it returns -1
Bauklotz says:
So we check if the thing it gives back is zero or higher (not negative)
Haskar says:
ok
Bauklotz says:
That means that if it is positive, needle is in hay
Haskar says:
So we are checking for SLAP in a %message?
Bauklotz says:
That IF check just checks if "slap" and "blockbot" is the message.
Haskar says:
And Blockbot too, right
Haskar says:
Or else infininity loop
Bauklotz says:
And no spaces are needed. meslapblockbot would work.
Bauklotz says:
As you see above, it cancels the function if it was sent by me
Bauklotz says:
To avoid loops
Bauklotz says:
Now it says the thing that you get on IRC if you slap blockbot.
Haskar says:
Then just the usual BBotSay
Bauklotz says:
* Name slaps victim around with a whale bone!
Bauklotz says:
That's it.
Haskar says:
Okay
Bauklotz says:
Now we activate the functions in the package.
Bauklotz says:
DONE
Haskar says:
Also, just 1 question, will $varnamehere work for a server-side thingy for the entire server time, AKA when I bring it up till I bring it down?
Bauklotz says:
Well.
Bauklotz says:
If you set a variable, that variable will exist until you manually remove it, or the game ends.
Bauklotz says:
game ends = blockland quit();
Haskar says:
If I set a $ var, not %?
Haskar says:
Or both
Bauklotz says:
Well.
Bauklotz says:
$ vars exist everywhere.
Bauklotz says:
% vars are removed when the function ends.
Bauklotz says:
Example:
Bauklotz says:
function do_this()
{
%cake = "exists";
}
Bauklotz says:
do_this();
Then type:
echo(%cake);
Bauklotz says:
Output: Blank string echoed (variable doesnt exist)
Bauklotz says:
get it?
Haskar says:
ok
Bauklotz says:
Just a small thing:
Haskar says:
Yes, I can understand the concept of local and global variables
Bauklotz says:
the ELSE keyword has the same syntax as IF, but does not have (expression)
Bauklotz says:
The ELSE keyword is just used below a IF statement used as a alternate thing if the latest IF check was FALSE.
Bauklotz says:
Okay?
Haskar says:
Yes, I know that from C++
Bauklotz says:
Okay.
Bauklotz says:
The following example echos (^ will be used here as new line):
0^1^2^3^4
Bauklotz says:
for( %i=0; %i<5; %i++ )
{
echo(%i);
}