Create a Script: Difference between revisions

m
no edit summary
m (Spaceeinstein moved page Create a thread to Create a Script)
mNo edit summary
 
Line 15: Line 15:


That is where the MAIN section ends and the first mission begins. Insert your script between it. The simplest scripts have this format:
That is where the MAIN section ends and the first mission begins. Insert your script between it. The simplest scripts have this format:
<pre>
{{Pre|
:simple_script
:simple_script
// Insert your code here
// Insert your code here
004E: end_thread
004E: end_thread
</pre>
}}


Your script can include a series of opcodes like adding cash to you or setting your wanted level:
Your script can include a series of opcodes like adding cash to you or setting your wanted level:
<pre>
{{Pre|1=
:simple_script
:simple_script
0109: player $PLAYER_CHAR money += 1000
0109: player $PLAYER_CHAR money += 1000
010D: set_player $PLAYER_CHAR wanted_level_to 6
010D: set_player $PLAYER_CHAR wanted_level_to 6
004E: end_thread
004E: end_thread
</pre>
}}


More complex code can be placed there instead, including spawning a ped, creating a clothes pickup, or creating a moving gate.
More complex code can be placed there instead, including spawning a ped, creating a clothes pickup, or creating a moving gate.


Your script can have an optional name with which the game can identify by using opcode 03A4. A maximum of 7 characters are allowed for the name. If needed, through different scripts you can end your script with opcode 0459.
Your script can have an optional name with which the game can identify by using opcode 03A4. A maximum of 7 characters are allowed for the name. If needed, through different scripts you can end your script with opcode 0459.
<pre>
{{Pre|
:simple_script
:simple_script
03A4: name_thread 'SCRIPTA'
03A4: name_thread 'SCRIPTA'
Line 39: Line 39:
// Insert your code here
// Insert your code here
004E: end_thread
004E: end_thread
</pre>
}}


== Loops ==
== Loops ==
The example above shows you a script that ends immediately. If you want your script to run continuously, you have insert a loop. For most cases, looping 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 script that ends immediately. If you want your script to run continuously, you have insert a loop. For most cases, looping 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:
<pre>
{{Pre|
:simple_script
:simple_script
while true
while true
Line 49: Line 49:
     // Insert your code here
     // Insert your code here
end
end
</pre>
}}


This script will repeat itself indefinitely so be careful what you put in it. In older or decompiled scripts, you may see this format:
This script will repeat itself indefinitely so be careful what you put in it. In older or decompiled scripts, you may see this format:
<pre>
{{Pre|
:simple_script
:simple_script
0001: wait 0 ms
0001: wait 0 ms
// Insert your code here
// Insert your code here
0002: jump @simple_script
0002: jump @simple_script
</pre>
}}


This style is lower level and behaves equivalently to the prior example script.
This style is lower level and behaves equivalently to the prior example script.
Line 63: Line 63:
== Conditions ==
== Conditions ==
Conditional opcodes are used to check whether the action is performed rather than to perform the action. If the condition is satisfied, it returns true, otherwise it returns false. In Sanny Builder, conditional opcodes 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 are used to check whether the action is performed rather than to perform the action. If the condition is satisfied, it returns true, otherwise it returns false. In Sanny Builder, conditional opcodes 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.
<pre>
{{Pre|1=
:simple_script
:simple_script
while true
while true
Line 78: Line 78:
     end
     end
end
end
</pre>
}}


In older or decompiled scripts, you may see this format:
In older or decompiled scripts, you may see this format:
<pre>
{{Pre|1=
:simple_script
:simple_script
0001: wait 100 ms
0001: wait 100 ms
Line 98: Line 98:
:simple_script_end
:simple_script_end
0002: jump @simple_script
0002: jump @simple_script
</pre>
}}


Again, this style is lower level and behaves equivalently to the prior example script. Both of the examples above show if '''one''' condition is met (the CAMERA key is pressed), the condition is true and the first command will be performed (add $2000). Otherwise, the condition would be false and reaches the alternate command (subtract $10). For IF statements with more than one conditions, you need to either add ''and'' or ''or'' after ''if''.
Again, this style is lower level and behaves equivalently to the prior example script. Both of the examples above show if '''one''' condition is met (the CAMERA key is pressed), the condition is true and the first command will be performed (add $2000). Otherwise, the condition would be false and reaches the alternate command (subtract $10). For IF statements with more than one conditions, you need to either add ''and'' or ''or'' after ''if''.


'''if and''' means if all of the conditions are met, then perform the command.
'''if and''' means if all of the conditions are met, then perform the command.
<pre>
{{Pre|
// ...
// ...
if and
if and
Line 112: Line 112:
end
end
// ...
// ...
</pre>
}}


This shows that if '''all''' conditions (if both keys 4 and 19 are pressed in this example) are met, the command will be performed. Otherwise, the code will skip the command and continue onwards.
This shows that if '''all''' conditions (if both keys 4 and 19 are pressed in this example) are met, the command will be performed. Otherwise, the code will skip the command and continue onwards.


'''if or''' means if any one of these conditions are met, then perform the command.
'''if or''' means if any one of these conditions are met, then perform the command.
<pre>
{{Pre|
// ...
// ...
if or
if or
Line 126: Line 126:
end
end
// ...
// ...
</pre>
}}


This shows that if '''either''' condition (if either key 4 or key 19 is pressed in this example) is met, the command will be performed. Otherwise, the code will skip the command and continue onwards.
This shows that if '''either''' condition (if either key 4 or key 19 is pressed in this example) is met, the command will be performed. Otherwise, the code will skip the command and continue onwards.


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.
<pre>
{{Pre|
00E1:  player 0 pressed_key 4 // IS pressed
00E1:  player 0 pressed_key 4 // IS pressed
80E1:  not player 0 pressed_key 4 // is NOT pressed
80E1:  not player 0 pressed_key 4 // is NOT pressed
</pre>
}}


== Save your changes ==
== Save your changes ==
Line 141: Line 141:
== See also ==
== See also ==
* [[Mission Scripting (Overview)]]
* [[Mission Scripting (Overview)]]
* [[Wikipedia:Thread (computer science)|Multithreading theory (Wikipedia)]]
* [[CLEO/Tutorial|CLEO tutorial]]


{{fdl}}
{{3-navi}}
[[Category:Modifications]]
{{VC-navi}}
12,236

edits