Ok, is it a good Idea to code simple events as a start?
It won't hurt, however it's by far not the easiest way to start.
Most people start by modifying weapons. (And spamming dataBlocks.)
The reason is that theres a set system for interacting with game content, where as with what most people start off with (/ commands)
doesn't have a definite way to interact with the game.
... If I understand what you have said correctly, it is completely false.
serverCmds (/commands) are just functions like anything else.
You can do whatever you want inside these functions.
The only special thing about functions whose names begin with serverCmd is that they may be called on the server by a client via commandToServer() (a client sided function.)
Also, similar to methods I describe below, serverCmd functions get an argument passed to them whenever they are called by a client, this is the client object who invoked the function call.
For example:
function serverCmdKillMyPlayer(%client) {
if(isObject(%client.player))
%client.player.kill();
}
The above would kill the player (if it exists) of the client who invoked the function call.
However you can also do much more complex things that are totally unrelated with the client.
For example dumping the title of the blockland homepage to the chat whenever somebody types /iLoveThisGame:
function blocklandFetcher::onConnected(%this) {
%this.send("GET / HTTP/1.1" NL "Host: blockland.us\n");
%this.send("");
}
function blocklandFetcher::onLine(%this, %line) {
if(strPos(strToLower(%line), "<title>") != -1) { //I don't believe case sensitivity is a potential issue anyway, strtoLower is probably not necessary.
talk(strReplace(strReplace(%line, "<TITLE>", ""), "</TITLE>", "")); //Talk() sends chat to players, and normally I would do a subString
//mess to get the title as the line containing the title may contain other stuff as well as the title.
//However for the purposes of this example, it doesn't really matter because blockland.us has the title on it's own line (for the time being).
%this.disconnect();
%this.delete();
}
}
function serverCmdILoveThisGame() {
%obj = new tcpObject(blocklandFetcher);
%obj.connect("blockland.us:80");
}
More on %this later.
Note: If I were writing this for a real script, I would have added more error handling callbacks.
I understand how register Output/input event works, and I also understand programming because I can program simple programs in C++, and I understand objects/classes (one of the main parts of scripting) because I can do it in C++.
...
I have finally understood something: those who learn scripting by just looking at the script have had experience. I have finally started to get some of the concepts, and I really want to learn.
Reading other people's scripts is how I started. Eventually you will want to read some stuff on GG (Garage Games) because just because blocklanders do stuff that work, it doesn't mean there isn't a better way. (Unless you're space guy in which case what you're doing is such a big hack that the way you're doing it at the moment is the ONLY way it can be done at all!)
What exactly is the %this that I see everywhere, er, what does it stand for, and where does it come from?
Obviously its a argument that the function is recieving and modifying, but I don't know where its coming from since it is very vague.
You're right to a certain extent.
%this is just what people generally use as the first argument of a method of an object.
This argument is always the object on which you are calling a given method.
For example:
function tcpObject::onConnected(%this, %line) {
%this.send("Hello World!");
}
would be a method of tcpObjects.
In this case, the onConnected callback is called whenever a given tcpobject successfully establishes a connection, but that is beside the point.
%this, is set to the object that was just connected.
I then use %this to use that connected object, and send "Hello World!" to that connection via the object %this.
The argument does not necessarily need to be %this.
It could be %bob.
new scriptObject(uselessObject) {
class = "whenIDoStuffIGetDeleted";
};
function whenIDoStuffIGetDeleted::doStuff(%bob) {
echo("deleting" SPC %bob.getID());
%bob.delete();
}
uselessObject.doStuff();
In this example, we create a scriptObject named uselessObject, this scriptObject is a member of the whenIDoStuffIGetDeleted class. Then, we create a method of the whenIDoStuffIGetDeleted class, this method is named doStuff. In this case, it is important that we have %bob to detect which object this method is being called on, otherwise we might delete the wrong object.
Note: I didn't test any of my examples.