Difference between revisions of "Create a mission"

From GTAMods Wiki
Jump to navigation Jump to search
(CLEO Mission)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
Creating a mission is tough. It is recommended that you start practicing with [[Create_a_thread|simple threads]] and work your way up instead of attempting to create a mission right away. There are many ways to create a mission so to simplify this for beginners, the rest of the article will show the basic structure of creating a working mission. The format uses [[Sanny Builder]] and should work for GTA III, Vice City, and San Andreas.
+
This tutorial will show you the basic steps on how to '''create a simple mission''' in the <code>[[main.scm]]</code> using the latest version of [[Sanny Builder]]. This tutorial applies to [[GTA III]], [[Vice City]], and [[San Andreas]]. This tutorial assumes that you know how to [[Create a thread|create simple scripts]] so it is recommended that you start practicing with them before attempting to create a mission. There are many ways to create a mission so to simplify this for beginners, the rest of the article will show the basic structure of creating a working mission.
  
 
== Define your mission ==
 
== Define your mission ==
First define your mission. Find
+
First define your mission. Find:
<source lang="scm">DEFINE MISSIONS</source>
+
<syntaxhighlight lang="scm">DEFINE MISSIONS</syntaxhighlight>
 
Increment that number by one. Scroll down until you see the last defined mission. Define your mission below it.
 
Increment that number by one. Scroll down until you see the last defined mission. Define your mission below it.
<source lang="scm">DEFINE MISSION {xxx} AT @MissionStart</source>
+
<syntaxhighlight lang="scm">DEFINE MISSION {xxx} AT @simple_mission</syntaxhighlight>
 
where {xxx} is the mission index, one more from the previous mission.
 
where {xxx} is the mission index, one more from the previous mission.
  
==Insert your trigger==
+
== Insert your trigger ==
Next create a thread that will trigger your mission to start. Find
+
Next create a script that will trigger your mission to start. Find:
<source lang="scm">create_thread</source>
+
<syntaxhighlight lang="scm">create_thread</syntaxhighlight>
Insert before it
+
Insert before it:
{| style="margin-right:auto"
+
<syntaxhighlight lang="scm">004F: create_thread @mission_trigger</syntaxhighlight>
| width="500px" | <source lang="scm">
 
004F: create_thread @MissionTrigger
 
</source>
 
| width="100px" style="text-align:center" | or
 
| width="500px" | <source lang="scm">
 
create_thread @MissionTrigger
 
</source>
 
|}
 
  
Find
+
Find:
<source lang="scm">//-------------Mission 0---------------</source>
+
<syntaxhighlight lang="scm">//-------------Mission 0---------------</syntaxhighlight>
That is where the MAIN section ends and the first mission begins. Insert your trigger between that.
+
That is where the MAIN section ends and the first mission begins. Insert your trigger code between that:
{| style="margin-right:auto"
+
<syntaxhighlight lang="scm">:mission_trigger
| width="500px" | <source lang="scm">
 
:MissionTrigger
 
0001: wait 0 ms
 
00D6: if
 
0256:  player $PLAYER_CHAR defined
 
004D: jump_if_false @MissionTriggerEnd
 
00D6: if
 
0038:  $ONMISSION == 0
 
004D: jump_if_false @MissionTriggerEnd
 
00D6: if
 
// Place your condition to start your mission
 
004D: jump_if_false @MissionTriggerEnd
 
0417: start_mission {xxx}
 
0004: $ONMISSION = 1
 
 
 
:MissionTriggerEnd
 
0002: jump @MissionTrigger
 
</source>
 
| width="100px" style="text-align:center" | or
 
| width="500px" | <source lang="scm">
 
:MissionTrigger
 
 
while true
 
while true
     wait 0
+
     0001: wait 0
 
     if
 
     if
 
         0256:  player $PLAYER_CHAR defined
 
         0256:  player $PLAYER_CHAR defined
Line 58: Line 29:
 
                 // Condition to start your mission
 
                 // Condition to start your mission
 
             then
 
             then
                 start_mission {xxx}
+
                 0417: start_mission {xxx}
 
                 $ONMISSION = 1
 
                 $ONMISSION = 1
 
             end
 
             end
 
         end
 
         end
 
     end
 
     end
end
+
end</syntaxhighlight>
</source>
 
|}
 
 
where {xxx} is your mission index or the label of your mission.
 
where {xxx} is your mission index or the label of your mission.
  
