CLEO Tutorial
Understanding the Code
Understanding the Code
I've come to write a tutorial for people ranging from those who know nothing about CLEO to those who know how to make scripts but still have things to learn. The best way, I've found, to learn CLEO is by looking at scripts, but to successfully look at the scripts and comprehend the content in them one has to understand some basics, some meanings. This will be the starter's dictionary for CLEO.
Types of scripters in CLEO:
- Beginner
- Doesn't understand how CLEO scripts work.
- Cannot create a script in CLEO without errors/mistakes/bugs.
- Doesn't fully understand how CLEO language works and its dictionary.
- Cannot create a script from scratch.
- Doesn't know how to use snippets.
- Doesn't know how to write/hack memory.
- Novice
- Understands the code from CLEO scripts generally.
- Knows how to write and create (basic) CLEO scripts (not necessarily fully).
- Understands how CLEO language works and at least half of its dictionary.
- Cannot create a script from scratch.
- Knows how to use snippets only with examples.
- Doesn't know how to write/hack memory.
- Mediocre
- Understands most of the code from CLEO scripts.
- Knows how to fully create (at least basic) scripts.
- Fully understands CLEO language and most if its dictionary.
- Can create a script from scratch with minor help.
- Knows how to use snippets.
- Doesn't know how to write/hack memory.
- Experienced
- Understands all the code within CLEO scripts.
- Knows how to fully and completely create scripts with all given functions.
- Fully understands CLEO language and all of its dictionary.
- Can create a script from scratch without any help.
- Knows how to use snippets.
- Knows how to write/hack memory with the help of snippets.
- Expert
- Understands all code from CLEO scripts.
- Knows how to fully and completely create scripts with all given functions.
- Fully understands CLEO language and all of its dictionary.
- Can create a script from scratch without any help
- Knows how to use snippets.
- Knows how to write/hack any kind of memory without any snippets.
This tutorial is for beginner, novice and mediocre scripters.
- If you know very little to nothing about CLEO and Sanny Builder, start from Chapter I and go on slowly.
- If you are a novice in scripting, you may start from the Chapter II.
- If you are mediocre, I suggest you check out Chapter II and jump straight to Chapter III.
Chapter I
About CLEO and Sanny Builder
About
CLEO and Sanny Builder started as and still are mission editors for GTA singleplayer series developed by Seemann and Deji. Yes, singleplayer; CLEO has never been intended to write beyond singleplayer, but as we can see, it can be used to do just that. More information can be found on the official website.
ASI Loader
There is also a small piece of script called 'ASI Loader'; this is intended for developers to be able to load scripts created in C language, but instead of .dll they have .asi extension. The original one by JernejL may be found here and the one by SilentPL may be found here.
Plugins
CLEO and Sanny Builder support the use of plugins, thanks to that we have SAMPFUNCS by FYP and MGFuncs. I've always preferred SAMPFUNCS over MGFuncs, and I will always use SAMPFUNCS; why? Because it is being updated more often and contains a lot more features. The latest version SAMPFUNCS by FYP can be acquired at BlastHack.net or Cheat-Master.ru or UGBase.eu. In order to install SAMPFUNCS all you have to do is drop SAMPFUNCS.asi in your GTA San Andreas (root) directory.
SAMPFUNCS
If you want to start scripting using the opcodes, variables and benefits given by SAMPFUNCS you must install SB (Sanny Builder) data. In order to do that just locate the SB Data folder within the downloaded package, copy the contents from inside the SB Data folder to [Sanny Builder 3 installation directory]\data\sa\ (C:\Program Files\Sanny Builder 3\data\sa is by default); replace, yes to all. And now you are ready to use SAMPFUNCS in your scripts.
CLEO Versions
You would often see these versions: CLEO 4.4, CLEO 4.1 and CLEO 4.3. And in this precise order because CLEO 4.4 > CLEO 4.1 > CLEO 4.3. CLEO 4.1 is the standard version of CLEO used for years, and still is, because until recently it supported the most mods (for multiplayer), unlike 4.3, but there came the custom and unofficial version 4.4 created by SR_Team. While 4.3 is the latest official version that ditches a lot of support for scripts used so far and for multiplayer, CLEO 4.4 by SR_Team is a modified and custom version of CLEO that supports the most of everything, and it can be found here.
Help Documentation of Sanny Builder
Useful documentation can be found in Sanny Builder by pressing F12 or clicking 'Help' and choosing 'Contents' from the dropdown menu. Choose 'Coding' (2nd option from top) and enjoy.
Help Documentation of Sanny Builder
Useful documentation can be found in Sanny Builder by pressing F12 or clicking 'Help' and choosing 'Contents' from the dropdown menu. Choose 'Coding' (2nd option from top) and enjoy.
Chapter II
The 101 Dictionary
Introduction
Here I will be talking about what things generally and in scripts mean. Examples, snippets and actual scripts can be found in Chapter III.
Basic Terminology
Opcode
Operation code that starts with 0, has 4 characters and ends with :. Anything past the : is either just a piece of text to tell what the opcode does or a parameter that allows the operation code to do what it needs to do. That parameter can be anything: Weapon ID, car ID, text, color, a number, etc.
Boolean
State that can only be true or false. In the script any number can be assigned to represent true and/or to represent false.
Class
Class in the script means a category that can be used as check, proc or property. Check is used in IF conditional sentence as a condition. Proc stands for procedure and is used as a consequence of the condition (After THEN, ELSE). Property is something between proc and check, it is used to get something from something or set something to something. Classes start with a word such as Actor, Player, Car, File, etc. followed by a dot (.) after which check, proc and property come. Example: Actor.Driving($PLAYER_ACTOR) is a check and it will check if player is driving in the IF conditional sentence. To display classes and keywords press CTRL + Space in Sanny Builder.
Keywords
Keywords are commands, set bold in Sanny Builder, they operate/function like opcodes. Each keyword has a task. Keywords are for example: IF, THEN, END, shake_camera, key_down, thread, set_weather, etc. Keywords can be both checks and procedures. For example the wait <milliseconds> keyword will pause the script for the set amount of milliseconds when the script reaches the wait keyword. To display classes and keywords press CTRL + Space in Sanny Builder.
Directives
Directives are places at the beginning of the script in the braces (curly brackets - {}), $ symbol is put before them. Directives include $CLEO, $VERSION, $NOSOURCE, $INCLUDE, etc.
Basic CLEO Syntax (Snippets)
Low-code
Low-code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | {$CLEO} 0000: NOP thread 'snippet' label_1 wait 0 03C0: 5@ = actor $PLAYER_ACTOR car if Actor.Driving($PLAYER_ACTOR) else_jump @label_2 Car.Destroy(5@) jump @label_1 :label_2 wait 0 0AF8: samp add_message_to_chat "{8650AC}[Snippet]: {FF0000}You are not driving!" color 0xFFFFFF jump @Label_1 |
High-code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | {$CLEO} 0000: NOP thread 'snippet' :label_1 wait 0 03C0: 5@ = actor $PLAYER_ACTOR car IF Actor.Driving($PLAYER_ACTOR) THEN Car.Destroy(5@) ELSE 0AF8: samp add_message_to_chat "{FF0000}You are not driving!" color 0xFFFFFF END |
High-level uses IF-THEN-ELSE-END statements, often referred to as high-code.
Basics from the Snippet-Script
0000: NOP
0000: is an opcode that does nothing. It is put in the beginning of the script, after {$CLEO}, in order for script to be able to be compiled. And Sanny prevents compiling if it is not there, apparently, to prevent bugs.
wait 0
A form of the wait keyword with number 0 that has a similar function in the label like the 0000: opcode has in the script. It is put at the very beginning of the labels, otherwise, for an unknown reason, the script crashes. NOTE: This is only about wait 0, not the entire wait keyword.
{$CLEO}
Is a directive arks that the script is made in CLEO and will be saved as a CLEO script for that GTA version (GTA San Andreas PC CLEO script extension is .cs)
thread
Is a keyword that creates a thread in the system; if there is no source available all labels will get the name of the thread.
:label
: marks the start of a label. The label is basically a work space where a certain piece of code (snippet) will be operating.
@label
@ marks the label itself and interaction with it within a code sentence. It can be used with a simple sentence such as jump, else_jump or with more advanced ones such as call.
$Variable
Global variables that come from the base of the CLEO and GTA itself start with $. These variables are not defined by the script but by the game/CLEO (SB) itself. They have the same meaning in all scripts. A script can define a global variable, however it is bad to do so as it may interfere with other scripts.
0@ to 31@
These are local variables defined in the script itself and used only by the part of the script they are defined in. It is possible to have multiple local variables of the same alias (number) but defined differently in different parts of the script. Regular variables may range from 0@ to 31@. Usually 0@ and 31@ are used to define boolean (true or 1 and false or 0) states of a command. 32@ and 33@ are timere. It is possible to define more variables, but we may talk about that later.
Conditions and Functions
IF
Keyword used as a conditional sentence, just like in real life. The condition can be written below or next to IF. The condition must be true/met in order for script to proceed.
IF AND
The conditional sentence where all conditions must be true for the script to proceed (maximum in Sanny Builder/CLEO is 8 conditions under one IF AND or IF OR).
IF OR
The conditional sentence where either of the given conditions must be true for the script to proceed (maximum in Sanny Builder/CLEO is 8 conditions under one IF AND or IF OR).
THEN
Keyword used as a consequence to the condition(s) under the IF conditional sentence.
ELSE
Keyword used as a consequence to the condition under IF conditional sentence, if that condition is NOT true.
END
Used to mark the end of IF-THEN(-ELSE) high-level code.
jump or goto
Keyword used to move to another label. Can be used as one of the consequences under THEN. At the end of the low-level script it marks where the script should go.
else_jump or jf
Keyword used as a consequence to the condition under IF like ELSE. The script will go to the given label.
FOR-TO(-STEP)
This system of functions is used for a limited loop. It is extremely rarely used in CLEO.
1 | for 31@ = 0 TO 10 step 1
|
1 2 3 4 5 6 7 8 9 10 11 | WHILE TRUE wait 0 for 31@ = 0 TO 10 step 1 wait 0 0AD1: show_formatted_text "The for loop is on %d" time 10 31@ end 0AD1: show_formatted_text "31@ is 10 or greater, for loop ends" 3000 wait 3000 END |
This is a high-level system, and its low-level compeer would look like this:
1 2 3 4 5 6 7 8 9 10 11 | :reset_loop 31@ = 0 // This will set the script to 0 :for_loop wait 0 // as we've said - necessary 0AD1: show_formatted_text "The for loop is on %d" time 10 31@ 31@ += 1 // this is step 1 IF 31@ = 10 // If 31@ is 10 or greater else_jump @for_loop // it will repeat until the condition is true 0AD1: show_formatted_text "31@ is 10 or greater, for loop ends" 3000 // result of the loop |
GOSUB-RETURN
Gosub is a keyword that will jump to another label and return back to where the gosub was. It can be used in loops or just generally when people want to make things look cleaner in low-code. It is primarily used in low-level coding. At the end of the label that gosub went to there shall be return keyword, which tells the script to return back to where it came from and continue from there.
Chapter III
Advanced
Variable/data types
5@
Local variable that can be any number.
5@s
Local short string variable.
5@v
Local long string variable.
$Anything
Global variable.
#
Model identifier. Used to mark models, such as #ADMIRAL or #AK47.
Mathematical Conditions
NOTE: Use only under IF conditional sentence as conditions!
A == B
A is equal to B
A > B
A is greater than B
A >= B
A is greater than B or equal to B
A < B
A is less than B
A <= B
A is less than B or equal to B
A <> B
A is unequal to B
Simple Value Manipulation (Math Calculations)
1@ = 25
25@ = 0
0@ = True
31@ = False
This operation sets/gives a value to the variable..
0@ and 31@ are booleans; their value is either 1 or 0, true or false.
NOTE: Not to be confused with == which checks the value!
000A:
1@ += 1
Mathematical operation: addition
Changes value 1@ for the given number using the mathematical operation.
1@ -= 1
Mathematical operation: subtraction
Changes value 1@ for the given number using the mathematical operation.
0012:
1@ *= 1
Mathematical operation: multiplication
Changes value 1@ for the given number using the mathematical operation.
0016:
1@ /= 1
Mathematical operation: division
Changes value 1@ for the given number using the mathematical operation.
Advanced
Variable/data types
5@
Local variable that can be any number.
5@s
Local short string variable.
5@v
Local long string variable.
$Anything
Global variable.
#
Model identifier. Used to mark models, such as #ADMIRAL or #AK47.
Mathematical Conditions
NOTE: Use only under IF conditional sentence as conditions!
A == B
A is equal to B
A > B
A is greater than B
A >= B
A is greater than B or equal to B
A < B
A is less than B
A <= B
A is less than B or equal to B
A <> B
A is unequal to B
Simple Value Manipulation (Math Calculations)
1@ = 25
25@ = 0
0@ = True
31@ = False
This operation sets/gives a value to the variable..
0@ and 31@ are booleans; their value is either 1 or 0, true or false.
NOTE: Not to be confused with == which checks the value!
000A:
1@ += 1
Mathematical operation: addition
Changes value 1@ for the given number using the mathematical operation.
000E:
Mathematical operation: subtraction
Changes value 1@ for the given number using the mathematical operation.
0012:
1@ *= 1
Mathematical operation: multiplication
Changes value 1@ for the given number using the mathematical operation.
0016:
1@ /= 1
Mathematical operation: division
Changes value 1@ for the given number using the mathematical operation.
Chapter IV
Complex Body and Syntax (Snippets)
Coming Soon
It would Russian...
ReplyDeleteno. English is the most popular language that's almost know by everyone.
DeleteThanks!
ReplyDeletePlease :) I need full :)))
ReplyDeleteWtf still coming soon
ReplyDeleteHe's no more working on this. Just forget it.
DeleteIt means gosub function some like execute/read multiple script ?
ReplyDeleteCan anyone create sanny builder for android (.apk)
ReplyDeleteUse exagear and install sannynbuilde.exe in exagear
Delete2020.... Still coming soon 😂
ReplyDelete😂😂😂
DeleteStill Coming Soon Please Upload Next Chapter Soon Please 😭😭😭🙏🙏🙏🙏
ReplyDelete"wait 0" is necessary not for some unknown reason, but so that while our script is sleeping this mental amount of time (0 milliseconds), other scripts can be executed.
ReplyDeleteA very useful article for beginners.
But I would not call gosub low-code, not all beginner scripters prefer to use it, but experienced scripters do not always need to use call-scm and they use gosub.
please tutor i want make samp hack
ReplyDeletePlease Bro Please Next chapter 🙏🏻
ReplyDelete