GTA: Modification Area
Would you like to react to this message? Create an account in a few clicks or log in to continue.
GTA: Modification Area

A website for the GTA modding scene

Search
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
» Big-game starts raising Schneider's profile
James227uk's Coding Tutorial EmptySun Mar 04, 2012 2:28 am by lavivi

» [Help] cleo created lighting
James227uk's Coding Tutorial EmptyThu Oct 14, 2010 1:03 am by findmy012

» Mission Question
James227uk's Coding Tutorial EmptyThu Oct 14, 2010 1:02 am by findmy012

» [IV] Spoiler Script
James227uk's Coding Tutorial EmptyThu Oct 14, 2010 1:02 am by findmy012

» Mission mod [help]
James227uk's Coding Tutorial EmptySat Sep 18, 2010 5:50 pm by jayd00

» Bc7 Mod Help
James227uk's Coding Tutorial EmptyFri Aug 20, 2010 11:19 am by pengpeng

» Found a bug
James227uk's Coding Tutorial EmptyFri Dec 18, 2009 4:22 am by _CJ360_

» [IV] Novitec Rosso 599 GTB
James227uk's Coding Tutorial EmptyTue Nov 17, 2009 4:22 pm by Kotton

» Hello/Guidance Request
James227uk's Coding Tutorial EmptyMon Oct 12, 2009 6:45 am by Adler

Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search
Affiliates
image

Image

Image

Image

Image

Image

Image

Image

Image

Image

image

Image

steve-m.com

Image


----- Русский -----

Если ваш сайт содержит большую коллекцию SCM/CLEO-скриптов (больше 16), напишите на мой e-mail, и я добавлю его в список. Приветствуются скрипты, которые не встречаются на других сайтах ... Спасибо. ))))


----- English -----

If your website has a big enough collection of SCM/CLEO scripts (more than 16) notify me by e-mail
, and I will add it to the list. The unique scripts are preferable ... Thank you. ))))
Log in

I forgot my password



March 2024
MonTueWedThuFriSatSun
    123
45678910
11121314151617
18192021222324
25262728293031

Calendar Calendar


You are not connected. Please login or register

James227uk's Coding Tutorial

2 posters

Go down  Message [Page 1 of 1]

1James227uk's Coding Tutorial Empty James227uk's Coding Tutorial Sat Apr 18, 2009 7:59 pm

james227uk

james227uk
Admin

CLEO3 Script Tutorial

Contents

1. Introduction
2. CLEO3 and Sanny Builder
3. Things you should know/Glossary
4. Spawn a car
5. Spawning pickups
6. Spawn an actor (Ped)
7. Making a cheat
8. High level constructions
9. Keywords
10. Opcode search
11. End
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
1. INTRODUCTION

Coding is fun and easy when you get the hang of it. An experienced coder can basically make the
game "His" by changing an important file: The main.scm . I, James227uk, thought I would write
this tutorial because it would help people.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
2. CLEO3 AND SANNY BUILDER