==Insert your mission==
+
== Insert your mission ==
Last insert your mission. If you are using GTA3 or Vice City, scroll all the way to the end of the file to insert your mission. If you are using San Andreas, find
+
Lastly insert your mission. If you are using GTA III or Vice City, scroll all the way to the end of the file to insert your mission. If you are using San Andreas, find
<source lang="scm">//-------------External script 0 (PLAYER_PARACHUTE)---------------</source>
+
<syntaxhighlight lang="scm" style="overflow: auto;">//-------------External script 0 (PLAYER_PARACHUTE)---------------</syntaxhighlight>
That is where the last mission ends and the first external scrpt starts. Insert your mission between that.
+
That is where the last mission ends and the first external script starts. Insert your mission between that:
{| style="margin-right:auto"
+
<syntaxhighlight lang="scm">:simple_mission
| width="600px" | <source lang="scm">
+
03A4: name_thread 'MISSA'
:MissionStart
+
0050: gosub @simple_mission_begin
03A4: name_thread 'NAME'
 
0050: gosub @MissionBegin
 
00D6: if
 
0112:  wasted_or_busted
 
004D: jump_if_false @MissionEnd
 
0050: gosub @MissionFailed
 
 
 
:MissionEnd
 
0050: gosub @MissionCleanup
 
004E: end_thread
 
 
 
:MissionBegin
 
// This section is where you place the contents of your mission
 
0051: return
 
 
 
:MissionFailed
 
// This section is what happens after you died or got busted during your mission
 
0051: return
 
 
 
:MissionCleanup
 
// This section is where you clean up the contents of your mission so you can end it
 
0004: $ONMISSION = 0
 
00D8: mission_cleanup
 
0051: return
 
</source>
 
| width="100px" style="text-align:center" | or
 
| width="500px" | <source lang="scm">
 
:MissionStart
 
thread 'NAME'
 
gosub @MissionBegin
 
 
if
 
if
     wasted_or_busted
+
     0112:  wasted_or_busted
 
then
 
then
     gosub @MissionFailed
+
     0050: gosub @simple_mission_failed
 
end
 
end
gosub @MissionCleanup
+
0050: gosub @simple_mission_cleanup
end_thread
+
004E: end_thread
  
:MissionBegin
+
:simple_mission_begin
 
// Place the contents of your mission
 
// Place the contents of your mission
return
+
0051: return
  
:MissionFailed
+
:simple_mission_failed
 
// Died or got busted during your mission
 
// Died or got busted during your mission
return
+
0051: return
  
:MissionCleanup
+
:simple_mission_cleanup
 
// Clean up the contents of your mission so you can end it
 
// Clean up the contents of your mission so you can end it
 
$ONMISSION = 0
 
$ONMISSION = 0
mission_cleanup
+
00D8: mission_cleanup
return
+
0051: return</syntaxhighlight>
</source>
+
This structure is required to allow the mission to end when you get wasted or busted while the mission is running.
|}
+
 
 +
== Save your changes ==
 +
Finally, after you have finished all the necessary changes, compile the file you are working on. As usual, in order to play the game with the modification, you must start a new game or else the game can crash. Check out the [http://gtaforums.com/forum/109-tutorials/ Tutorial Forum] for more in-depth tutorials or the [http://gtaforums.com/forum/317-coding/ Mission Coding Forum] for further help on coding.
  
 
==CLEO Mission==
 
==CLEO Mission==
Line 139: Line 80:
 
It contains some conditions and if they are true the mission is eventually triggered.  
 
It contains some conditions and if they are true the mission is eventually triggered.  
 
<source lang="scm">
 
<source lang="scm">
{CLEO .cs}
+
{$CLEO .cs}
  
 
0000: NOP
 
0000: NOP
Line 164: Line 105:
 
'''Mission Script'''
 
'''Mission Script'''
 
<source lang="scm">
 
<source lang="scm">
{CLEO .cm}
+
{$CLEO .cm}
  
 
:MissionStart
 
:MissionStart
Line 191: Line 132:
 
return
 
return
 
</source>
 
</source>
'''{CLEO .cm}'''
+
'''{$CLEO .cm}'''
 
: This CLEO directive is used because we want the file to be compiled as a CLEO Mission(.cm).
 
: This CLEO directive is used because we want the file to be compiled as a CLEO Mission(.cm).
 
Also in a .cm script you can use up to 1022 + 2 timers local variables instead of 32 + 2 timers.<br>
 
Also in a .cm script you can use up to 1022 + 2 timers local variables instead of 32 + 2 timers.<br>
Line 197: Line 138:
 
: In order to end a CLEO mission script you have to use '''004E: end_thread''' instead of '''0A93: end_custom_thread''' which is used in normal CLEO scripts.
 
: In order to end a CLEO mission script you have to use '''004E: end_thread''' instead of '''0A93: end_custom_thread''' which is used in normal CLEO scripts.
  
==Final note==
 
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.
 
 
== External Links ==
 
== External Links ==
 
* {{GTAF|section|109|Tutorial Forum}}
 
* {{GTAF|section|109|Tutorial Forum}}

Latest revision as of 07:44, 22 July 2015

This tutorial will show you the basic steps on how to create a simple mission in the main.scm using the latest version of Sanny Builder. This tutorial applies to GTA III, Vice City, and San Andreas. This tutorial assumes that you know how to create simple scripts so it is recommended that you start practicing with them before attempting to create a mission. There are many ways to create a mission so to simplify this for beginners, the rest of the article will show the basic structure of creating a working mission.

Define your mission

First define your mission. Find:

DEFINE MISSIONS

Increment that number by one. Scroll down until you see the last defined mission. Define your mission below it.

DEFINE MISSION {xxx} AT @simple_mission

where {xxx} is the mission index, one more from the previous mission.

Insert your trigger

Next create a script that will trigger your mission to start. Find:

create_thread

Insert before it:

004F: create_thread @mission_trigger

Find:

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

That is where the MAIN section ends and the first mission begins. Insert your trigger code between that:

:mission_trigger
while true
    0001: wait 0
    if
        0256:   player $PLAYER_CHAR defined
    then
        if
            $ONMISSION == 0
        then
            if
                // Condition to start your mission
            then
                0417: start_mission {xxx}
                $ONMISSION = 1
            end
        end
    end
end

where {xxx} is your mission index or the label of your mission.

Insert your mission

Lastly insert your mission. If you are using GTA III or Vice City, scroll all the way to the end of the file to insert your mission. If you are using San Andreas, find

//-------------External script 0 (PLAYER_PARACHUTE)---------------

That is where the last mission ends and the first external script starts. Insert your mission between that:

:simple_mission
03A4: name_thread 'MISSA'
0050: gosub @simple_mission_begin
if
    0112:   wasted_or_busted
then
    0050: gosub @simple_mission_failed
end
0050: gosub @simple_mission_cleanup
004E: end_thread

:simple_mission_begin
// Place the contents of your mission
0051: return

:simple_mission_failed
// Died or got busted during your mission
0051: return

:simple_mission_cleanup
// Clean up the contents of your mission so you can end it
$ONMISSION = 0
00D8: mission_cleanup
0051: return

This structure is required to allow the mission to end when you get wasted or busted while the mission is running.

Save your changes

Finally, after you have finished all the necessary changes, compile the file you are working on. As usual, in order to play the game with the modification, you must start a new game or else the game can crash. Check out the Tutorial Forum for more in-depth tutorials or the Mission Coding Forum for further help on coding.

CLEO Mission

First of all, in order to make a CLEO mission two files are required: A .cs file which will trigger the mission this file usually includes conditions. Also, you need a .cm file which contains the code of the mission.

Example

Mission Trigger

It contains some conditions and if they are true the mission is eventually triggered.

{$CLEO .cs}

0000: NOP

while true
    wait 0
    if and
      $ONMISSION == 0
      player.defined(0)
    then
        if 
          // your conditions
        then
            0004: $ONMISSION =  1  
            0A94: start_custom_mission "MyMission"
        end
    end
end

Firstly, this script checks if the player is on a mission and if he is defined. Finally if your conditions are true too the mission script is triggered.

0A94: start_custom_mission "MyMission"

0A94 is used to start the mission the parameter must match to the mission name without the .cm extension because the opcode will search for the file with the extension .cm. The parameter can also contain the directory of the file (starting from game\CLEO) example "Missions\MyMission".

Mission Script

{$CLEO .cm}

:MissionStart
03A4: name_thread "TEST"  
gosub @MissionBegin
if
    wasted_or_busted
then
    gosub @MissionFailed
end
gosub @MissionCleanup
end_thread
 
:MissionBegin
// Place the contents of your mission
return
 
:MissionFailed
// Died or got busted during your mission
return
 
:MissionCleanup
// Clean up the contents of your mission so you can end it
$ONMISSION = 0
mission_cleanup
return

{$CLEO .cm}

This CLEO directive is used because we want the file to be compiled as a CLEO Mission(.cm).

Also in a .cm script you can use up to 1022 + 2 timers local variables instead of 32 + 2 timers.
NOTE

In order to end a CLEO mission script you have to use 004E: end_thread instead of 0A93: end_custom_thread which is used in normal CLEO scripts.

External Links