Strobe Modding
Welcome to our site! Please take a moment to register or if you already have an account, LOG IN now.

 
 
HomeCalendarGalleryFAQSearchMemberlistUsergroupsRegisterLog in

Share | 
 

 [TUT] Cleo Scripting Tutorial [Part 1]

View previous topic View next topic Go down 
AuthorMessage
Reckless
Admin
avatar

Posts : 74
Join date : 2012-03-19
Age : 22
Location : Los Angeles, CA

PostSubject: [TUT] Cleo Scripting Tutorial [Part 1]   Fri Mar 23, 2012 3:02 pm



Chapterlesson
First Steps in Cleo scripting
with Sannybuilder
- Start for newbies
The Editor- The main functions
- Option: different view of the decompiled code
- Classes and Keywords
Data types- locals @, globals $, "strings '
and hash # to enter modelname
Scripting/Writing a Thread

coding in praxis,
a must-read for newbies
- Using conditional checks
- The IF - Variation
- Script structure simple
- Script structure extended
- Script exemble: Slowmotion
- Spawn a 3D model
- Placing cars by using parked_car_generator
Special Particularities in Cleo- enable_thread_saving
- special cleo global var
- Script Exemble by using Special Global Cleo Variable/ Store a car at any place
- Template for Cleo Mission Script
gosub ... to read a subscript- basic knowledge to understand mission scripts



Chapterlesson
Additional Themes

the lessons are in one post
- Create a FXT file
- Load a special actor
- Tuning parts
- Animations
- sounds of Audio folder
Math coding

the lessons are in one post
- give access with math coding
- Access check with local variables
- Declare or not declare (first reason)
- Time check for milliseconds in real time
- Time check for game hours
- Integer values and floating points
- Declare or not declare (second reason)
- Integer to float and reversed
- Show the calculated values with text_draw opcode
- Math calculations
Save script- simple save script example
Memory Coding

the lessons are in one post
-cheat codes
- Gravity
- ASCII Table
- related links to car struct, actor struct, object struct
Advanced Memory Access to learn the basics
Changing Car Handling
call_scm_function- for advanced
Catch random actor- get_actor_in_sphere
- RandomActor_for_to_step_method
Car Drive Tutorial

the lessons are in one post
- car drive_to
- drive-to commands
- Let the driver do corrections
- Let the driver drive
- Define a scmpath for the driver
- Car drive scripts in praxis
Carrec Paths- Record a path with Seemanns carrec.cs
- assign_car to_path
Particle Effects- show particle effects of effects.fxp
Special opcodes to show particles- sparks, gunflash, blood, corona, shadow, smoke
LIGHT and shadow- the light in gta
- Flash_Light_Illumination
- create_searchlight
- shadow
Object - COLLISION - check

the lessons are in one post
- object.dat definitions
- beachball and bball_col
- throw object
- Missilescript
JumpTable- 0871: init_jump_table
Teleport- Sphere (red marker)
- Location Check
Teleport into interior- Interior Entrance
All links redirect toGTAForums.com


related links
gtamodding.com: List_of_opcodes
GTA:SA Opcodes, Discussion thread
PLPyntons_UnifiedOpcodes
opcode descriptions by PLPynton in sascm.ini format
(be careful, some opcodes are nevermore compatible
because of changed parameter order)
my opcodes.txt
Dejis Opcode Database


CLEO Script Tutorial

english language

CLEO Script Tutorial deutschsprachig





INDEX


The first 6 chapters are written in this first post, below of the index




______________________________________________________________________________________
______________________________________________________________________________________



First Steps in Cleo scripting with Sannybuilder

Download newest version of Sannybuilder from Seeman at http://sannybuilder.com/


Install Sannybuilder and create a folder for your scripts
Therefor youre promt to indicate your GTASA-Install dir.

Then start Sannybuilder,
Open a new blank page, copy the script below and insert it into the new page.



CODE
{$CLEO .cs}
:DEMOTEXT
03A4: name_thread "DEMO"
wait 1000

:DEMOTEXT_1
wait 0
if
0256: player $PLAYER_CHAR defined
004D: jump_if_false @DEMOTEXT_1
if
00E1: key_pressed 0 17
004D: jump_if_false @DEMOTEXT_1
00BA: text_styled 'FEM_OK' 1000 ms 1
0A93: end_custom_thread

Save it in your Sannyscript folder and give it a name.


Compile the script. Click on menue icon with "running man" to choose compile + copy
If the CLEO - Library is installed, the script will be compiled and copied in to GTASA\CLEO - folder