Sanny Builder (We'll call it SB from now XD)is the tool you code in. Not to mention, SB is the
only tool that can open and save .cs and .cm files. CLEO3 is an extensive project to extend the
coding possibilities in the game. With lots of extra opcodes it certainly achieves it's goal.
More to the point, CLEO scripts do not require you to start a new game. This means you can just
add and remove mods all you like without starting from the beginning. Cool huh? Yep, it is.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
3. THINGS YOU SHOULD KNOW/GLOSSARY

In coding you store data to things called variables. Something like $EXAMPLE or 1@. When
making CLEO scripts, it's advisable to use Local Variables (1@, 2@, 3@ etc) to avoid conflicts
with the main.scm file. The limit for locals in a single script is form 0@ to 30@, although to
33@ if you count 32@ and 33@, which are local timers and not normal use locals.
A global variable is like $CUSTOM. The only time you really need to use them is when you need
a variable in more than one thread. Although, there will be times when you will HAVE TO USE THEM!

- THREAD

A thread is basically your mod. It organises it. It's composed of labels

- LABEL

A label is a section of your script. You typically start a new label when using a loop

- MAIN.SCM

The main.scm is the main script file for the game. It contains the missions and the CODE for
external scripts

- EXTERNAL SCRIPT

Examples of external scripts are the Parachute and the video games. The CODE is stored in the
SCM, though the actual thing is in the script.img

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
4. SPAWN A CAR

Something most people want to do. There are two ways of achieving this. Either a Car Generator
or a Keypress Spawn. A Car generator typically spawns a car like the Greenwood in Grove St.
Here is the opcode you need:


Code:

014B: $PARKED_RHINO = init_parked_car_generator #RHINO color -1 -1 1 alarm 0 door_lock 0 0 10000
at 2435.302 -1671.848 12.8007 angle 90.0


Lets go through the values.

$PARKED_RHINO - is the name of this car generator. We will need it later.
#RHINO - is the vehicle's model. A full list appears when you type a #
-1 -1 - These values are the cars colours. -1 -1 means the primary and secondary colour of the
car will be a random colour. A full list of colours can be found on this chart:

James227uk's Coding Tutorial Image:Carcolors

alarm 0 - 0 for alarm off 1 for on. If it's on, when the player or a ped trys to enter the
vehicle it's alarm will sound.

door_lock 0 - 0 for doors unlocked, 50 for a 50 percent chance doors will be locked and 100
for always locked


2435.302 -1671.848 12.8007 - The position the car will spawn at. These are called coordinates.
Move to a place in the game where you want your car, ALT+TAB to
SB and right click. Hover over
insert and click Player Coords.

angle 90.0 - The way the car will face. Face the way you want it to face in game, ALT+TAB to SB,
right click, hover over insert and click Player Angle


So now we have discussed the values (Correctly called Parameters). Here is a script you can
change:

Code:

{$CLEO .cs}

014B: 1@ = init_parked_car_generator #INFERNUS color -1 -1 1 alarm 0 door_lock 0 0 10000
at 2435.302 -1671.848 12.8007 angle 90.0
014C: set_parked_car_generator 1@ cars_to_generate_to 101
0A95: enable_thread_saving
0A93: end_custom_thread

This simply creates an Infernus under the bridge in Grove St. It's never locked and never
alarmed. Now look at opcode 014C. 0 means it will never spawn, and 101 means it will spawn unlimited times. (where as 99 would make it spawn 99 times, and etc, read more about how that works in the topic "Car generator(rules)".
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
5. SPAWN A PICKUP

There are namy types of pickups. We're talking Money, Asset, Property and the most common of all
, Weapons. In this section I will explain how to create a Weapon pickup. Here is the opcode:

Code:

032B: $811 = create_weapon_pickup #M4 group 15 ammo 60 at 2021.879 1001.467 10.3203


There are also another opcodes for pickups:

Code:

0213: $PICKUP_INFO_HOSPITAL = create_pickup #INFO type 3 at 2027.77 -1420.52 16.49
0213: $PICKUP_INFO_HOSPITAL = create_pickup #INFO type 3 at 2027.77 -1420.52 16.49
0518: $BUY_ASSET_PICKUPS[0] = create_available_asset_pickup 'PROP_3' at $X_PROPERTY_TO_BUY[0] $Y_PROPERTY_TO_BUY[0] $Z_PROPERTY_TO_BUY[0] price $1653  // Press ~k~~PED_ANSWER_PHONE~ to buy this property.


There are many more in the opcode search. But we will focus on 032B. Lets look at the params:

$811 - The variable identifier
#M4 - The weapon
15 - Type of pickup. The main ones are 1, which is disabled and 15 which reappears after
sometime
60 - How much ammo which will be in this pickup. A melee weapon should only have 1 ammo.
2021.879 1001.467 10.3203 - The coords. Use the right click trick from the car section to get
these

Heres a script you can change:

Code:

{$CLEO}

thread 'WEAPONSS'

032B: 2@ = create_weapon_pickup #AK47 group 15 ammo 100000 at 2021.879 1001.467 10.3203


This spawns an Ak47 at the desired coords with infinite ammo.
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-



Last edited by james227uk on Sat Apr 18, 2009 8:04 pm; edited 1 time in total

http://james227ukmods.synthasite.com

2James227uk's Coding Tutorial Empty Re: James227uk's Coding Tutorial Sat Apr 18, 2009 8:01 pm

james227uk

james227uk
Admin

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
6. SPAWN AN ACTOR (PED)

This may be a challenge for you. Eventually you will get the hang of it. In this section we will
create a ped that will stand in front of the player when we press a key. When you do that, read
on and we will make a ped in our gang, and make it attack the player. This section also
introduces loading, checking availability and releasing models.

So lets spawn the ped. Here's the code:

Code:

{$CLEO}

thread 'THEACTA'

:START
wait 0
if
  Player.Defined($PLAYER_CHAR)
jf @START
if
    0AB0: key_pressed 49 // Press 1
jf @START
#BMYPIMP.Load()
04C4: store_coords_to 5@ 6@ 7@ from_actor $PLAYER_ACTOR with_offset 0.0 5.0 0.0

:SECOND
wait 0
if
    #BMYPIMP.Available()
jf @SECOND
Actor.Create(8@, 23, #BMYPIMP, 5@, 6@, 7@)
Actor.RemoveReferences(8@)
#BMYPIMP.Destroy()
wait 1000
jump @START


Overview:

Player.Defined - This should be in almost all scripts that use labels
0AB0: key_pressed - Checks if the player presses a certain key. Find a list of 0AB0 keys in
SB help>F12>CLEO 3 code library>Virtual key Codes
#BMYPIMP.Load - Loads the model BMYPIMP
04C4: store_coords - Store coords from an actor with a given offset
#BMYPIMP.Available - Checks if model BMYPIMP is loaded and ready to use
Actor.Create - Creates the ped
Actor.RemoveReferences - Turns the ped into a random ped like on the streets. Once this is used,
any special options like in gang, attack actor will stop working for
this actor
#BMYPIMP.Destroy() - Regardless of the word destroy, it releases the BMYPIMP model
wait 1000 - Tells the game engine to wait a second. 1000/1000 ms = 1 Second. Meaning 5000 is 5
seconds
jump @START - Tells the engine to jump to a different label, in this case the start of the
script

Here's some more advanced scripts:

Code:

{$CLEO}

thread 'THEACTA'

:START
wait 0
if
  Player.Defined($PLAYER_CHAR)
jf @START
if
    0AB0: key_pressed 49 // Press 1
jf @START
#BMYPIMP.Load()
04C4: store_coords_to 5@ 6@ 7@ from_actor $PLAYER_ACTOR with_offset 0.0 5.0 0.0
07AF: $PLAYER_GROUP = player $PLAYER_CHAR group

:SECOND
wait 0
if
    #BMYPIMP.Available()
jf @SECOND
Actor.Create(8@, 23, #BMYPIMP, 5@, 6@, 7@)
0631: put_actor 8@ in_group $PLAYER_GROUP
wait 60000
Actor.RemoveReferences(8@)
#BMYPIMP.Destroy()
wait 1000
jump @START


This code adds the actor to the players gang for 1 minute then turns him into a random ped. So
what about guns? Well here:

Code:

{$CLEO}

thread 'THEACTA'

:START
wait 0
if
  Player.Defined($PLAYER_CHAR)
jf @START
if
    0AB0: key_pressed 49 // Press 1
jf @START
#BMYPIMP.Load()
#M4.Load()
04C4: store_coords_to 5@ 6@ 7@ from_actor $PLAYER_ACTOR with_offset 0.0 5.0 0.0

:SECOND
wait 0
if
    #BMYPIMP.Available()
    #M4.Available()
jf @SECOND
Actor.Create(8@, 23, #BMYPIMP, 5@, 6@, 7@)
01B2: give_actor 8@ weapon 31 ammo 100000 // Load the weapon model before using this
wait 60000
Actor.RemoveReferences(8@)
#BMYPIMP.Destroy()
wait 1000
jump @START


For a list of weapon numbers and models, they're here:

F12>SCM Documentation>GTA SA>Weapon Numbers
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
7. MAKING A CHEAT

Most of the info in this section is by my friend, gtasbigfoot. This script will spawn an
andromada when you type ANDR

Code:

{$CLEO .cs}
:androm
03A4: name_thread 'androm'

:start
0001: wait 0 ms
0A8D: 0@ = read_memory 0x00969110 size 4 virtual_protect 0 
00D6: if 1                 
04A4:  0@ == 0x414E4452 //=andr 
004D: jump_if_false @start


:start_0
0247:  request_model #ANDROM
038B: load_requested_models

:check
0001: wait 0 ms
00D6: if
0248:  model #ANDROM available
004D: jump_if_false @check

03E5: text_box 'CHEAT1'  // Cheat aktiviert
04C4: store_coords_to 3@ 4@ 5@ from_actor $PLAYER_ACTOR with_offset 0.0 12.8 0.0
00A5: 6@ = create_car #ANDROM at 3@ 4@ 5@
0224: set_car 6@ health_to 4000
08A4: set_car 6@ extra_parts_angle_to 1.0

0249: release_model #ANDROM

0A8C: write_memory 0x00969110 size 4 value 0 virtual_protect 0
0002: jump @start


This is the line you will be intrested in for the cheat:

Code:

04A4:  0@ == 0x414E4452 //=andr


And in particular, this part:

Code:

0x414E4452


41 = A
4E = N
44 = D
52 = R

Here is a full list:

[quote=LIST!]
40 = @
41 = A
42 = B
43 = C
44 = D
45 = E
46 = F
47 = G
48 = H
49 = I
4A = J
4B = K
4C = L
4D = M
4E = N
4F = O
50 = P
51 = Q
52 = R
53 = S
54 = T
55 = U
56 = V
57 = W
58 = X
59 = Y
5A = Z
[/quote]

So CARS would be:

C = 43
A = 41
R = 52
S = 53

String them together and you have 43415253. To put into the opcode would be: 0x43415253
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
8. HIGH LEVEL CONSTRUCTIONS

This is where the coding gets real; and I'm not joking. High level constructions make code work
easier and make your script look pro. Lets take the spawn an actor code from earlier.

Code:

{$CLEO}

thread 'THEACTA'

:START
wait 0
if
  Player.Defined($PLAYER_CHAR)
jf @START
if
    0AB0: key_pressed 49 // Press 1
jf @START
#BMYPIMP.Load()
04C4: store_coords_to 5@ 6@ 7@ from_actor $PLAYER_ACTOR with_offset 0.0 5.0 0.0

:SECOND
wait 0
if
    #BMYPIMP.Available()
jf @SECOND
Actor.Create(8@, 23, #BMYPIMP, 5@, 6@, 7@)
Actor.RemoveReferences(8@)
#BMYPIMP.Destroy()
wait 1000
jump @START


Now let's put some high level constructions in it.

Code:

{$CLEO}

thread 'THEACTA'

:START
wait 0
if and
  Player.Defined($PLAYER_CHAR)
    0AB0: key_pressed 49 // Press 1
then
    #BMYPIMP.Load()
    04C4: store_coords_to 5@ 6@ 7@ from_actor $PLAYER_ACTOR with_offset 0.0 5.0 0.0
else
    jump @START
end

:SECOND
wait 0
if
    #BMYPIMP.Available()
then
Actor.Create(8@, 23, #BMYPIMP, 5@, 6@, 7@)
Actor.RemoveReferences(8@)
#BMYPIMP.Destroy()
wait 1000
jump @START
else
    jump @SECOND
end


So for the first one, If the player is defined and the key is pressed, it will load the model
and store coords, else, if they not, it will jump at the starting label, START.

A full list:

- Break
- Continue
- Repeat
- While
- Then
- Else
- Break
- Until
- While
- End

When you write a high level construction, you need to put End at the end of your high level
statement. Look at the code above for an example, and here's another one:

Code:

if
    #AK47.Available()
then
    jump @SECOND
else
    jump @START
end


Think of it as:

Code:

start>---------------->\/
if                    |
    #AK47.Available()  |
then                  |
    jump @SECOND        |
else                  |
    jump @START        \/
end <------------------<


Except the start is invisible
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
9. KEYWORDS

I think this will be helpful so some people -

KEYWORD - OPCODE - COMMENT

- create_thread 004F Creates a thread
- create_thread_wb 00D7 Basically useless
- else_jump 004D Jump_If_False
- end_thread 004E Ends the current thread
- end_thread_named 0459 Ends a different thread
- fade 016A Makes the screen fade
- fading 016B Checks if the screen is fading???
- gosub 0050 Go to another section of the script. Needs a return
- goto 0002 Make it go to another part of the script???
- if 00D6 Standard check
- increment_mission_attempts 0317 Adds one to total mission attempts???
- jf 004D Jump_If_False
- jump 0002 Jumps to another section of the script
- mission_cleanup 00D8 Use after a mission
- return 0051 Returns to the line after a gosub. Matches gosub.
- select_interior 04BB Selects an interior for use???
- set_wb_check_to 0111 Basically useless
- set_weather 01B6 Sets the current weather
- shake_camera 0003 Shakes the camera for a set amount of time
- start_mission 0417 Starts a mission by name or ID number
- thread 03A4 Creates a thread
- wait 0001 Wait some time
- wasted_or_busted 0112 Checks if wasted or busted
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
10. Opcode Search

Throughout this whole tutorial I have been mentioning the opcode search. This tool built into SB
allows you to search for the opcode you desire. Searching jump into it will show all the opcodes
containing jump in them. Opcode search can be accessed by pressing CTRL+ALT+2
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
11. End

Well that concludes my tutorial. I hope you have learnt something.

Tutorial written by James227uk in 2009. Copyright 2009.




You MAY NOT rip parts of this tutorial. You MAY NOT put this tutorial in your name. If this
tutorial is on any website other than james227ukmods.synthasite.com or waterviper.forumtwilight.com you MUST
mention me as the author otherwise I will flame your website under a proxy server. Thank you.

http://james227ukmods.synthasite.com

3James227uk's Coding Tutorial Empty Re: James227uk's Coding Tutorial Fri Apr 24, 2009 11:29 am

gtasbigfoot

gtasbigfoot
Admin

Well, good work, James Grin Smile. If you wanna expand your tutorial, I have also did a "Getting started in scripting" tutorial; also may I suggest one thing?

Explaining about the main.scm start? Using arrays to write/read any value to the games memory, as this is very useful, and specially if you have not CLEO installed, to use the opcodes 0a8c/0a8d.


Code:

0@ = 0xB7CE50
gosub @MemoryRead32
054C: use_GXT_table 'POOL'
01E3: text_1number_styled 'NUM' 1@ 5000 ms 1 // ~1~
//...
// end_thread

:MemoryRead32
  0@ -= 0xA49960
  0@ /= 4
  008B: 1@ = &0(0@,1i)
return


As an example above reads the players money which is located at 0xB7CE50, it then gosubs to the sub-script, and reads the memory, then returns, and shows the players total cash(bux).


Code:

:MemoryRead32
  0@ -= 0xA49960
  0@ /= 4
  008B: 1@ = &0(0@,1i)
return


0xA49960 needs to be replaced with 0xA4BFE0 if your using the game version v1.


Code:

:MemoryRead32
  0@ -= 0xA4BFE0
  0@ /= 4
  008B: 1@ = &0(0@,1i)
return



Original script:


Code:

// 0@ -address
// 2@ -new value
// 3@ -length (in bytes)
//--write specified number of bytes into memory
:MemoryWrite
0085: 5@ = 0@
0@ /= 4
0@ *= 4          // memory address
0062: 5@ -= 0@    // offset (0, 1, 2, 3)
:_GetInitValue      // if you specify mem offset in 5@, you're able to gosub here
gosub @MemoryRead // get initial value
3@ *= 8 // bytes -> bits
5@ *= 8
dec(3@)
for 6@ = 0 to 3@               
  if
    08B6: test 2@ bit 6@
  then
    08BF: set 1@ bit 5@    // 1
  else
    08C5: clear 1@ bit 5@  // 0
  end
  inc(5@) // next memory bit
end
008A: &0(0@,1i) = 1@  // write new value
return

//--write 32-bit value into memory-----------

:MemoryWrite32bit
0@ -= 0xA49960
0@ /= 4
008A: &0(0@,1i) = 1@
return

//--read 32-bit value from memory-----------

:MemoryRead
0@ -= 0xA49960
0@ /= 4
008B: 1@ = &0(0@,1i)
return


An example, add 10 million dollars to the player:


Code:

0@ = 0xB7CE50 // 0@ -address
2@ = 10000000 // 2@ -new value
3@ = 1        // 3@ -length (in bytes)
gosub @MemoryWrite
end_thread



More info on this and more in the SA Memory Example Topic.

BTW, I corrected one mistake you made in the first post, I can not notice anything else, which is so bothersome.

Bye, Дуэйн.

http://gtamodding.com

Sponsored content



Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum