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
Tutorial Section
Basic GSC Coding: If, Else and Else If
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="CabCon" data-source="post: 9841" data-attributes="member: 1"><p>Today I am going to explain the "if", "else if" and "else" command. The "if" checks if what its inside it is true or false and if its true, it does what its inside the "if". If what is inside the "if" is false and you have defined a "else", the program will run what you wrote in the else, this 3 commands are quite simple to use and understand, example:</p><p>[code]if( a < b )</p><p>{</p><p> c = 1;</p><p>}</p><p>else</p><p>{</p><p> c = 2;</p><p>}[/code]</p><p></p><p>The "else" is not needed to be added, only if you want to have another option in case the "if" variable is false. The "if" always has after it: "if" + "(" + the condition you want + ")". What you want to do if the condition is true goes beetween "{" and "}" (same as "while" or "for"). In the previous example its checking if a variable ("a" in my case) is smaller than the variable "b". If "a" is really smaller than "b", it will make: c = 1;. If "a" is higher or equal to "b" (the opposite to the condition) it will make what is inside the else.</p><p></p><p>You can put "if"s inside another "if"s (same applies to "else" and "else if", example:</p><p>[code]if( a < b )</p><p>{</p><p> if( a == 3 )</p><p> {</p><p> c = 4;</p><p> }</p><p> else</p><p> {</p><p> c = 3;</p><p> }</p><p>}</p><p>else</p><p>{</p><p> c = 2;</p><p>}[/code]</p><p></p><p>The "else if" I have mentioned is used when you are going to add more than 2 "if checks", the game will be checking them in order until one is true, if any is true, it will run the "else" or nothing (in case you havent defined an else), example:</p><p>[code]if( a == 1)</p><p>{</p><p> c = 1;</p><p>}</p><p>else if( a == 2 )</p><p>{</p><p> c = 2;</p><p>}</p><p>else if( a == 3 )</p><p>{</p><p> c = 3;</p><p>}</p><p>else</p><p>{</p><p> c = 4;</p><p>}[/code]</p><p></p><p>The previous example will check first if "a" is equal to 1, if its not, it will do the same with a == 2, if "a" is not 2 it will continue checking if a == 3. If any of the "if" or else conditions is true, it will set the "c" variable to 4.</p><p></p><p>Inside "if"s and "else if"s you have to use some symbols, this are the most common:</p><p><strong>==</strong> = <strong>=</strong></p><p><strong>!=</strong> = <strong>not =</strong></p><p><strong>&&</strong> = <strong>and</strong></p><p><strong>||</strong> = <strong>or</strong></p><p><strong><</strong> = <strong>smaller</strong></p><p><strong><=</strong> = <strong>smaller or =</strong></p><p><strong>></strong> = <strong>higher</strong></p><p><strong>>=</strong> = <strong>higher or =</strong></p><p><strong>!</strong> = <strong>not</strong></p><p></p><p>You can optimize "if", "else" and "else if" commands when inside them there is only 1 line of code, when that happens you can remove the "{" and "}", example:</p><p>[code]if( a < b )</p><p> c = 1;</p><p>else</p><p> c = 2;[/code]</p><p></p><p>Lets do some examples with real game stuff:</p><p>[code]if( self.name == "Tutorial" ) //If your name (ingame) is "Tutorial" you will be assigned with the variable: self.isvip</p><p> self.isvip = true;[/code]</p><p></p><p>[code]if( self isHost() ) //if you are the host it will run those 2 threads</p><p>{</p><p> self thread LeHax();</p><p> self thread AdminPowers();</p><p>}[/code]</p><p></p><p>[code]if( self getStance() == "crouch" ) //If you are crouching it will print that on screen</p><p> self iPrintLnBold( "You are crouching" );</p><p>else if( self getStance == "prone" && self getVelocity()[0] == 0 && self getVelocity()[1] == 0 ) //if you are lying down and your x and y velocities are 0 it will print that</p><p> self iPrintLnBold( "You are proning and stopped" );</p><p>else //if you are standing up it will print this</p><p> self iPrintLnBold( "You are standing up" );[/code]</p><p></p><p>[code]if( self.hasradar == 1 || self hasWeapon( "onemanarmy_mp" ) ) //if you have radar or you have OMA it will print Noobie on screen</p><p> self iPrintLn( "Noobie" );[/code]</p><p></p><p><strong>Question?</strong></p><p><a href="http://cabconmodding.com/index.php?forums/gsc-section-questions.54/" target="_blank">Ask them here</a>.</p><p></p><p>Credits to Yamato!</p></blockquote><p></p>
[QUOTE="CabCon, post: 9841, member: 1"] Today I am going to explain the "if", "else if" and "else" command. The "if" checks if what its inside it is true or false and if its true, it does what its inside the "if". If what is inside the "if" is false and you have defined a "else", the program will run what you wrote in the else, this 3 commands are quite simple to use and understand, example: [code]if( a < b ) { c = 1; } else { c = 2; }[/code] The "else" is not needed to be added, only if you want to have another option in case the "if" variable is false. The "if" always has after it: "if" + "(" + the condition you want + ")". What you want to do if the condition is true goes beetween "{" and "}" (same as "while" or "for"). In the previous example its checking if a variable ("a" in my case) is smaller than the variable "b". If "a" is really smaller than "b", it will make: c = 1;. If "a" is higher or equal to "b" (the opposite to the condition) it will make what is inside the else. You can put "if"s inside another "if"s (same applies to "else" and "else if", example: [code]if( a < b ) { if( a == 3 ) { c = 4; } else { c = 3; } } else { c = 2; }[/code] The "else if" I have mentioned is used when you are going to add more than 2 "if checks", the game will be checking them in order until one is true, if any is true, it will run the "else" or nothing (in case you havent defined an else), example: [code]if( a == 1) { c = 1; } else if( a == 2 ) { c = 2; } else if( a == 3 ) { c = 3; } else { c = 4; }[/code] The previous example will check first if "a" is equal to 1, if its not, it will do the same with a == 2, if "a" is not 2 it will continue checking if a == 3. If any of the "if" or else conditions is true, it will set the "c" variable to 4. Inside "if"s and "else if"s you have to use some symbols, this are the most common: [B]==[/B] = [B]= !=[/B] = [B]not = &&[/B] = [B]and ||[/B] = [B]or <[/B] = [B]smaller <=[/B] = [B]smaller or = >[/B] = [B]higher >=[/B] = [B]higher or = ![/B] = [B]not[/B] You can optimize "if", "else" and "else if" commands when inside them there is only 1 line of code, when that happens you can remove the "{" and "}", example: [code]if( a < b ) c = 1; else c = 2;[/code] Lets do some examples with real game stuff: [code]if( self.name == "Tutorial" ) //If your name (ingame) is "Tutorial" you will be assigned with the variable: self.isvip self.isvip = true;[/code] [code]if( self isHost() ) //if you are the host it will run those 2 threads { self thread LeHax(); self thread AdminPowers(); }[/code] [code]if( self getStance() == "crouch" ) //If you are crouching it will print that on screen self iPrintLnBold( "You are crouching" ); else if( self getStance == "prone" && self getVelocity()[0] == 0 && self getVelocity()[1] == 0 ) //if you are lying down and your x and y velocities are 0 it will print that self iPrintLnBold( "You are proning and stopped" ); else //if you are standing up it will print this self iPrintLnBold( "You are standing up" );[/code] [code]if( self.hasradar == 1 || self hasWeapon( "onemanarmy_mp" ) ) //if you have radar or you have OMA it will print Noobie on screen self iPrintLn( "Noobie" );[/code] [B]Question?[/B] [URL='http://cabconmodding.com/index.php?forums/gsc-section-questions.54/']Ask them here[/URL]. Credits to Yamato! [/QUOTE]
Verification
Post reply
Forums
Gaming
Call of Duty Classics
Tutorial Section
Basic GSC Coding: If, Else and Else If
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