The Cleo script file get then the file extension, which is written in the Cleo Script directive at the beginning of the script

{$CLEO .cs} = Cleo directive will be compiled to *.cs
As DEMOTEXT.txt saved and compiled as DEMOTEXT.cs

______________________________________________________________________________________

If CLEO is not installed, then sannybuilder will prompt you to do it and at the lower right corner of the editor
appears the CLEO - box with a red border. Click on it and Sannybuilder installs Cleo immediately.
Or download the cleo auto install exe at http://cleo.sannybuilder.com
______________________________________________________________________________________

If the compiling process was successful you get then a report message

click on OK to confirm
the lower value "Largest Script" shows the script file size
the other values belongs to a compiling process of a main.scm

Test then the script ingame, press fire button to display the text message "OK"
The script ends then, will be deactivated because it ends with opcode 0A93: end_custom_thread

______________________________________________________________________________________
______________________________________________________________________________________



The Editor

The main functions can be found as icon button in the menue bar

1. Decompile: sanny opens script files with extensions .CS, .CM or .SCM

2. Compile: sanny compiles by default to a [Name]main.SCM

Sanny compiles automaticly to Cleoscript files, if the script have a Cleo-Direktive as entry

{$CLEO .cs} = Cleo-Direktive, will be compiled to Name.CS
{$CLEO .cm} = Cleo-Direktive, will be compiled to Name.CM





Useful tools

Choose TOOLS on menue, then IDE Tools >> Coords Manager
to read the x,y,z coordinate and the z-angle of the current player position if the game is running

Choose TOOLS on menue, then IDE Tools >> Opcode Search
to search for opcodes
type any keyword to find a codeline which include this word
or type an opcode to find the description
the foundings are allways existing lines of original main.scm
The opcode search tool requires to create the opcode.txt in Sanny Builder 3\data\sa folder
Load the decompiled original main into sannybuilder then choose TOOLS on sanny menue, then: make opcodes.txt




Line numbers
Choose TOOLS, then options
in option menu EDITOR you can find the feature to switch Line numbers off/on
The line number is part of the editor, not of the script


The Sannybuilder HELP

Choose HELP on menue, then Content to find informations,
such like key_press numbers, weapon numbers, bodyparts etc..



______________________________________________________________________________________
______________________________________________________________________________________



Option: different view of the decompiled code

Choose TOOLS, then options
in option menu GENERAL you can find the feature to switch between 2 ways for decompiling

either decompile by writing opcodes
or decompiling without opcodes




1. Writing Opcodes
All entries are shown with their opcodes
The opcodes are the real programm codes of the script functions
and by showing them is like to see the name of the command
Script with opcodes:

CODE
:CARSL_6439
00D6: if
00E1: player 0 pressed_key 16
004D: jump_if_false @CARSL_6535
010B: 5@ = player $PLAYER_CHAR money
00D6: if
002D: 5@ >= 14@ // (int)
004D: jump_if_false @CARSL_6512
0012: 14@ *= -1
0109: player $PLAYER_CHAR money += 14@
0002: jump @CARSL_6700

2. Without Opcodes
The script is more slim, maybe more clear (but not for me)
especially 004D: jump_if_false will be now jf
But not all opcodes are disappeared. Many codes must be used furthermore by applying their opcodes.
Script without opcodes:

CODE
:CARSL_6439
if
00E1: player 0 pressed_key 16
jf @CARSL_6535
5@ = Player.Money($PLAYER_CHAR)
if
002D: 5@ >= 14@ // (int)
jf @CARSL_6512
14@ *= -1
Player.Money($PLAYER_CHAR) += 14@
jump @CARSL_6700

By compiling it doesnt matter if you use codes with opcodes or without opcodes
You can merge everything and sanny compile it as well,
provided that the code is correct and codelines which includes opcodes by decompiling without opcodes
must be used furthermore by using opcodes


A special feature by decompiling without opcodes is to translate opcode based commands into
Classes and Keywords

For a couple of codes can be used CLASSES
Read more about classes in Sannybuilder-HELP theme: Coding >> Classes

This code by decompiling with writing opcodes
00AB: put_car 22@ at -1577.942 52.6333 40.0

will by shown by decompiling with without opcodes in this kind:

Car.PutAt(22@, -1577.942, 52.6333, 40.0)

the meaning of the code is defined by the class entries

Car= class-name
PutAt= class-member
name and member are combined with a dot in the middle
22@ = class-owner
class-owner and parameters are placed in brackets and separated with comma
(parameter = needed information for the command)



Sanny allows to use some KEYWORDS instead using opcodes

Opcode = Keyword
_____________
0001: = wait
00d6: = if
004d: = else_jump
004d: = jf
0002: = jump
0051: = return
0050: = gosub
016a: = fade
01B6: = set_weather
03a4: = thread
04BB: = select_interior
0417: = start_mission
00d8: = mission_cleanup
0317: = increment_mission_attempts


Instead writing
004D: jump_if_false @MAIN_6
can be written
jf @MAIN_6
or
else_jump @MAIN_6
you also can merge it
004D: jf @MAIN_6


______________________________________________________________________________________
______________________________________________________________________________________


Data types


: (doublepoint) marks a Label (adress)

CODE
:MAIN_1

@ is used for 2 different functions

1. in jump instruction to mark the label which should be reached

CODE
004D: jump_if_false @SAVE_5
0050: gosub @SAVE_14
0002: jump @SAVE_1

2. to mark LOCAL VARIABLES

The stuff in the game needs a identity for registration to can handle with it
The identities can be variable, for exemble by calculating something

The local variable is builded with the @ sign and a number
0@, 1@, ... 30@ from 0@ up to 31@ is possible, 32@ and 33@ are for timers, thats maximum in an .cs file

1@ defines a parked_car generator

CODE
014B: 1@ = init_parked_car_generator #PCJ600 0 17 1 alarm 0 door_lock 0 0 10000 at 2490.0 -1682.0 13.5 angle 90.0
1@ can then be used furthermore as variable name of the parked_car generator

CODE
014C: set_parked_car_generator 1@ cars_to_generate_to 101


$ is used to mark a GLOBAL VARIABLE

The stuff in the game needs a identity for registration to can handle with it
The identities can be variable, for exemble by calculating something

The global variable is builded with the $ sign and a a letter or a word or a number or both
But using global variables in Cleo scripts can cause heavy bugs or crashs
only $PLAYER_CHAR, $PLAYER_ACTOR, $ONMISSION are valid



global, local, whats that ?
Global variables are used in the main.scm to communicate between different threads
Local variables are also used in the main.scm but they can not communicate between different threads
You can create a car with a LOCAL variable in a thread as 1@ and also with 1@ in an other thread of main.scm
1@ = create_car
You have then 2 different cars, commanded from 2 different threads

You can create a car with GLOBAL variable in a thread but dont use again the same global to create it again in an other thread.
$mycar5 = create_car
But you can command the car from an other thread of the main.scm by using a GLOBAL variable
At least:
The GLOBAL variables are storable, the LOCAL variables not

But dont using global variables in Cleo scripts because they can cause heavy bugs or crashs
only $PLAYER_CHAR, $PLAYER_ACTOR, $ONMISSION are valid


# marks the connected entry as filename of a loadable model

CODE
0247: load_model #BMYCG
0247: load_model #HMYCM
0247: load_model #SWATVAN
0247: load_model #M4
0247: load_model #COLT45
For Cleo can only be used models which are defined in vehicles.ide, peds.ide or default.ide
Other models needs to use their ID number


'...' short string to insert letters or numbers like GXT entrynames or names of special IPL entries

CODE
03A4: name_thread 'MAIN'
0917: audio_zone 'BEACH' enable_sound 0
00BA: show_text_styled GXT 'INTRO_1' time 1000 style 2
0299: activate_garage 'MODLAST'
07FB: set_interior 'GYM1' access 1 // Ganton Gym
0390: load_txd_dictionary 'LD_BEAT'
076C: set_zone 'GAN1' gang 1 density_to 25

"..." long string to insert letters or numbers like animation- and IFP file names, bodypart names, particel names, etc...

CODE
087B: set_player $PLAYER_CHAR clothes_texture "PLAYER_FACE" model "HEAD" body_part 1
038F: load_texture "DOWN" as 1 // Load dictionary with 0390 first
0605: actor -1 perform_animation_sequence "DAN_LOOP_A" IFP_file "DANCING" 4.0 loop 1 0 0 0 time -1 // versionA
0674: set_car_model #GREENWOO numberplate "GROVE4L_"
0245: set_actor 5@ walk_style_to "GANG2"
064B: 25@ = create_particle "EXPLOSION_MOLOTOV" at 2010.0 -1610.0 16.5 type 1

