BullyWiiPlaza
Modder
- Messages
- 214
- Reaction score
- 174
- Points
- 818
I created the following functions to make toggles and printing easier. I distinguish between global prints which should be announced to everyone in the center of the scren using your name so that they know who did what and local prints which are only announced to you in the killfeed. According to which kind of mod you have, you may set the
variable to true or leave it undefined.
If I wanted to toggle god mode I would for example write the following:
What happens here is when you run the function it will say
in the killfeed to you only and turn god mode on. When you run the function again, it will print
and it will turn it off. As you can see, clean code. Note: Always using brackets after an if or else is good coding style but if you really wanted, you could omit them. I don't.
Our next example is a so-called global mod being toggled. For this I'll use the dvar for player movement speed:
Notice how I'm using the level entity to attach the variable since it's a level variable and not a self variable. Also I'm using a third argument for
because I want it to be printed globally to the center of the screen and not just in the killfeed of the invoker.
When you run the function the first time it will say your name followed by a colon and
. It also turns the mod on. Then if you run the function again, you can imagine what happens. I'm using the
Now compare, what do you prefer writing? The basic way like as follows
or "my" way? I guess the answer is obvious.
Code:
printGlobally
Code:
printToggleState(modName, toggleVariable, printGlobally)
{
if(!isDefined(printGlobally))
{
printGlobally = false;
}
message = modName + " ";
if(toggleVariable)
{
message += booleanToString(true);
if(printGlobally)
{
message = modName + " " + booleanToString(true);
printGlobalPlayerAction(message);
return;
}
self iPrintln(message);
return;
}
message += booleanToString(false);
if(printGlobally)
{
message = modName + " " + booleanToString(false);
printGlobalPlayerAction(message);
return;
}
self iPrintln(message);
}
printGlobalPlayerAction(action)
{
iPrintlnBold(self.name + ": " + action);
}
booleanToString(booleanVariable)
{
return booleanVariable ? "^2ON^7" : "^1OFF^7";
}
Code:
toggleGodMode()
{
self.godMode = invertAndPrint("God Mode", self.godMode);
if(self.godMode)
{
self enableInvulnerability();
}
else
{
self disableInvulnerability();
}
}
Code:
God Mode ^2ON
Code:
God Mode ^1OFF
Our next example is a so-called global mod being toggled. For this I'll use the dvar for player movement speed:
Code:
toggleSuperSpeed()
{
level.superSpeed = invertAndPrint("God Mode", level.superSpeed, true);
setDvar("g_speed", self.godMode ? 400 : 90);
}
Code:
invertAndPrint()
When you run the function the first time it will say your name followed by a colon and
Code:
Super Speed ^2ON
You do not have permission to view link
Log in or register now.
to shorten the code even further.Now compare, what do you prefer writing? The basic way like as follows
Code:
toggleGodMode()
{
if(!isDefined(self.godMode))
{
self.godMode = true;
self iPrintln("God Mode ^2ON");
self enableInvulnerability();
}
else
{
self.godMode = undefined;
self iPrintln("God Mode ^1OFF");
self disableInvulnerability();
}
}
Last edited: