Difference between revisions of "Create a script"

From GTAMods Wiki
Jump to navigation Jump to search
m
Line 1: Line 1:
Creating a simple thread is one of the first steps in understanding how to code. This article will show you the basic steps on how to create the simplest thread using [[Sanny Builder]]. It should work for GTA3, Vice City, and San Andreas.
+
'''Creating a simple thread''' is one of the first steps in understanding how to code. This article will show you the basic steps on how to create the simplest thread using [[Sanny Builder]]. It should work for [[GTA 3]], [[Vice City]], and [[San Andreas]].
  
==Create your thread==
+
== Create your thread ==
 
First create your thread using opcode [[004F]] (or ''create_thread'' command). Find
 
First create your thread using opcode [[004F]] (or ''create_thread'' command). Find
 
<source lang="scm">create_thread</source>
 
<source lang="scm">create_thread</source>
Line 8: Line 8:
 
''mythread'' is an arbitrary [[label]]. You can name the label with anything.
 
''mythread'' is an arbitrary [[label]]. You can name the label with anything.
  
==Insert your contents==
+
== Insert your contents ==
 
Next you have to insert the contents into your thread. Find
 
Next you have to insert the contents into your thread. Find
 
<source lang="scm">//-------------Mission 0---------------</source>
 
<source lang="scm">//-------------Mission 0---------------</source>
Line 15: Line 15:
 
// Insert your contents here
 
// Insert your contents here
 
004E: end_thread</source>
 
004E: end_thread</source>
The contents can include simple [[:Category:OpCodes|opcodes]] or longer threads like in the examples of [[009A|creating a ped]] and [[00A5|creating a vehicle]].
+
The contents can include simple [[opcode]]s or longer threads like in the examples of [[009A|creating a ped]] and [[00A5|creating a vehicle]].
  
==Thread names==
+
== Thread names ==
 
Your thread can have a name. Use opcode [[03A4]] to name your thread. It is essential if you need to end your thread from another part of the script with opcode [[0459]].
 
Your thread can have a name. Use opcode [[03A4]] to name your thread. It is essential if you need to end your thread from another part of the script with opcode [[0459]].
  
==Loops==
+
== Loops ==
 
The example above shows you a thread that ends straight away. If you want the thread to run continuously, you have to loop the thread. For the most part, looping the thread requires opcode [[0001]] (or ''wait'' command) to be placed somewhere within the loop or else the game will crash. There are exceptions but it is safer to have it. The simplest loop has this format
 
The example above shows you a thread that ends straight away. If you want the thread to run continuously, you have to loop the thread. For the most part, looping the thread requires opcode [[0001]] (or ''wait'' command) to be placed somewhere within the loop or else the game will crash. There are exceptions but it is safer to have it. The simplest loop has this format
 
<source lang="scm">:mythread
 
<source lang="scm">:mythread
Line 28: Line 28:
 
This thread will repeat itself indefinitely so be careful what you put in it.
 
This thread will repeat itself indefinitely so be careful what you put in it.
  
==Conditions==
+
== Conditions ==
 
Conditional opcodes checks whether the action is performed rather than to perform the action. In Sanny Builder, they are noted by spaces between the opcode and the description of the opcode. Conditions start with IF statements that checks if an action is performed.
 
Conditional opcodes checks whether the action is performed rather than to perform the action. In Sanny Builder, they are noted by spaces between the opcode and the description of the opcode. Conditions start with IF statements that checks if an action is performed.
<source lang="scm">:Cbeck
+
<source lang="scm">:Check
 
0001: wait 0 ms
 
0001: wait 0 ms
 
00D6: if
 
00D6: if
 
// Conditional opcode
 
// Conditional opcode
 +
0256:  player $PLAYER_CHAR defined
 
004D: jump_if_false @CheckEnd
 
004D: jump_if_false @CheckEnd
 
// Command
 
// Command
 
    
 
    
:CbeckEnd
+
:CheckEnd
 
0002: jump @Check</source>
 
0002: jump @Check</source>
 
For IF statements with more than one conditions, you need to either add ''and'' or ''or'' after ''00D6: if''.
 
For IF statements with more than one conditions, you need to either add ''and'' or ''or'' after ''00D6: if''.
  
 
'''if and''' means if all of the conditions are met.
 
'''if and''' means if all of the conditions are met.
<source lang="scm">:Cbeck
+
<source lang="scm">:Check
 
0001: wait 0 ms
 
0001: wait 0 ms
 
00D6: if and
 
00D6: if and
 
// First condition
 
// First condition
 +
00E1:  player 0 pressed_key 4
 
// Second condition
 
// Second condition
 +
00E1:  player 0 pressed_key 19
 
004D: jump_if_false @CheckEnd
 
004D: jump_if_false @CheckEnd
 
// Command
 
// Command
 
    
 
    
:CbeckEnd
+
:CheckEnd
 
0002: jump @Check</source>
 
0002: jump @Check</source>
This means if both the first and second conditions are met, perform the command. Else jump to label ''CheckEnd''.
+
This means if '''both''' the first '''and''' second conditions are met, perform the command. Else jump to label ''CheckEnd''.
  
 
'''if or''' means if either one of these conditions are met.
 