To set entries of strings equal to variable names must be used special opcodes and extended variable signs
05AA:
05A9:
06D2:
06D1:
furthermore can strings also replaced with variables by using extended variable signs

@s - local-string-variable

CODE
05AA: 5@s = 'FEM_OK'
00BC: show_text_highpriority GXT 5@s time 10000 flag 1

s$ - global-string-variable
Attension by using Global vars in cleo scripts, it can cause bugs or crashes!

CODE
05A9: s$Actor_Speech_GXT_Reference = 'CATX_UA' // ~z~Carl, you are a f*cking idiota!
00BC: show_text_highpriority GXT s$Actor_Speech_GXT_Reference time 10000 flag 1
05AA: 5@s = s$Actor_Speech_GXT_Reference
00BC: show_text_highpriority GXT 5@s time 10000 flag 1

@v - local-long-string-variable

CODE
06D2: 28@v = "LAPDAN1" // @v = string
0812: AS_actor $PLAYER_ACTOR perform_animation "LAPDAN_P" IFP_file 28@v 1000.0 loopA 0 lockX 0 lockY 0 lockF 1 time -1

v$ - global-long string-variable
Attension by using Global vars in cleo scripts, it can cause bugs or crashes!

CODE
06D1: v$1225 = "Bat_block"// 16-byte strings
0605: actor $PLAYER_ACTOR perform_animation_sequence v$1225 from_file "BASEBALL" 4.0 1 0 0 0 -1 ms


______________________________________________________________________________________
______________________________________________________________________________________


Scripting/Writing a Thread

The scripts which are running in GTA are called THREAD
They are defined in the main.scm as thread with the create_thread command or a mission script as mission
As well the Extern scripts of script.img are also threads.

The cleo programm checks if there is .cs file in the Cleo folder
and if yes, it start this script as thread

Script structur / short version:

At first, the head, it beginns with the Cleo directive

CODE
{$CLEO .cs}
First Label (adress)

CODE
:Akt
Then give the thread a name

CODE
03A4: name_thread 'AKT'
now put a code inthere which will doing something and then end_custom_thread as last code
its ready then to test it ingame


CODE
{$CLEO .cs}
:Akt
03A4: name_thread 'AKT'
08B2: toggle_thermal_vision 1
0A93: end_custom_thread
Script above activates the Infrarot view unless in cutscenes
The script ends then, will be deactivated because it ends with opcode 0A93: end_custom_thread
The script will be started by each loading of savegame or by start new game

______________________________________________________________________________________



Next step / using conditional checks

A conditional check requires minimum 3 opcodes

1. the IF-variation
2. the real question
3. the jump instruction by negation




1. if

2. 0AB0: key_pressed 8

3. 004D: jump_if_false @akt_01



We use the previous script again but now we wonna be able to switch into normal view
Therefore we use a conditional check and build a "LOOP"

Loop means that a jump instruction can send the reading process to a previous adress
I call such an adress "Loop-adress"
Important:
The first opcode after such a Loop-adress must be the wait opcode
mostly wait 0 millisecond

the jump instruction can be a jump instruction by negation
or also a normal jump instruction


CODE
004D: jump_if_false @akt_01
or

CODE
0002: jump @akt_01


The conditional check of a key press in the script below should be passed by pressing BACKSPACE


CODE
{$CLEO .cs}
:Akt
03A4: name_thread 'AKT'
08B2: toggle_thermal_vision 1

:Akt_01//----------------------------Loop adresse
0001: wait 0 ms
if
0AB0: key_pressed 8
004D: jump_if_false @Akt_01//--------jump instruction by negation
08B2: toggle_thermal_vision 0
0A93: end_custom_thread
Script above activates the Infrarot view and toggle back to normal view by key_press
The reading process is looping as long as BACKSPACE is not pressed
the jump instruction by negation sends the reading process allways to the label :Akt_01
1000 times per second

_________________


Strobe Modding Owner/Founder Arrow Forum Head Administrator
Click the spoiler for an insta-boner. (56k ALERT!!)
Spoiler:
 

Back to top Go down
http://strobemodding.nstars.org
 
[TUT] Cleo Scripting Tutorial [Part 1]
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» Great Tank and Weathering tutorial
» Power Sword Tutorial (with more to follow)
» charlie the unicorn PART 4
» Nimmy Part 1: The first sort of date? Not really? [p r i v a t e--To Roxanne]
» Instant Mold Tutorial

Permissions in this forum:You cannot reply to topics in this forum
Strobe Modding :: GTA SA Modding :: GTA SA Tool Box-
Jump to: