Sorry for the text wall, but I tried to explain this as simply as I could. Please tell me if you didn't understand part of it. (Anyone else: please tell me if I got any of this wrong :P)
On RTB prefs:As Thorfin25 stated, you can also combine the Super Admin and Admin checks into one variable using a List pref. General format:
RTB_registerPref("[GUIName]", "[GUICategory]", "[PrefName]", "list [Opt0] 0 [Opt1] 1 [Opt2] 2 [Opt3] 3...", "[ModName], 1, 0, 0);where [Opt0], [Opt1], etc. are the names of your options. It's possible to use more than two options, so let's add a Host-Only setting. (Unfortunately, I don't remember how to check if a client is the host - you'll have to ask someone else.) In this case, the code should be something like:
RTB_registerPref("Restriction Level","ClearGhostBricks","OAA::AdminLevel","list Admin 1 SuperAdmin 2 Host 3","Server_Clearghostbricks",1,0,0);If this is used, then $OAA:AdminLevel will be 1 for admins and above, 2 for super admins, and 3 for host-only. This is set with a dropdown list of options (of course!) in the RTB prefs menu. It'd probably be a good idea to make sure only the host can change it, but I don't remember how to do that. It's one of those last 3 arguments ('1, 0, 0').
On binary logic:You don't need to define two functions at all (if you want to, there's more on that topic later), or even use two Ifs. Basically: '&&' means 'And', '||' means 'Or'. The P in PEMDAS applies to these - &&s and ||s in parentheses are used first. Let's combine the check for admin and the check for super admin, and tell the client if they can't clear ghost bricks.
if((!%client.isAdmin && $OAA:AdminLevel == 1) || (!%client.isSuperAdmin && $OAA:AdminLevel == 2)) {
messageClient(%client, "<color:00ffff>Server<color:ffffff>: You don't have permission to clear ghost bricks.");
return;
}
//Rest of the function.Or, a more readable version, with the way it'd be written in english:
if( //IF
(!%client.isAdmin //the client is NOT admin or super admin
&& $OAA:AdminLevel == 1) //AND the admin restriction level is '1'...
|| //OR,
(!%client.isSuperAdmin //if the client is NOT super admin (but might be a normal admin)
&& $OAA:AdminLevel == 2) //AND the admin restriction level is '2'...
) { //THEN
messageClient(%client, "<color:00ffff>Server<color:ffffff>: You don't have permission to clear ghost bricks.");
//tell the client they can't clear ghost bricks
return; //and ignore the rest of the function.
} //Otherwise, if the client met the restrictions, continue to
//the rest of the function.On having two 'function serverCmdClearGhostBricks's:As everyone's saying, defining a function 'only works once'. Every time you make a function with the same name, all previous times go ignored by Blockland. For example, let's say I want to make a function to add two numbers together.
AddNumbers.cs:function AddThese(%a, %b) {return %a ++;}Upon testing, I notice that the function doesn't do what I want it to at all! I forgot what ++ is for - it just adds 1 to a variable. AddThese(%a, %b) completely ignores %b and just adds 1 to %a - AddThese(2, 9) is 3 instead of 11! Instead of changing the function, I type a new one before it:
AddNumbers.cs:function AddThese(%a, %b) {return %a + %b;}
function AddThese(%a, %b) {return %a++;}To my surprise, the function still doesn't work! This is because only the second one - the last to appear in the code, in this case - is used. The line '
function AddThese(%a, %b) {return %a + %b;}' does absolutely nothing, in this case.
On Packages and 'parent::':There
is a way to define a function twice and have it do both things. You need to use a package and parent the older function.
Let's say I want a function that makes the console say 'Hi!', aptly named 'SayHi'.
SayHi.cs:function SayHi() {
echo("Hi!");
}Easy enough! But what if I also want to make it say 'How are you doing?' This should be easy - but the catch is, I absolutely
need it in a separate function (to keep it organized or something).
THIS WILL NOT WORK:SayHi.cs:function SayHi() {
echo("Hi!");
}
function SayHi() {
echo("How are you doing?");
}As above, Blockland entirely ignores the first function, using the second one instead. To fix this, we first need to put the second function in a
package so it doesn't override the first...
SayHi.cs:function SayHi() {
echo("Hi!");
}
package AlsoAskHow { //everything past this line is in a "package" named "AlsoAskHow"
function SayHi() {
echo("How are you doing?");
}
}; //the package "AlsoAskHow" stops here
echo("SayHi.cs was executed!"); //this line is not part of it and will always runNote that a package differs from a function: it always has a {, but not (), after its name, and always ends with a };. Once the package is created, it can be used to switch between both SayHi()s.
-Using
ActivatePackage(AlsoAskHow); will make SayHi(); result in "How are you doing?".
-Using
DeactivatePackage(AlsoAskHow); will make SayHi(); result in "Hi!".
Basically - a package is used to 'enable' or 'disable' pieces of your code whenever you want to do so. (All new packages are 'disabled' by default.) The problem with this is that the console still only says either one line or the other. To use both of them, we need to tell the function in the package to use the function outside the package.
Blockland considers the function outside of the package to be the "original" function. We can use this to refer to it from the one inside the package, like so:
function SayHi() {
echo("Hi!");
}
package AlsoAskHow {
function SayHi() {
parent::SayHi(); //this basically means "use the original SayHi here"
echo("How are you doing?");
}
};Please note that packages are very useful in certain situations, but
SHOULD NOT be used to tack pieces onto one function like this. You can add that code to the function itself just as easily.
Edit: Whoops, apparently there's an explanation of
why packages are useful
here and I didn't even notice it.