'''if or''' means if either one of these conditions are met.
<source lang="scm">:Cbeck
+
<source lang="scm">:Check
 
0001: wait 0 ms
 
0001: wait 0 ms
 
00D6: if or
 
00D6: if or
 
// First condition
 
// First condition
 +
0118:  actor 0@ dead
 
// Second condition
 
// Second condition
 +
0118:  actor 1@ dead
 
004D: jump_if_false @CheckEnd
 
004D: jump_if_false @CheckEnd
 
// Command
 
// Command
 
    
 
    
:CbeckEnd
+
:CheckEnd
 
0002: jump @Check</source>
 
0002: jump @Check</source>
This means if either the first or the second condition is met, perform the command. Else jump to label ''CheckEnd''.
+
This means if '''either''' the first '''or''' the second condition is met, perform the command. Else jump to label ''CheckEnd''.
  
Opcodes normally starts with the number ''0'', but conditional opcodes can start with the number ''8''. This checks if the condition is NOT performed.
+
Opcodes normally starts with the number ''0'', but conditional opcodes can start with the number ''8''. This checks if the condition is '''NOT''' performed.
 +
<source lang="scm">
 +
0214:  pickup 3@ picked_up // IS picked up
 +
8214:  not pickup 3@ picked_up // is NOT picked up</source>
  
==Final Notes==
+
== Final Notes ==
 
Using this format requires you to start a new game. If you do not understand what is being said here, try looking into the [http://www.gtaforums.com/?showforum=109 Tutorial Forum] for more in-depth tutorials or the [http://www.gtaforums.com/index.php?showforum=49 Mission Coding Forum] on how to understand this.
 
Using this format requires you to start a new game. If you do not understand what is being said here, try looking into the [http://www.gtaforums.com/?showforum=109 Tutorial Forum] for more in-depth tutorials or the [http://www.gtaforums.com/index.php?showforum=49 Mission Coding Forum] on how to understand this.
 +
 +
== See Also ==
 +
* [[Mission Scripting (Overview)]]
  
 
[[Category:Mission Scripting]][[Category:GTA 3]][[Category:GTA VC]]
 
[[Category:Mission Scripting]][[Category:GTA 3]][[Category:GTA VC]]
  
 
{{SA-navi}}
 
{{SA-navi}}

Revision as of 07:46, 24 February 2009

Creating a simple thread is one of the first steps in understanding how to code. This article will show you the basic steps on how to create the simplest thread using Sanny Builder. It should work for GTA 3, Vice City, and San Andreas.

Create your thread

First create your thread using opcode 004F (or create_thread command). Find

create_thread

Insert before it

004F: create_thread @mythread

mythread is an arbitrary label. You can name the label with anything.

Insert your contents

Next you have to insert the contents into your thread. Find

//-------------Mission 0---------------

That is where the MAIN section ends and the first mission begins. Insert your contents between it. The simplest format of a thread have this format

:mythread
// Insert your contents here
004E: end_thread

The contents can include simple opcodes or longer threads like in the examples of creating a ped and creating a vehicle.

Thread names

Your thread can have a name. Use opcode 03A4 to name your thread. It is essential if you need to end your thread from another part of the script with opcode 0459.

Loops

The example above shows you a thread that ends straight away. If you want the thread to run continuously, you have to loop the thread. For the most part, looping the thread requires opcode 0001 (or wait command) to be placed somewhere within the loop or else the game will crash. There are exceptions but it is safer to have it. The simplest loop has this format

:mythread
0001: wait 0 ms
// Insert your contents here
0002: jump @mythread

This thread will repeat itself indefinitely so be careful what you put in it.

Conditions

Conditional opcodes checks whether the action is performed rather than to perform the action. In Sanny Builder, they are noted by spaces between the opcode and the description of the opcode. Conditions start with IF statements that checks if an action is performed.

:Check
0001: wait 0 ms
00D6: if
// Conditional opcode
0256:   player $PLAYER_CHAR defined 
004D: jump_if_false @CheckEnd
// Command
  
:CheckEnd
0002: jump @Check

For IF statements with more than one conditions, you need to either add and or or after 00D6: if.

if and means if all of the conditions are met.

:Check
0001: wait 0 ms
00D6: if and
// First condition
00E1:   player 0 pressed_key 4 
// Second condition
00E1:   player 0 pressed_key 19
004D: jump_if_false @CheckEnd
// Command
  
:CheckEnd
0002: jump @Check

This means if both the first and second conditions are met, perform the command. Else jump to label CheckEnd.

if or means if either one of these conditions are met.

:Check
0001: wait 0 ms
00D6: if or
// First condition
0118:   actor 0@ dead 
// Second condition
0118:   actor 1@ dead 
004D: jump_if_false @CheckEnd
// Command
  
:CheckEnd
0002: jump @Check

This means if either the first or the second condition is met, perform the command. Else jump to label CheckEnd.

Opcodes normally starts with the number 0, but conditional opcodes can start with the number 8. This checks if the condition is NOT performed.

0214:   pickup 3@ picked_up // IS picked up
8214:   not pickup 3@ picked_up // is NOT picked up

Final Notes

Using this format requires you to start a new game. If you do not understand what is being said here, try looking into the Tutorial Forum for more in-depth tutorials or the Mission Coding Forum on how to understand this.

See Also