CabConModding
Facebook
Twitter
youtube
Discord
Contact us
RSS
Menu
CabConModding
Home
New
Top
Premium
Rules
FAQ - Frequently Asked Questions
Games
Fornite
Call of Duty: Black Ops 3
Clash of Clans
Grand Theft Auto 5
Apex Legends
Assassin’s Creed Origins
Forums
Premium
Latest posts
What's new
Latest posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Log in
Register
What's new
Premium
Latest posts
Menu
Log in
Register
Navigation
Install the app
Install
More options
Dark Theme
Contact us
Close Menu
Forums
Gaming
Call of Duty Classics
Call of Duty: Black Ops 2
Call of Duty: Black Ops 2 Mods and Scripts
Call of Duty: Black Ops 2 Scripts
Printing/Toggle Utilities
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="BullyWiiPlaza" data-source="post: 1186" data-attributes="member: 543"><p>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 [CODE]printGlobally[/CODE] variable to true or leave it undefined.</p><p>[CODE]printToggleState(modName, toggleVariable, printGlobally)</p><p>{</p><p> if(!isDefined(printGlobally))</p><p> {</p><p> printGlobally = false;</p><p> }</p><p></p><p> message = modName + " ";</p><p></p><p> if(toggleVariable)</p><p> {</p><p> message += booleanToString(true);</p><p></p><p> if(printGlobally)</p><p> {</p><p> message = modName + " " + booleanToString(true);</p><p> printGlobalPlayerAction(message);</p><p> return;</p><p> }</p><p></p><p> self iPrintln(message);</p><p> return;</p><p> }</p><p></p><p> message += booleanToString(false);</p><p></p><p> if(printGlobally)</p><p> {</p><p> message = modName + " " + booleanToString(false);</p><p> printGlobalPlayerAction(message);</p><p> return;</p><p> }</p><p></p><p> self iPrintln(message);</p><p>}</p><p></p><p>printGlobalPlayerAction(action)</p><p>{</p><p> iPrintlnBold(self.name + ": " + action);</p><p>}</p><p></p><p>booleanToString(booleanVariable)</p><p>{</p><p> return booleanVariable ? "^2ON^7" : "^1OFF^7";</p><p>}[/CODE]</p><p>If I wanted to toggle god mode I would for example write the following:</p><p>[CODE]toggleGodMode()</p><p>{</p><p> self.godMode = invertAndPrint("God Mode", self.godMode);</p><p></p><p> if(self.godMode)</p><p> {</p><p> self enableInvulnerability();</p><p> }</p><p> else</p><p> {</p><p> self disableInvulnerability();</p><p> }</p><p>}[/CODE]</p><p>What happens here is when you run the function it will say [CODE]God Mode ^2ON[/CODE] in the killfeed to you only and turn god mode on. When you run the function again, it will print [CODE]God Mode ^1OFF[/CODE] and it will turn it off. As you can see, clean code. Note: Always using brackets after an <strong>if</strong> or <strong>else </strong>is good coding style but if you really wanted, you could omit them. I don't.</p><p></p><p>Our next example is a so-called global mod being toggled. For this I'll use the dvar for player movement speed:</p><p>[CODE]toggleSuperSpeed()</p><p>{</p><p> level.superSpeed = invertAndPrint("God Mode", level.superSpeed, true);</p><p> setDvar("g_speed", self.godMode ? 400 : 90);</p><p>}[/CODE]</p><p>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 [CODE]invertAndPrint()[/CODE]because I want it to be printed globally to the center of the screen and not just in the killfeed of the invoker.</p><p></p><p>When you run the function the first time it will say your name followed by a colon and [CODE]Super Speed ^2ON[/CODE]. It also turns the mod on. Then if you run the function again, you can imagine what happens. I'm using the <a href="https://en.wikipedia.org/wiki/%3F:" target="_blank">ternary operator</a> to shorten the code even further.</p><p></p><p>Now compare, what do you prefer writing? The basic way like as follows</p><p>[CODE]toggleGodMode()</p><p>{</p><p> if(!isDefined(self.godMode))</p><p> {</p><p> self.godMode = true;</p><p> self iPrintln("God Mode ^2ON");</p><p> self enableInvulnerability();</p><p> }</p><p> else</p><p> {</p><p> self.godMode = undefined;</p><p> self iPrintln("God Mode ^1OFF");</p><p> self disableInvulnerability();</p><p> }</p><p>}[/CODE]or "my" way? I guess the answer is obvious.</p></blockquote><p></p>
[QUOTE="BullyWiiPlaza, post: 1186, member: 543"] 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 [CODE]printGlobally[/CODE] variable to true or leave it undefined. [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] If I wanted to toggle god mode I would for example write the following: [CODE]toggleGodMode() { self.godMode = invertAndPrint("God Mode", self.godMode); if(self.godMode) { self enableInvulnerability(); } else { self disableInvulnerability(); } }[/CODE] What happens here is when you run the function it will say [CODE]God Mode ^2ON[/CODE] in the killfeed to you only and turn god mode on. When you run the function again, it will print [CODE]God Mode ^1OFF[/CODE] and it will turn it off. As you can see, clean code. Note: Always using brackets after an [B]if[/B] or [B]else [/B]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: [CODE]toggleSuperSpeed() { level.superSpeed = invertAndPrint("God Mode", level.superSpeed, true); setDvar("g_speed", self.godMode ? 400 : 90); }[/CODE] 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 [CODE]invertAndPrint()[/CODE]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 [CODE]Super Speed ^2ON[/CODE]. It also turns the mod on. Then if you run the function again, you can imagine what happens. I'm using the [URL='https://en.wikipedia.org/wiki/%3F:']ternary operator[/URL] 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(); } }[/CODE]or "my" way? I guess the answer is obvious. [/QUOTE]
Verification
Post reply
Forums
Gaming
Call of Duty Classics
Call of Duty: Black Ops 2
Call of Duty: Black Ops 2 Mods and Scripts
Call of Duty: Black Ops 2 Scripts
Printing/Toggle Utilities
CabConModding is now on facebook! Check the latest Updates, the Site Status and much more now!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…
Top