Quantcast

Jump to content

» «
Photo

Coding bible part I

31 replies to this topic
tomworld10
  • tomworld10

    Mark Chump

  • Members
  • Joined: 29 Jun 2005

#1

Posted 14 November 2006 - 09:31 PM Edited by tomworld10, 31 May 2008 - 04:36 PM.

Grand Theft Auto

San Andreas




Mission Coding with Sanny Builder Tutorial
Part I
Getting started








Introduction :

Hi, since a long time I wanted to make a tutorial for newbies, it won't tell you what to do, it will helps you doing what you want to do. It can also be a good tutorial for Sanny builder. I tried to make a tutorial for anyone even if you don't know anything about programming. You might want jump straight to part II, if you think you know enough about coding to get started.

If you need/feel like reading it all, I highly recommend you to print it. It will be much easier to read, to make annotation, you will be able to bring it anywhere you go, and it will be easier to do things in Sanny Builder while reading it. For printting, use the Printable Version of Topic, for this just clic on print this topic link on top right of the first message. But don't forget that there is animated .gif, so you might still want to look at the topic on the computer to get them animated. I also advice you to read it in Sanny Builder's Help Content in Articles chapter, there you have active links to SCM documentation, websites, animation, and always available even offline.


With Mission coding (or Mission scripting) you can make your own missions, your own mods or modificate existing ones (you can find many in this Mission Mods and this Mission Coding (and is where you can ask questions about coding) .


Mission coding is done with the files main.scm and script.img in data\script folder of San Andreas. Main.scm is a compiled file, so it's made in a language that the computer can understand it easily. If you open main.scm with hexadecimal editor it looks like that inside :
CODE
D6 00 04 00 19 01 02 45 0E 4D 00 01 FE 3D 87 02 A6 00 02 45 0E

So you need to uncompile it to have it in a human readable format, then we will be able to program in it. You don't need to do anything on the file script.img, the file is needed, so each main.scm will need his own script.img.

So to decompile main.scm you need Sanny Builder. There is many other decompiler but if you a beginer Sanny will be the best coding solution, because it's continuously update, has proper support, is fast, is colorfull rolleyes.gif !!!!! And the tutorial is made with and for Sanny Builder.
Sanny Builder is close to Barton Waterduck's San Andreas Mission builder but because the syntax is different I highly advise to use Sanny Builder but if you want to disobey, here it is : Barton's Waterduck Mission Builder -Craig's version, thanks to him.


Something very important, to get informations, the Sanny Builder's Help, it' full of very useful information and always available (like offline).


Launch the executable follow usual installation process. Then go first to Tools\options (or press F10). In general tab check Show progress, Show report, Show warning, Quick game loading, Condition check, Ranges check, Writes opcodes, maybe Replace mission numbers, Insert Original mission names, Add extra info to SCM. I will explain later why we need those.

Like this :
user posted image

Close Sanny Builder and reopen it.


There is many other good tutorials that should help you : YeTi's SA Coding Tutorial Part One, YeTi's SA Coding Tutorial Part Two, Y_less quick tuto, those are for San Andreas. Vice City tutorials can help you too : Alex "Y_Less" Cole's n00b guide to coding, littleguna's VC Coding Tutorial, YeTi's VC Coding Tutorial Part One, YeTi's VC Coding Tutorial Part Two. The GTAforums tutorial archive. You can find more in this forum here.
You can visit GTAmodding.com and particulary Mission scripting category.




1. Main.scm architecture :


So now copy original main.scm and script.img to a new coding working folder (or anywhere you want : desktop, My docs, recycle bin, your mum's docs biggrin.gif ....) you've created and open it (make backups !!!!! like doing right away a new folder for original main.scm and script.img) by clicking open and selecting SCM File (*.scm). You can see the progress bar filling up (That's why we've truned on the option "Show progress").


- Define section :

And you will get something like that :
CODE
// This file was decompiled using sascm.ini published by Seemann (http://sannybuilder.com/files/SASCM.rar) on 13.10.2007
DEFINE OBJECTS 389
DEFINE OBJECT SANNY BUILDER 3.03                
DEFINE OBJECT INFO                    // Object number -1
DEFINE OBJECT KEYCARD                 // Object number -2
DEFINE OBJECT AD_FLATDOOR             // Object number -3
DEFINE OBJECT KB_BANDIT_U             // Object number -4
etc...


As you can see it defines the objects that will be used in the main.scm, there is 389 of them like said on top ( DEFINE OBJECTS 389 ). To add an object just go to to last one and add yours.


Further down (much further down) you can find that :
CODE
DEFINE MISSIONS 135
DEFINE MISSION 0 AT @INITIAL
DEFINE MISSION 1 AT @INITIL2
DEFINE MISSION 2 AT @INTRO
DEFINE MISSION 3 AT @NONE
etc...


This defines the missions, there is 135 of them like said on top ( DEFINE MISSIONS 135 ). If you use Xbox or Playstation 2, or jarjar 2-player mod files you can see that there is more mission which are 2 player console mission but that's another story...


CODE
DEFINE EXTERNAL_SCRIPTS 78 // Use -1 in order not to compile AAA script
DEFINE SCRIPT PLAYER_PARACHUTE AT @PLCHUTE // 0
DEFINE SCRIPT PARACHUTE AT @PARACH // 1
DEFINE SCRIPT BCESAR2 AT @BCESAR2 // 2
DEFINE SCRIPT BCESAR3 AT @COKEC // 3
DEFINE SCRIPT SLOT_MACHINE AT @BANDIT // 4
etc...


This defines the external scripts which are scripts (programs) that are triggered when needed, there is 78 of them like said on top. That's what handles the Parachute (player - PLAYER_PARACHUTE - and non-players - PARACHUTE -), Games at the casino ( ROULETTE , VIDPOK -Video Poker-, BLACKJ -Black Jack-, WHEELO -Wheel Of Fortune-, etc...), Shops ( AMMU , TATTOO , BARBER , JUNKFUD , CARMOD ), and many other thing more or less weird ( DEBT , STRIPW , GF_SEX , HOME_BRAINS ...) More about thoses later on.

Then you get to those 2 lines :
CODE
DEFINE UNKNOWN_EMPTY_SEGMENT 0

DEFINE UNKNOWN_THREADS_MEMORY 574
Which are undocumented and useless for me and you.



- Main section :

Now you can see something like this :
CODE
{$VERSION 3.1.0027}

//-------------MAIN---------------
03A4: name_thread 'MAIN'
016A: fade 0 time 0
042C: set_total_missions_to 147
030D: set_max_progress 187
0997: set_total_respect_points_to 1339
01F0: set_max_wanted_level_to 6
0111: set_wasted_busted_check_to 0
00C0: set_current_time_hours_to 8 current_time_minutes_to 0
04E4: unknown_refresh_game_renderer_at 2488.562 -1666.864
03CB: set_rendering_origin_at 2488.562 -1666.864 13.3757
062A: change_stat 165 to 800.0 // floating-point values
062A: change_stat 23 to 50.0 // floating-point values
062A: change_stat 21 to 200.0 // floating-point values
062A: change_stat 160 to 0.0 // floating-point values
0629: change_stat 181 to 4 // integer values
0629: change_stat 68 to 0 // integer values
0053: $PLAYER_CHAR = create_player #NULL at 2488.562 -1666.864 12.8757
etc...



Up to before there (use Sanny search tool and search "mission 0") :
CODE
//-------------Mission 0---------------
// Originally: Initial 1

:INITIAL
03A4: name_thread 'INITIAL'
06C8: enable_riot 0
0004: $1515 = 0
0005: $1500 = 5.0
etc...
It is called the main part or the main section (and sometimes with imprecision named the main thread). In this there is many little bit of scripts that for example create the red circles which start missions, the thing that handles the phone calls ( CELLFON and other things), that handles grilfriends, from where everything is triggered (started), where many many mods are added, and that's where you will start coding. The main section is composed of many little threads, but it starts with the main thread. And the thread is (and is the only one) created by the engine itself, you don't have to use the opcode that create threads 004F ( create_thread ) like everyother ones to ingnite it. Don't worry, a whole part will be dedicated to threads later.

In the main part you can only use locals variables ( 0@ , 1@ , 2@ , etc...) up to 31@ included, 32@ and 33@ are internals local timers (counts the amount of time elapsed, we'll see it later) that you can use too. But any over 33@ will not work in the main part. Sanny won't be happy and will tell you that the local var. is out of range (that's why we've turned "Range check" option on). You can use any globals you want but their number is limited to 16383, it should be far enough.






- Now Mission section :


Then after :
CODE
//-------------Mission 0---------------
// Originally: Initial 1

:INITIAL
03A4: name_thread 'INITIAL'
06C8: enable_riot 0
0004: $1515 = 0
0005: $1500 = 5.0
etc...

It's the first mission (which actually ain't a mission because it's done during the first milliseconds of a new game before the cutscene and doesn't give any mission points). This mission actually create parked cars, some weapons pick up and other thing.




After will get to the mission 1 (search mission 1)
CODE
//-------------Mission 1---------------
// Originally: Initial 2

:INITIL2
03A4: name_thread 'INITIL2'
0004: $3407 = 25
0004: $3408 = 100
0004: $3409 = 250
etc...

Same as mission 0 it's not a mission, it only set some variables equal to number value, parked some cars again, activate some doors and lifts.


Then Mission 2
CODE
//-------------Mission 2---------------
// Originally: Intro

:INTRO
03A4: name_thread 'INTRO'
0050: gosub @INTRO_47
00D6: if
0112:   wasted_or_busted // mission only
004D: jump_if_false @INTRO_38
0050: gosub @INTRO_9715
etc...
This one is part of the intro cutscene and the mission ends when you got to the red circle at CJ's home.

After there is the arcades games ( originally: Video game: They crawled from uranus ; originally: Video game: Duality ; originally: Video game: Go Go Space Monkey ; originally: Video game: Let's get ready to BUMBLE ; originally: Video game: poker ) then other thing like pool ( originally: Pool ), dance ( originally: Lowrider (bet and dance) ) and Zero "hidden/bonus" mission ( originally: Beefy Baron ) and after those the "Big smoke" Mission (mission 11) which is first mission of the game.

And then like that up mission's 134 end.
If you want to add a mission add after that and define it in define mission section. (more later on).






- External script section (last section)


After the last mission you can see all the defined external script starting with the first one PLAYER_PARACHUTE :
CODE
//-------------External script 0 (PLAYER_PARACHUTE)---------------

:PLCHUTE
03A4: name_thread 'PLCHUTE'
0247: request_model #GUN_PARA

:PLCHUTE_16
etc...


and then
CODE
//-------------External script 1 (PARACHUTE)---------------

:PARACH
03A4: name_thread 'PARACH'
0004: $8275 = 0
etc...


and so on till the 77th external scripts. Many things in external scripts, by looking at the name of the external, you can often figure out what it is used for.

What's most important for now is the main part.

But still about main.scm architecture, you need to know that some things are limited in main.scm look, here . As you can see the main size (the lenght of all 'main part' threads) is limited to 200 000 bytes. To know how long the 'main part' is compile and look the report it tells you "MAIN size : XXXXXX b." and then the biggest mission "Largest Mission : XXXX b." and the Largest external script :
user posted image
That's why we've set on the option "Show report".















2. Stripped scm and Opcodes :

A. Stripped SCM :

For your first coding projects you need a main.scm that is small (orgininal one is just hudge), and doesn't have thing that is useless for scripting. You will gain time compiling and not having to wait for the first cutscene. And also because of the scm limits, read above.

So a stripped scm is a main.scm which don't contains any mission, any external script, any main threads. Contains almost nothing, it just creates the player.

You can find one in the folder \data\sa where you installed Sanny Builder under the name stripped.txt, it looks weird because it's written in Sanny Builder classes syntax, I won't tell much you about it, find more in Sanny Builder's Help. Not because it isn't good because I think it'll be easier to first learn with the "opcode method".

You should have something like that :


CODE
{
 use macro (Ctrl+J) "headsa"
 to insert a file header      
}
{$VERSION 3.0.0000}
var
$PLAYER_CHAR: Player
end // var
03A4: name_thread 'MAIN'
01F0: set_max_wanted_level_to 6
0111: toggle_wasted_busted_check 0
00C0: set_current_time_hours_to 8 minutes_to 0
04E4: unknown_refresh_game_renderer_at 2488.56 -1666.84
03CB: set_rendering_origin_at 2488.56 -1666.84 13.38
0053: $PLAYER_CHAR = create_player #NULL at 2488.56 -1666.84 13.38
01F5: $PLAYER_ACTOR = create_player_actor $PLAYER_CHAR
07AF: $PLAYER_GROUP = player $PLAYER_CHAR group
0373: set_camera_directly_behind_player
01B6: set_weather 0
0001: wait 0 ms
087B: set_player $PLAYER_CHAR clothes_texture "PLAYER_FACE" model "HEAD" body_part 1
087B: set_player $PLAYER_CHAR clothes_texture "JEANSDENIM" model "JEANS" body_part 2
087B: set_player $PLAYER_CHAR clothes_texture "SNEAKERBINCBLK" model "SNEAKER" body_part 3
087B: set_player $PLAYER_CHAR clothes_texture "VEST" model "VEST" body_part 0
070D: rebuild_player $PLAYER_CHAR      
01B4: toggle_player $PLAYER_CHAR can_move 1
016A: fade 1 time 0
04BB: select_interior 0
0629: change_integer_stat 181 to 4
016C: restart_if_wasted_at 2027.77 -1420.52 15.99 angle 137.0 town_number 0
016D: restart_if_busted_at 1550.68 -1675.49 14.51 angle 90.0 town_number 0
0180: set_on_mission_flag_to $ONMISSION // Note: your missions have to use the variable defined here
0004: $DEFAULT_WAIT_TIME = 250
03E6: remove_text_box

// put your create_thread commands here



:MAIN_LOOP
0001: wait $DEFAULT_WAIT_TIME ms
00BF: $TIME_HOURS = current_time_hours, $TIME_MINS = current_time_minutes
0002: jump @MAIN_LOOP


// put your mods (threads) here

//-------------Mission 0---------------
// put your missions here



//-------------External script 0---------------
// put your external scripts here


You probably noticed that there isn't a Define section ( DEFINE OBJECTS , DEFINE MISSIONS ...) there is nothing to worry here because there isn't anything that needs to be defined here. As said in the file if you need an header (define section) press CTRL+J and select headsa. Like on the pic :
user posted image

Then you'll get what you're missing :
CODE
DEFINE MISSIONS 0
//DEFINE MISSION {ID} 0 AT {LABEL} @
DEFINE EXTERNAL_SCRIPTS 0 // Use -1 in order not to compile AAA script
//DEFINE SCRIPT {NAME}  AT {LABEL} @
DEFINE UNKNOWN_EMPTY_SEGMENT 0
DEFINE UNKNOWN_THREADS_MEMORY 0


Now you can define your missions and external scripts.

To put mods in this stripped scm you need to put your create threads command (like 004F: create_thread @MYTHREAD ) where it says : // put your create_thread commands here . And put your scripts after the MAIN_LOOP where it says // put your mods (threads) here .


B. Opcodes :

In begining of most lines there is a 4 digit number followed by two dots like 0001:, 087B:, 016A: or 004E: like this 0605: in Sanny Builder . Those are called opcodes !!!!!!! And that's why we've set on the "Write opcodes" option.





The opcode is the number of the command (action or operation) that the game engine will do with the parameters given, all opcodes (expect for a few) has a fixed number of parameters.

Parameters (also called Params, or just P1, P2, or %p ) are the input (numbers, actors, vehicles, text strings any type of variables) of the command. Sanny builder on bottom left tells you how much parameters an opcode needs :
user posted image


Here is two example :

simple
CODE
000A: 3@ += 1 // integer values
  • 000A : the opcode which does the operation add to integers
  • 3@ and 1 : are the parameters, this opcode has 2 parameters.
So this get the local variable (more later) 3@ and adds one to it, like if 3@ was equal to 1 now it will be equal to 2 !!!


more complex
CODE
0605: actor $PLAYER_ACTOR perform_animation_sequence "ATM" from_file "PED" 4.0 loop 0 0 0 0 6000 ms
  • 0605 : the opcode of the command
  • $PLAYER_ACTOR , "ATM" , "PED" , 4.0 , 0 , 0 , 0 , 0 , 6000 : are the parameters, this opcode has 9 parameters.
This command make the created actor (character) $PLAYER_ACTOR perform the animation "ATM" in the animation file "PEDS" , 4.0 is the playback rate of the animation, loop 0 mean it won't do the anim again once finish if the integer is set to 1 the actor will do the again again and again (loop) until it's told to do something else (or destroy, or "free" -changing it to any others ped you see in the game, opcode 01C2), then there is other parameters that we will talk later about them. The last one is the time for how long the animation will be executed by the engine, act like a wait and will make the engine stop executing the code until that time.


Now to find the opcode you need you have many places :
  • Brilliant new "Opcode search tool" in Sanny Builder. In Tools menu, IDE tools, opcode search. Here just write what you're looking for and you'll get a chance to find it. There is a special section in Sanny Builder Readme at 4. Opcode Search Tool. It tells you the keys to copy opcodes to clipboard (selected opcode = Enter), to sort opcodes, etc... It uses the opcodes.txt that is created by Sanny and that you have to recrate manually if you change sacm.ini.

  • Original main.scm uncompiled (the more trustable one most times -pretty good explanation and if used here it DOES work-) Thanks to R* for making the game !!!!! Thanks to Barton Waterduck, Sanny Builder authors, and many others who help decompiling the scm, they should recognize themselves (if they have time reading this).

  • GTA:SA Opcodes @ GTAforums the place for opcodes and is very good because it contains good description, explainations, and what the value of a parameter do.
    Thanks to everyone who posted in the topic and to opius for starting it.
  • http://sa-db.webtools4you.net/ THE interactive database, the best way to use it is to search "nothing" (just clic go) you'll have all opcodes, and then search with your internet browser "find in the page".
But the best way is to refer to all of them !!!





The opcode descriptions come from a file called sascm.ini which is located in data\sa of Sanny builder installation folder. Updating this file will make new descriptions or/and change the opcode parameters.
  • Original Sanny Builder sascm.ini is very good I advise you to keep it for the begining.

  • Unified opcode databse from PLPynton here, or the file here.. If you don't want to use the file you can still find some opcodes in the topic.

    This opcode "database" has two big advantage, because it's very complete and keeps original parameters order, and a disadvantage is that it use a completly different syntax for description.
    Thanks to PLPynton for creating it.


  • Spaceeinstein's sascm.ini here. Use the syntax which has always been used. Thanks to him.
To use the files sascm.ini that are given there you have to compile all the files you are working on close Sanny builder (if open) put the file in folder \data\sa in Sanny Builder installation folder (make backup), open Sanny and uncompile the files. Evrytime you change sascm.ini you have to do that.



!!!!!!!!!!!! Important !!!!!!!!!!!!

About sascm.ini, don't mess too much with them, choose one and stick to it for a while. Everytime you change it you have to convert all your files, or compile and uncompile, but you have to watch out for opcode parameters, they get sometimes mess up in changing sascm.ini and you'll get crashes and bugs (and they'll be very hard to find).
You will also have to recreate your opcodes.txt files otherwise completion with F1 or in the Opcode search. To do this go Tools and "Make opcodes.txt".
My advise is to choose one of those, or keep the one that is given in Sanny Builder, and don't change it until you have a good reason to do so.
The tutorial is made with the sascm.ini given in Sanny Builder.











3.Parameters and variables :


There is different types of parameters :
  • integer (or int), also called whole numbers like 1 or -2 or 321 or any other.

  • Floats or floating point values, any decimal number like 1.2 or -2372.3845 . More on floating point numbers

  • An actor like CJ (YOU) which is store in the global variable $PLAYER_ACTOR , or Ryder ingame character in $SA_RYDER , or the soldier who watch the gate of the army base in Ryder's mission is store in the local variable @102 . The variable gets called an handle when holding (keeping in memory) an actor (or a car), it will be the name of the object next, the handle form where you grab it.

  • A "car" (in coding every vehicle -flying, floating, choppering- is a car), like often the car you're driving $PLAYER_CAR , well like the actors they're stored in local or global variables. Same as actors when stocking a car in a variable it's then called an handle.

  • Model identifier like #CHEETAH , #ARMY , #PARACHUTE , the 3D model of a car, an actor, an object. It refers to the dff files that are store in gta3.img. And this model is needed to be loaded (put in memory) to create cars, actors or objects.

  • Short text strings (8 bytes long) like 'STRAP_4' or 'MTIME3' which are lettred words that the engine "reads" when passing through and look for the file -or the line a the file- named. They're always 7 character maximum. It refers to file names such as gxt, animation files, IPL files (interiors garage etc...) or threads names, text entries (from gxt file), animations (the animation in the animation file), and many other things. Don't worry much it's just a format for the parameter.

  • Long text strings (16 bytes or more long,) like "ATM" or "JEANSDENIM" . It's exactly the same as above it's just a format for the parameter, but this one can handle longer words (Sanny's ReadMe says up to 255 characters) and is used even if the word is shorter than 7 characters. You can find more explanations on strings (both short and long in this message from Seemann)

  • Labels like MAIN_4059 which are used only in jumps (and gosubs) because those opcodes ( 0002: jump @ ; 004D: jump_if_false @ ; 0050: gosub @ ; or 004F: create_thread @ ) make the engine travels to (jump at) the label told. The label is represented with : before it.

    example :
    :label
    0001: wait 0 ms
    0002: jump
    @label
Variables are a little piece of memory where you store something in it. Once you've defined it the engine will remeber it until it's changed or cleared, even after saving the variable will still present (saving saves all the variable and reloads it when the game is loaded). Like when you create an actor you assign it a variable, which would be like it's name. In those you can put anything integer, floats, actors, vehicles, text strings (special format).



Then there is two big family of variables :
  • Global variables : which are represented by starting with $ . Globals can be use everywhere in the main.scm. If you set it to something in the main part in mission it will still be accessible and equal to something. Exemples : $ONMISSION , $PLAYER_ACTOR .

  • Local variables : Locals are represented by an @ at the end like 1@ , 2@ . Each thread ( created by 004F) has his own set of locals, like 0@ in :thread_A isn't the same as 0@ in :thread_B . In main part you cannot use over 33@ (which is a local timer see downer for more details). But in mission you can use up to 1024@ .
Locals timers : 32@ and 33@ , are internal locals timers, they count the number of milliseconds that have elapsed. Like if you set it to 0 , wait 10 seconds and look how much 32@ or 33@ worth you'll find 10 000. if you set it to 1 000 and wait 5 second before looking it will then be equal to 6 000 ms.

Short and long text strings : text strings are stored in special format of variables. Text string a highlighted in red in Sanny. There is 4 kind of text variables 2 for short (8 bytes, 'STRING' ) strings, 2 for long strings (16 bytes, "LONGSTRING" ) :

For short strings :

- a global text string like : s$1169 or s$ACTOR_SPEECH_GXT_REFERENCE which can always be accessible like other globals.

- a local text string like : 170@s or 5@s which are accessible only in their own thread.


For long strings :

- a global text string : v$1225 or v$MYLONGSTRING , same as short string but for long ones...

- a local long string : 28@v , same as short ones...


BUT watch out, for exemple 0@s replace 0@ if existing and vice versa, it is the same variable but they're just in a different format.


And I want to remind (or tell) you that a integer and a float are different to game engine ( 1 isn't the same as 1.0 !!!!!). If the opcode needs a float and you give it a int (and vice versa) the game WILL crash.
You can convert an integer to a float with opcode 008D. And convert a float to an integer with 008C.












tomworld10
  • tomworld10

    Mark Chump

  • Members
  • Joined: 29 Jun 2005

#2

Posted 14 November 2006 - 09:35 PM Edited by tomworld10, 31 May 2008 - 04:51 PM.

4. Threads and labels :

A thread is a "stand alone" (something that needs nothing but itself) piece of code. It's like a program by itself (like an opened window on your operating system -like Microsoft Windows-). So to use (play ingame with) your future mods (programs, windows) you'll need to create a new one. What you do with 004F like :
CODE
004F: create_thread @MYTHREAD


Threads are like fire in a world with matches (ligther, silex, well you cannot "make" fire you need to ingnite it from another fire -like the Olympic Flame never switched off between 2 olympic games). You must create a new one from an existing one. As I said before the main thread is created by the engine itself. The 'MAIN' thread wil then be the match will lite your fire. So if it's the only existing thread (like in a stripped main.scm) you'll need to create your thread in the main thread BEFORE it gets switched off by (before this line) :
CODE
004E: end_thread



If using a bigger file (like orignal main.scm) just create it where there is many others create_thread (004F) like this :


user posted image


Don't worry about "00D7: create_thread_with_wasted_busted_check " because their real use is actually unknown yet. Use 004F, there is better ways to check if player is wasted or busted (like conditional opcode 0112). As Seeman tells us later in the topic 004f creates a thread with 0 to 32 extra-parameters, and 00d7 creates a thread with 0 extra-parameters. So don't worry at all about 00d7 because 004f does the same and as more functionalities. (Seemann's message)



Like I said before in each single thread you've create you have for each thread it's very own set of locals from 0@ to 33@ ( 32@ and 33@ being local timers). They're pretty usefull because not sucking up memory.




A label is a little piece of thread like :MAIN_4059 . Think now the thread as a book (no more fire cry.gif ) and labels would be pages of this book. Then you can easily understand that a jump (or jump_if_false, or gosub) to a certain label would be like a report to a certain page.


I made an animated example for you to see how the game engine travels through the labels :
user posted image

The red line represent the code (the engine is called sometimes simply the code, like the code reader) going through labels.

As you can see the thread label is created from another thread. You can see the code "seperating" in two one going to just created thread label one keeps doing the thread it use to do, and it gets ended (but could be continuing to do things if you don't end it).
It goes through :label to :label_100 . In :label_100 you can see there is an "if" with a condition in it, followed by a jump_if_false, this means that if $PLAYER_ACTOR is near position in 3 dimension 2498.0 -1711.0 1015.0 the code can pass through and jump to :label_200 .
So the code keeps looping in :label_100 until the condition is satisfied.
Then jumps to :label_200 without passing through :label_150 , going straight to :label_200 . Does what it needs to do in :label_200 (which is to put the 3D coordinates of actor $PLAYER_ACTOR into variables $X_COORD $Y_COORD $Z_COORD ). Then jumps to :label_150 , waits 1minute and jump back :label_100 and check again if player's near the point. And will do all over again and again and again. You don't have to end a thread if you don't need to, it can just keep check something to start. Don't forget you got to do something with your thread, keep it running or end it but don't let it free.


!!!!!!! Notice the wait (0001: wait 0 ms), because it's compulsory !!!!!!!!!!!!!
When looping you have to add a wait so the engine doesn't get itself stucked in it, and it won't even crash then it will just simply freeze. The only way to recover from it is to force resolution change (sometimes just impossible to do, and some laptops have a combo key) and end GTA:SA with task manager.

If you don't really know if you should add a wait or not just add "wait 0 ms", because most times you will not see the difference at all, and mostly anything under 500 ms you don't notice it.








5. "If"s and conditional opcodes :

What's called an "if" is a code strucutre that checks if something is happening. Like :
if
I die
if not then --> I will finish my mods
--> you give all my unfinished mods to the GTA community


In Sanny Builder it would look like
user posted image

The engine will travel straight through if the something checked happens but jump to another label if it doesn't happend (004D: jump_if_false @ ). The something (which could or not happend) of the if is called a condition, for them you use conditionals opcode !!!!!!! And you can put up to seven conditions in one if !!!!!!! (I know you're like "Yes I'm so happy, that's really change my life !!!!!!...." but... )



Then there is two kind of multiple conditions ifs :

When you have multiple conditions you might want to have all conditions true (happens) or at least one of them true.
  • if and is when you want all the conditons to be true for passing through like :
    user posted image
    So here you can see that if all those external scripts are loaded it goes through but then if any of them isn't it will jump to label :INTMAN_1088 . You can think it as if this and this and this is OK then go throught if not jump because it's false.


  • if or is when you only need one of those conditions to be go through like :
    user posted image
    Here it's if any of these door is open keep going but if not jump to :MAIN_4336 . You can think it as if this or this or this or happens go througt but if there isn't any that is true jump because it's false.
And and or are called logic operators.

Notice how it wouldn't make sens to add an or or an and in a single condition if. Only one condition, you just cannot use them, only one element !!!!! And sanny builder won't like it neither it will tell you "hey don't do that".

On the other hand don't forget to put an or or an and to your multiples conditions ifs, becasue sanny won't say anything, the game might not crash, but I'm sure it won't work properly, either and or or, but you need to put something in multiple conditions ifs.




You can negate all conditional opcodes. Negate is like adding a not in the conditons. If actor not dead, or if actor not driving. Then it means that to pass through it, the condition needs to return false (don't happend). You can negate conditional opcodes in mutlpiple conditions ifs too. To negate a conditional opcode you have to put a 8 at the first digit instead of 0, like :
user posted image
not negated


user posted image
negated

You don't have to write not the compiler (sanny) will not look at it, and it will write it when re-uncompiling. But you still can write not if you want, it makes it clearer and easier to work with. But you really HAVE TO write the 8 in the opcode.

When you negate all conditions a 'multiple conditions if', you have to change around the logic operator.

user posted image

user posted image

Those two do the same :
  • the first one checks if player is agressive or aiming at actor 14@ or aiming at actor 15@ or aiming at actor 16@ or aiming at actor 17@ , if any of those is true the code passes through and jump to labelz .
  • the second one check if player is not agressive and not aiming at actor 14@ and not aiming at actor 15@ and not aiming at actor 16@ and not aiming at actor 17@ , if any of those is false (if player do aims) the code will jump because it's false to labelz .
Sometimes when look for some nice mods you might find :

CODE
00D6: if 0


or
CODE
00D6: if 5


or
CODE
00D6: if 21


or
CODE
00D6: if 25


Don't worry it's the same, compile, then decompile it and you'll have the logic operator written. And that's why we've enable "Conditions check", so we can use and & or and Sanny writes them when decompiling.

if 0 = if

if x = if and

if 2x = if or

Read Conditions in Sanny Builder's Help or/and
here (It's for Vice City but is the same, just ignore "?") for more explanations.

You might want to do high-level conditions construction, read Conditions in Sanny Builder's Help, it explains it pretty well. Low level constructions can be good for now, and you can make high level with low level anyway.



BUT remember well when doing "if"s, add waits where you know the code is going to loop back. And a wait 0 is never a problem because it actually wait for 0 milisecond which is pretty short !!!!!!! but it will let time to the engine doing other things. Relook at the animated exemple for labels to understand where you'll absolutly need wait.














6. Request models, load them before create, then releasing it to free memory :

When creating actor (with opcode 009A), car (with op 00A5), object (with op 0107), give weapon to an actor you have to request the dff model before and load it, and check that is it loaded for real !!!!!!

Like :
CODE
0001: wait 0 ms
0247: request_model #HFYBE
0247: request_model #POLICE_BARRIER
0247: request_model #BMYBOUN
0247: request_model #WMYBOUN
0247: request_model #DESERT_EAGLE
0247: request_model #MP5LNG
0247: request_model #CHEETAH
0247: request_model #TURISMO
038B: load_requested_models
00D6: if and
 0248: model #HFYBE available
 0248: model #BMYBOUN available
 0248: model #WMYBOUN available
 0248: model #DESERT_EAGLE available
 0248: model #MP5LNG available
004D: jump_if_false @GSHAUTO_564
00D6: if and
 0248: model #POLICE_BARRIER available
 0248: model #CHEETAH available
 0248: model #TURISMO available
004D: jump_if_false @GSHAUTO_564
009A: 11@ = create_actor 4 #WMYBOUN at 561.0 -1252.0 17.0
009A: 14@ = create_actor 4 #BMYBOUN at 552.0 -1257.0 17.0
009A: 15@ = create_actor 5 #HFYBE at 567.0 -1290.0 17.5
009A: 16@ = create_actor 4 #WMYBOUN at 561.0 -1255.0 17.0
009A: 17@ = create_actor 4 #BMYBOUN at 553.5 -1260.0 17.0
009A: 18@ = create_actor 4 #WMYBOUN at 569.0 -1292.0 17.5
009A: 19@ = create_actor 4 #BMYBOUN at 569.0 -1288.0 17.5
0107: 9@ = create_object #POLICE_BARRIER at 560.0 -1254.0 17.0
00A5: 0@ = create_car #TURISMO at 1793.4956 -1907.4233 12.3992
00A5: 1@ = create_car #CHEETAH at 1793.4956 -1907.4233 12.3992
01B2: give_actor 11@ weapon 29 ammo 900 // Load the weapon model before using this
01B2: give_actor 14@ weapon 29 ammo 900 // Load the weapon model before using this
01B2: give_actor 15@ weapon 24 ammo 300 // Load the weapon model before using this
01B2: give_actor 16@ weapon 29 ammo 900 // Load the weapon model before using this
01B2: give_actor 17@ weapon 29 ammo 900 // Load the weapon model before using this
01B2: give_actor 18@ weapon 29 ammo 900 // Load the weapon model before using this
01B2: give_actor 19@ weapon 29 ammo 900 // Load the weapon model before using this



Look how I first request the models (with 0247: request_model) then load them (with 038B: load_requested_models). Then checks if all models requested are available to use (with 0248). If any of them is load jumps back to top and re-request and reload them. If they all are then create the actor, the weapons and the object. You can see in the comment (after //) that 01B2 need the weapon model to be load before using it (for weapons numbers look in Sanny's help at Weapons numbers in SCM documentation for GTA SA or at very good Generic SA SCM Documentaion.


Once you've finished doing what you need to with thoses (they're all dead, player is too far away, don't want them here, etc...) transform them into usuals peds and cars (like all the peds and cars you see in-game) or destroy them (the object must be destroyed) :

CODE
0108: destroy_object 9@
01C3: remove_references_to_car 1@ // Like turning a car into any random car
01C3: remove_references_to_car 0@ // Like turning a car into any random car
01C2: remove_references_to_actor 11@ // Like turning an actor into a random pedestrian
01C2: remove_references_to_actor 14@ // Like turning an actor into a random pedestrian
01C2: remove_references_to_actor 15@ // Like turning an actor into a random pedestrian
01C2: remove_references_to_actor 16@ // Like turning an actor into a random pedestrian
01C2: remove_references_to_actor 17@ // Like turning an actor into a random pedestrian
01C2: remove_references_to_actor 18@ // Like turning an actor into a random pedestrian
01C2: remove_references_to_actor 19@ // Like turning an actor into a random pedestrian


or
CODE
0108: destroy_object 9@
00A6: destroy_car 0@
00A6: destroy_car 1@
009B: destroy_actor_instantly 11@
009B: destroy_actor_instantly 14@
009B: destroy_actor_instantly 15@
009B: destroy_actor_instantly 16@
009B: destroy_actor_instantly 17@
009B: destroy_actor_instantly 18@
009B: destroy_actor_instantly 19@


Don't apply those (01C2, 01C3, 0108, 00A6, 009B, etc...) to an actor, or a car that doesn't exist (or when the handle that should hold it -like 0@, $car, etc...- doesn't hold it), because the game will badly crash!!!!!!

Once you got rid of actors/cars/objects (So when you finished using them, and after you have delete them, and only after that), you can release the models you've used because you no longer need them.

CODE
0249: release_model #WMYBOUN
0249: release_model #BMYBOUN
0249: release_model #HFYBE  
0249: release_model #POLICE_BARRIER
0249: release_model #DESERT_EAGLE
0249: release_model #MP5LNG
0249: release_model #CHEETAH
0249: release_model #TURISMO



You actualy could have release those models earlier, you don't need them to be loaded after you have created the game object (object, actor or vehicle). But I advise you for a start to release the model only at the end of your script/mission when you sure won't need it anymore. It will prevent you from a few return to desktop.



Conclusion :


Well, this part was mostly informations, there isn't much to do. But now you that an opcode is a 4 digit number that do things with the parameters you gave it. You know the different types of parameters, what's a local variable and what's a global one. And many other things that you need to know to keep going. Now we speak the same "language" we can get to real coding.
Let's get to part II...

Have fun

Seemann
  • Seemann

    Ruhe

  • GTA Mods Staff
  • Joined: 03 Sep 2004
  • Russia
  • Best Tool 2013 "Sanny Builder"
    Contribution Award [Mods]
    Helpfulness Awards [Mods]

#3

Posted 15 November 2006 - 09:07 AM

@ tomworld10

QUOTE
You can you any globals you want

Their number is limited too. Only up to 16383 variables can be used.

QUOTE
It uses the sascm.ini provided to Sanny

No, it uses OPCODES.TXT as well as F1.

QUOTE
you have for each thread it's very own set of globals from 0@ to 33@

... of locals ...

QUOTE
Don't worry about "00D7: create_thread_with_wasted_busted_check " because their real use is actually unknown yet. Use 004F, there is better ways to check if player is wasted or busted (like conditional opcode 0112).

I believe, 00d7 is not related to the wasted_busted check at all. It is the same as 004F but has the only parameter while 004F checks if there are the extra parameters.

QUOTE
- Ctrl + F3 : find previous

Shift + F3

QUOTE
- This will create a cheetah (#CHEETAH)

- This will create a... *BOOM* (game's dead...) smile.gif Check out the model name, it's #NULL.


ps. awesome work wink.gif

jarjar
  • jarjar

    Boss

  • BUSTED!
  • Joined: 07 Aug 2005

#4

Posted 15 November 2006 - 09:55 AM

Nice job tomworld10, although, it would be better suited and of more use if it was posted in the Tutorials Forum smile.gif .

Y_Less
  • Y_Less

    629

  • Members
  • Joined: 14 Mar 2004

#5

Posted 16 November 2006 - 01:38 AM

Err, WOW!

I've not finished reading it all yet, tbh that may take a while so if you actually mention these I appologise. 1, you mention that the MAIN segment is sometimes inaccurately called the MAIN thread wheras infact the main thread is something different, it is basically the unending, entirely useless loop at the end of the initial setup (technically everything from the start of the code to that loop is the main thread.

Seemann, I think you my have just solved one of the oldest coding mysteries, it was pretty much always known that code was nothing to do with wasted/busted checks but no-one knew what it actually was, that's possibly the best suggestion I've heard yet.

Also, you CAN bypass the global variable limitation by using badly formed arrays (array indexes can be 32bit so if you have a 1 cell big array but reference points outside it it can read almost anywhere.)

dertyjerzian
  • dertyjerzian

    I have a custom member title. I call it "Solid Snake"

  • BUSTED!
  • Joined: 08 Jun 2005

#6

Posted 16 November 2006 - 04:31 AM Edited by dertyjerzian, 23 November 2006 - 05:27 PM.

Ok, I finished it. I still can't code lol.gif
cookie.gif

Seemann
  • Seemann

    Ruhe

  • GTA Mods Staff
  • Joined: 03 Sep 2004
  • Russia
  • Best Tool 2013 "Sanny Builder"
    Contribution Award [Mods]
    Helpfulness Awards [Mods]

#7

Posted 16 November 2006 - 08:22 AM Edited by Seemann, 16 November 2006 - 08:31 AM.

QUOTE (Y_Less @ Nov 16 2006, 10:38)
that's possibly the best suggestion I've heard yet

This is more than suggestion. I was looking through exe code and didn't see any differences between them except two things. First of them, as I said, 004f looks for the extra parameters to pass them into a new thread, while 00D7 just creates a new one. And the second difference is that when you set the negative value for 004f's label (create_thread -1) the engine rewrites this with the opcode value (0x4F), so actually it's the same as 004F: create_thread 0x4f. I don't know why it may happen.

Though, I think both these opcodes have to be named 'create_thread' or
CODE
004f: create_thread_with_extra_params
00d7: create_thread


QUOTE (Y_Less @ Nov 16 2006, 10:38)
Also, you CAN bypass the global variable limitation by using badly formed arrays (array indexes can be 32bit so if you have a 1 cell big array but reference points outside it it can read almost anywhere.)

Right, I already used this way.

tomworld10
  • tomworld10

    Mark Chump

  • Members
  • Joined: 29 Jun 2005

#8

Posted 16 November 2006 - 11:09 PM Edited by tomworld10, 11 December 2006 - 01:32 PM.

Hi,



Thanks for your support guys, I love that.


@Seemann : thanks for the corrections, I've corrected part one, but as part II is locked I can edit it yet but I'll do it in my files. This is a freeware you can use parts or all of it if you want to.

@jarjar : I wanted it to be her first so I can correct mistakes, add more things on it.

@Y_Less : "I've not finished reading it all yet" for me this is very gratefulness, and " Err, WOW!" I'm not sure what it means but it seems nice tounge.gif .

@dertyjerzian : yes, you're right it could be cleaned up but I've already written it, updated it, reupdated it, and now I've got to finish it up, once this will be done I'll be far too tired to clean it up (and it will be very ahrd for me to delete pieces of this hard work...). But as I said to Seemann this is a freeware you can use parts or all of it if you want to, so if you want to clean it up, don't worry go for it, the christian bible as summary too.


Have fun

Seemann
  • Seemann

    Ruhe

  • GTA Mods Staff
  • Joined: 03 Sep 2004
  • Russia
  • Best Tool 2013 "Sanny Builder"
    Contribution Award [Mods]
    Helpfulness Awards [Mods]

#9

Posted 18 November 2006 - 08:43 AM

QUOTE

It's exactly the same as above it's just a format for the parameter, but this one can handle longer words (Sanny's ReadMe says up to 255 characters) and is used even if the word is shorter than 7 characters.

I figured out how the game handles with the long strings. There is a number of limits and game sets the needed one itself for specific opcodes:

(the following numbers are real maximum without a null-terminator);
----------------------------------------------------

8 bytes (the smallest limit I've ever seen):
is set for the car numberplate used in 0674, 09e2

14 bytes:
is used for the textures names: 038F, 09A9

15 bytes: is used for the opcodes that store a string into the var block memory.
For example: 06D1
also is used for the shopping item names:
For example: 087B, 075D, 075E

17 bytes: is used for the object group names.
For example: 0776, 0777, 0778; the 5th parameter of 0755;

23 bytes: is used for the animation names.
For example, 0393, 0812; the 4th parameter of 0755; the 2nd param of 075a and so on.

31 bytes: is used for the particle names.
For example: 064B, 0669, 066A and so on.

39 bytes: is used for the debug opcodes.
For example: 0660, 0661, 0662 and similar.

----------------------------------------------------

-/TNT\-
  • -/TNT\-

    not like any other rainbow.

  • Members
  • Joined: 06 Aug 2006

#10

Posted 20 November 2006 - 03:34 PM

Big, big thanks tomworld, the best motivation for me to involve myself in scripting.

Bigun
  • Bigun

    wandering about

  • Members
  • Joined: 10 Jul 2004

#11

Posted 21 November 2006 - 02:21 PM

Great job, tomworld!
We finally have a good up-to-date tutorial on SA coding. happy.gif
You DO need to add some things in, though it's still better than other existing tutorials. icon14.gif
The use of animated GIFs was a nice idea! Props. Though you it's a bit hard to understand - you should re-do them, use a wider line and with different colors when it loops so they're distuinguishable. Also each move/line-curve you should add the number in the image, and underneath the image write slightly-detailed explanations of each number.

And you're probably aware that there is a Tutorials forum. Yes, all tutorials go there, including coding tutorials. In fact AFAIK you can post some non-directly-GTA-modding-related tutorials there too.

tomworld10
  • tomworld10

    Mark Chump

  • Members
  • Joined: 29 Jun 2005

#12

Posted 11 December 2006 - 05:30 PM

sorry my bug

Mark
  • Mark

  • Feroci
  • Joined: 15 Aug 2002
  • United-Kingdom

#13

Posted 11 December 2006 - 06:51 PM

Excellent! Time for me to piss about spawning things I think smile.gif .

BMWPower
  • BMWPower

    SiX-In-Line Rulz!

  • Members
  • Joined: 06 Nov 2004

#14

Posted 18 December 2006 - 01:19 PM

@Tom: thanks, mate, that's great. I hope after i read the two parts i'll be able to do something.. blush.gif turn.gif

ceedj
  • ceedj

    PEDS Creator

  • Feroci
  • Joined: 21 May 2005
  • United-States

#15

Posted 18 December 2006 - 02:32 PM

QUOTE (tomworld10 @ Nov 14 2006, 16:35)
Once you got rid of actors, or/and cars, (and only after that) you can release the models you've used because you no longer need them.

It's very important to do it this way, so you don't crash the games, and don't slow it because to many models are loaded.

Hi tom! Nice job on this; SB scares me, so this will give me a way to "ease" into it after doing Barton/c++ stuff for so long. So thank you!

I was wondering if you could expand upon the above quote, as I'm not quite sure I understand. I was under the impression that once a model is loaded and the appropriate car/ped/object is created, that you can release the model immediately after.

For example, in my mod, I have a teleporter for about 30 areas of San An. What I did was created a ped at the Red Dragon, animated it then teleported to CJ's house in Ganton and did the same thing to a second, different ped. No crashes. In fact, I set the ped in LV to do a long animation, jumped to Ganton, did another long animation for ped 2, teleported back and ped 1 was just finishing. I suspect the same would happen to ped 2, but I never bothered to go back and check; I figured, it didn't crash, so yay me. smile.gif

(Just to clarify, my mod does indeed release the model immediately after creation.)

So is this practice as you stated just because R* does and no one bothered to check otherwise? Or could it be a byproduct of the "hook" I use (which injects itself into the game)?

Just curious about this, and thanks again. Great job on the tutorial. icon14.gif

tomworld10
  • tomworld10

    Mark Chump

  • Members
  • Joined: 29 Jun 2005

#16

Posted 18 December 2006 - 07:30 PM

Hi,


Thanks for your support members with many stars, thanks a lot.


Sadly I havn't had much time to finish part II (and sadly again I got heaps work to do on it)....


@ceedj : I've clarified what I wanted to say, so release after using/animating/etc and after deleting. BUT you're actualy right sometimes you can release just right after creating, but first R* does it after deleting (for me R* is 99% right), and sometimes I found out that you need to have the model in memory while doing thing on the actor/car/object otherwise it crash, I'm pretty sure for when you make the actor using a weapon. I MIGHT BE WRONG, but as it's a tutorial I wanted to do it the "safe" way, and I thought is not very important as you can load up to 256 models (not sure i'm saying 256 for what I remember), so you have probably heaps "memory slots" for other models before having to release them.

What I'm saying it's that you don't need to release them right away as you still can load a lot models. But like you I've seen that sometime you could release them right away it doesn't crash the game.

But again I wanted to show the "safe" way in the tuto, and further more I wanted to show the R* way. And as it's one of the more important thing of the bible I wanted it to be very very very safe....

And as well I'm sure that releasing the model after animating and then deleting doesn't make the game crash, but I'm not as sure that releasing the models right away doesn't make the game crash.

I hope I been clear enough. Thank you for pointing out things that are not clear enough, thank you for reading, thank you for asking, thank you for giving examples with your question and thank you for your support.



@everyone : Don't forget unfinished part II is here.




Have fun

Bigun
  • Bigun

    wandering about

  • Members
  • Joined: 10 Jul 2004

#17

Posted 19 December 2006 - 12:44 AM

QUOTE (tomworld10 @ Dec 18 2006, 21:30)
@ceedj : I've clarified what I wanted to say, so release after using/animating/etc and after deleting. BUT you're actualy right sometimes you can release just right after creating, but first R* does it after deleting (for me R* is 99% right), and sometimes I found out that you need to have the model in memory while doing thing on the actor/car/object otherwise it crash, I'm pretty sure for when you make the actor using a weapon.

R* code (or at least what we have of it) is often inefficient/bad (despite it working).
You can 'release_model' immediately after creating the object. Basically, 'request_model' is "load the model and keep it always loaded" or "load the model and flag to not unload it" and 'release_model' ISN'T "unload the model", it is "flag model can-be-unloaded", then the engine will unload that model when it's no longer needed (ie nothing uses it).

When giving weapons to actors, you need to have the weapon model loaded. You can understand why this is needed; especially if the weapon is gonna end up as the chosen-weapon/currently-held-weapon.
Also this isn't really relevant for this discussion, as you DON'T need the ACTOR model loaded, you need the weapon model.

QUOTE (tomworld (continued))
and I thought is not very important as you can load up to 256 models (not sure i'm saying 256 for what I remember), so you have probably heaps "memory slots" for other models before having to release them.


Even if there was no internal limit, it would still be important. For one, you don't wanna waste memory on models which are no longer in use/no longer needed.

Also, I don't remember the exact limit since I'm somewhat dusty on SCMing, but I'm pretty positive it's LOWER than 100. I think it's actually as low as ~60. If you will, a quick forum search should give you the exact limit.

QUOTE (tomworld (continued))
What I'm saying it's that you don't need to release them right away as you still can load a lot models.


Well, you don't NEED to release them right away, but as stated above, you should.
The last part of the sentence isn't true either; you can't actually know how many models are currently loaded (by the engine itself, or if it doesn't account in the limit, by other scm threads).

QUOTE (tomworld (continued))
But like you I've seen that sometime you could release them right away it doesn't crash the game.


It should never cause problems. Maybe there are rare exceptions (well, logically opcodes which somehow have to do something specifically with a model), but I don't remember any off the top of my head.


Good luck with writing the rest of your tutorial, good job. smile.gif

tomworld10
  • tomworld10

    Mark Chump

  • Members
  • Joined: 29 Jun 2005

#18

Posted 20 December 2006 - 08:39 PM Edited by tomworld10, 20 December 2006 - 08:44 PM.

Hi,



@admins : Can I request to change the topic icon to a SA icon, if possible, on part I and II, I forgot about when I created the topics. Sorry about that and thank you in advance, thank you again for all your continious work.


@everyone : I've seen a few days ago a list of all animations (Action sequences), But I can't find it again, I was pretty sur it was in a pinned topic but it's not.... Was I only dreaming ??? If I wasn't can you please tell me where it is or a give me a link. Thank you in advance.




@Bigun
QUOTE (tomworld10@coding part I)
Once you got rid of actors/cars/objects (So when you finished using them, and after you have delete them, and only after that), you can release the models you've used because you no longer need them. (Note that this is a disputed topic but it's my point of view you can read discussion about it from this message and the followings)


As people are still free to do what I tell them to or not I give them the possibility to do as they want if (and only if) they are bothered to read further....

About R* they made the games so for me they can code as bad as I do, or even worst, they will still be 99% right. They unintentionally thaught me coding (yes, if it wasn't obvious enough, I didn't know coding before), So I'll be teaching coding the same way they do.

Then when you say :
QUOTE (Bigun @ Posted on Dec 19 2006 @ 00:44)
Basically, 'request_model' is "load the model and keep it always loaded" or "load the model and flag to not unload it" and 'release_model' ISN'T "unload the model", it is "flag model can-be-unloaded", then the engine will unload that model when it's no longer needed (ie nothing uses it).

There could be a chance where the actor is not in sight of the player (too far away), not being animated, nothing using the model, for a "long time", the model could be considered as no longer needed by the engine and so have a little crash....

But I'm sure you're right for 99 times out of 100 but as I said to ceedj I'm sure that releasing the model after deleting the actor doesn't make the game crash, but I'm not as sure that releasing the models right away doesn't make the game crash.

Well a lot of talking for not very much but thank you for your giving your point of view in the discussion and for saying what you find wrong in the tuto, I like it even if we don't agree about what we are debating.




Have fun



ceedj
  • ceedj

    PEDS Creator

  • Feroci
  • Joined: 21 May 2005
  • United-States

#19

Posted 20 December 2006 - 08:51 PM

RE: Animation list, that was me. smile.gif

Here's a link from GTAGarage:

SA Animations List

EDIT: Note that the animations listed are only the ones I found in the main.scm. I know there are a TON more though.

Y_Less
  • Y_Less

    629

  • Members
  • Joined: 14 Mar 2004

#20

Posted 20 December 2006 - 08:52 PM

If an actor has an assigned handle it will not disappear until you explicitly tell it to. Actors aren't like peds, releasing the model after you've created it is not a problem. Also, request_model isn't what Bigun said, it is literally requesting the engine to load a model, which is why you need to check it.

However there is no right or wrong time to unload the model, it makes no difference with the model memory size.

Bigun
  • Bigun

    wandering about

  • Members
  • Joined: 10 Jul 2004

#21

Posted 20 December 2006 - 09:26 PM Edited by Bigun, 20 December 2006 - 09:46 PM.

QUOTE (Y_Less @ Dec 20 2006, 22:52)
If an actor has an assigned handle it will not disappear until you explicitly tell it to.  Actors aren't like peds, releasing the model after you've created it is not a problem.

Yeah, I wrote my previous post based on that, I should've mentioned it.
While there is an object still referenced, it's model is always flagged as needed. So an object's model won't get unloaded (regardless of whether you release_model or not) until you remove_references (I don't remember as I haven't actually compiled SCMs for ages, but I think when you do destroy_something, it also remove_references it automatically) to it.

QUOTE (Y_Less)
Also, request_model isn't what Bigun said, it is literally requesting the engine to load a model, which is why you need to check it.


Hm? That's what I said.
QUOTE (Bigun (me))
Basically, 'request_model' is "load the model and keep it always loaded"

could be worded as: "load the model and flag not to unload it"
That doesn't contradict the fact you need to check if the loading is finished or not.
Also, I guess I should account for the references part. Ultimately:
request_model == "Load the model, and flag not to unload it"
release_model == "Flag to unload the model once:
A) There's no object referenced using that model
and
B) It's no longer in use (aka no object at all near the camera uses the model)"

QUOTE (Y_Less)
However there is no right or wrong time to unload the model, it makes no difference with the model memory size.

Yeah, this is minor, though despite that, you should ideally just 'release_model' the model once you're done with it. Makes the code more robust (mostly provided there aren't subsequent uses of the model there). Also, if you happen to have more than one "end/cleanup" label in your code thread, you won't need to have the 'release_model' opcodes in each.

Y_Less
  • Y_Less

    629

  • Members
  • Joined: 14 Mar 2004

#22

Posted 22 December 2006 - 03:04 PM

I edited the post icon but I'm not sure if you couldn't have done it yourself tbh.

silvermanblue
  • silvermanblue

    Magnets=Miracles

  • Leone Family Mafia
  • Joined: 06 Feb 2004

#23

Posted 23 December 2006 - 06:54 AM

Not to shabby here thake these cookie.gif cookie.gif catloaf_by_anuj.gif

tomworld10
  • tomworld10

    Mark Chump

  • Members
  • Joined: 29 Jun 2005

#24

Posted 11 February 2007 - 06:20 PM



Hi,



@silvermanblue : thank you

@Y_Less : I'm sorry you're right I could have done it my self, but I always thought I could not and like I don't create new topics very often I really thougt I couldn't... Sorry again

@Bigun : You are right. But after the reasons I already gave leaving it in the tutorial, the biggest reason is that I will have to change it everywhere in the tutorial, and that's a big load of work, and I'm too afraid of confusing newbies... But maybe one day once the bible will be all finished, I might make something cleaner about this.

@ceedj : After adding "This file was written by ceedj. Please ask the author before mirroring it, thank you." and anything you want, can I mirror your SAAnims.txt, so its "one clic" available ? Because having to log in on gtagarage, downloading the zip, uncompressing and finaly reading is a someway long operation. Having it "one clic" would make it much easier to read and further more easier for bible readers.



@everyone : The bible is slowly growing up, chapter 7.Objects and moving them is finished, chapter 8.Animations and particules is about half way done, but isn't that hard to complete. I'm getting afraid of chapter 9.Animating vehicles and car mods,because I'm not very good at driving behaviour and all such things, no trouble with the rest of the chapter, but driving behaviour, follow paths and those things will need a lot of research and testing...
So any help from you guys will be truly appreciated !!!!! Don't put yourself in a hurry, but just keep it in mind and when you have the time, just post here. Thank you all in advance for this

The other chapters should be pretty much easy, as there isn't much research and testing to do for me.



Have fun


ZAZ
  • ZAZ

    Kernlochbohrer

  • Feroci
  • Joined: 10 Jan 2005
  • European-Union
  • Contribution Award [Mods]
    Helpfulness Awards [Mods]

#25

Posted 15 May 2008 - 04:09 PM

Can someone of the admins pinn these 2 topics please biggrin.gif

Coding bible part I

Coding bible part II

Y_Less
  • Y_Less

    629

  • Members
  • Joined: 14 Mar 2004

#26

Posted 16 May 2008 - 01:17 PM

QUOTE (tomworld10 @ Feb 11 2007, 18:20)
@everyone : The bible is slowly growing up, chapter 7.Objects and moving them is finished

Sounds good, just wondering if you covered any of this in it, unfortunately I can't find the original topic linked to there any more sad.gif .

tomworld10
  • tomworld10

    Mark Chump

  • Members
  • Joined: 29 Jun 2005

#27

Posted 17 May 2008 - 07:17 PM


Hi,

QUOTE (Y_Less @ May 16 2008 @ 13:17)
QUOTE (tomworld10 @ Feb 11 2007 @  18:20)

@everyone : The bible is slowly growing up, chapter 7.Objects and moving them is finished


Sounds good, just wondering if you covered any of this in it, unfortunately I can't find the original topic linked to there any more sad.gif .


No I didn't mention 0400 at all, I will then (but don't know when). I've redone (clean look) the part II Sanny's help page (haven't sent it to Seeman thought), I've still got to redo part I, but I'm busy playing IV...

And now I've got a vga cable so I can play on my pc screen...

My next job is to redo part I for Sanny because it's actually the best place for it (active link to scm documentation, no need to print to keep animations, highlighted code both in code and text, accessible offline).


Have fun



gtasbigfoot
  • gtasbigfoot

    平和クールです

  • Members
  • Joined: 01 Jan 2008

#28

Posted 27 May 2008 - 09:12 PM

Nice,i like these tuts.

when you redo it can you bring opcode 09C7: into the tut,i think it's the most unknown opcode (not sure) but it's good.


tomworld10
  • tomworld10

    Mark Chump

  • Members
  • Joined: 29 Jun 2005

#29

Posted 29 May 2008 - 05:21 PM



Hi,

This version have been updated, and since the Bible is getting older there no need for off the history of the bible to be put at front.

So for the record it's here :
QUOTE (tomworld10 @ Nov 14 2006 @ 21:31)
Hi,


First a little introduction, this tutorial could have never happened, as I said in Back to Reality topic  I spelled a glass of beer on my laptop computer and the only copy of this tutorial (in this actual state) was in it...
It was f*cked, 10 minutes after this happened, I tried the hard drive separatly (with an adaptor I've bought a while ago) and it didn't work....
Yesterday I was on Convar website looking for sending them my hard drive so they can get my data back, and at the time they ask for my credit card number, I thought let's give it a last try...

And this bloody little c*nt DID work !!!!!!!!!!!!!! I was crazy and I thought before anything happend again, I'll post it even if it's not finished.

Comments, crittics, modifying propositions are more than welcome they are REQUIRED !!!!!!!!!!!!! As well many things are not done yet, and it's been about a month I havn't had a look at it. Credits are not done yet as well and I know it's a very important part. As part I and II are mostly information I'll make part III which will be a real tutorial where you do things not just read and learn.

And I know "Coding bible" is really a lot, way too much prentious, but as the old (part I) and the new Testament (part II) are only informations and as it's pretty hudge I thought it would be a pretty good and original name for it. If you wonder what alternative name I thought for part III you'll get the answer right away : the Apocryphal book...



Have fun


Deji
  • Deji

    Coding like a Rockstar!

  • Feroci
  • Joined: 24 Dec 2007
  • None
  • Contribution Award [Mods]

#30

Posted 15 October 2008 - 10:50 PM

QUOTE (tomworld10 @ Feb 11 2007, 18:20)
@everyone : The bible is slowly growing up, chapter 7.Objects and moving them is finished, chapter 8.Animations and particules is about half way done, but isn't that hard to complete. I'm getting afraid of chapter 9.Animating vehicles and car mods,because I'm not very good at driving behaviour and all such things, no trouble with the rest of the chapter, but driving behaviour, follow paths and those things will need a lot of research and testing...
So any help from you guys will be truly appreciated !!!!! Don't put yourself in a hurry, but just keep it in mind and when you have the time, just post here. Thank you all in advance for this.

I have to say, you are my hero! After reading your tutorial I went mod crazy! I got about 6 mods out or in progress and I've only known to code for 2 weeks!

Your tutorial as it is taught me much more than what was there so maybe I can help you complete the bits I know? Particles are pretty simple and I used them in my 'Fun Mod' where CJ can smoke and pee tounge2.gif

I also feel that the '13. Maths, stats and timers : ' should come much sooner... It's quite important if you want to control a players money, health ect...

Basically, I want to be able to help with the things I do know, then you can do the things I don't and I can learn tounge.gif I know alot thats to be added anyway and driving behaviour I can handle. I used it for the drive-by part of my fun mod wink.gif Following paths is easy for me too, with both the follow_roads thing and the scmpath is pretty simple. I've not really done many missions, I'm just starting my first and have so far made the cut-scene (Which is a bit buggy atm)

If not, thanks anyway for making the excellent tutorial which taught me so much. Cant wait until you finish the missions part tounge2.gif Especially since I'm stuck in my cut-scene at simply putting the camera's position (I've already done it, yet it stays behind the player)

I just wish I coulda helped with the animations bit. I love activating anims and use them in nearly every mod I make!




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users