Difference between revisions of "Spawn a ped"

From GTAMods Wiki
Jump to navigation Jump to search
(Check if the model is loaded)
(tutorial update)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
'''Spawning a ped''' (also called ''character'' or ''actor'') is not as simple as inserting one line. There are steps that need to be taken in order to successfully spawn a ped. This tutorial will show you the basic steps of spawning a ped using a format used in [[Sanny Builder]]. These examples are for [[San Andreas]] but with minor tweaks can be used for [[GTA III]] and [[Vice City]].
 
'''Spawning a ped''' (also called ''character'' or ''actor'') is not as simple as inserting one line. There are steps that need to be taken in order to successfully spawn a ped. This tutorial will show you the basic steps of spawning a ped using a format used in [[Sanny Builder]]. These examples are for [[San Andreas]] but with minor tweaks can be used for [[GTA III]] and [[Vice City]].
  
==Create your thread==
+
== Create your script ==
First, [[create a thread]]. Here is an example:
+
First, [[create a script]]. Here is an example:
{| style="margin:right"
+
 
| width="500px" | <source lang="scm">
+
<syntaxhighlight lang="scm">
004F: create_thread @LoadModel
+
004F: create_thread @spawn_ped
</source>
+
</syntaxhighlight>
<source lang="scm">
+
 
:LoadModel
+
<syntaxhighlight lang="scm">
 +
:spawn_ped
 
// add code from tutorial here
 
// add code from tutorial here
 
004E: end_thread
 
004E: end_thread
</source>
+
</syntaxhighlight>
| width="100px" style="text-align:left" | or
+
 
| width="500px" | <source lang="scm">
+
== Load your model ==
create_thread @LoadModel
+
It is very important that the model of your ped has been loaded into the game. If your create a ped with an unavailable model, the game will crash. You can find a list of all peds available to use in the [[default.ide]] file for GTA III and Vice City or the [[peds.ide]] file for San Andreas. The script uses the ped's IDE number but Sanny Builder supports using the ped's model name with a hash character. Let's try the first ped in the list, BFORI.
</source>
 
<source lang="scm">
 
:LoadModel
 
// add code from tutorial here
 
end_thread
 
</source>
 
|}
 
  
==Request your model==
+
<syntaxhighlight lang="scm">
It is very important to request the model of your ped. You can find a list of all peds available to use in the [[default.ide]] file for GTA III and Vice City or the [[peds.ide]] file for San Andreas. Use opcode [[0247]] or the command ''Model.Load'' to request your ped model. The script normally uses the ped's ID number but Sanny Builder support using the ped's model name with a hash character. Let's try the first ped in the list, BFORI.
+
0247: request_model #BFORI
{| style="margin:right"
+
038B: load_requested_models
| width="500px" | <source lang="scm">
+
</syntaxhighlight>
0247: load_model #BFORI
 
</source>
 
| width="100px" style="text-align:left" | or
 
| width="500px" | <source lang="scm">
 
Model.Load #BFORI
 
</source>
 
|}
 
  
There are some ped-spawning opcodes that do not need the ped's model to be loaded. See [[Spawn a ped#Other opcodes|below]] for more information.
+
An alternative way to load the models involves more code but the game would not pause for the models to load like the code above. It uses an [[Create a thread#Conditions|IF statement]] with the conditional opcode [[0248]].
  
==Check if the model is loaded==
+
<syntaxhighlight lang="scm">
Next, you have to check if the model is loaded using an [[Create a thread#Conditions|IF statement]] with the conditional opcode [[0248]] or the command ''Model.Available''. If your create a ped with an unavailable model, the game will crash.
 
{| style="margin:right"
 
| width="500px" | <source lang="scm">
 
 
repeat
 
repeat
 
     wait 0 ms
 
     wait 0 ms
Line 49: Line 33:
 
     end
 
     end
 
until false
 
until false
</source>
+
</syntaxhighlight>
| width="100px" style="text-align:left" | or
+
 
| width="500px" | <source lang="scm">
+
There are some ped-spawning opcodes that do not require the ped's model to be explicitly loaded. See [[#Other opcodes|below]] for more information.
repeat
 
    wait 0
 
    if
 
        Model.Available(#BFORI)
 
    then
 
        break
 
    end
 
until false
 
</source>
 
|}
 
Alternatively, this check can be bypassed entirely if opcode [[038B]] is used after the models are requested, but the simplicity in coding requires trading off some hiccups to the game as the models are streamed.
 
  
Below you can find the code that the game uses to check if a model is loaded.
+
== Create your ped ==
<source lang="scm">
+
Now you can use the primary opcode to create a ped: [[009A]]. The opcode includes the ped's [[pedtype]] and the coordinate to spawn the ped. Sanny Builder has a built-in coordinates tool. Go to ''Tools>IDE Tools>Coords manager...'' or use the shortcut ''Ctrl+Alt+1'' while the game is running. This will show the current position of your player character.
while 8248:  not model #BFORI available
 
    wait 0
 
end
 
</source>
 
  
==Create your ped==
+
<syntaxhighlight lang="scm">
Now you can use the main opcode to create a ped: [[009A]], or the command ''Actor.Create''. The opcode includes the ped's [[pedtype]] and the coordinate to spawn the ped. Sanny Builder has a built-in coordinates tool. Go to ''Tools>IDE Tools>Coords manager...'' or use the shortcut ''Ctrl+Alt+1'' while the game is running. This will show the current position of your player character.
 
{| style="margin:right"
 
| width="500px" | <source lang="scm">
 
 
009A: 0@ = create_actor_pedtype 4 model #BFORI at 0.0 0.0 0.0
 
009A: 0@ = create_actor_pedtype 4 model #BFORI at 0.0 0.0 0.0
</source>
+
</syntaxhighlight>
| width="100px" style="text-align:left" | or
 
| width="500px" | <source lang="scm">
 
Actor.Create(0@, 4, #BFORI, 0.0, 0.0, 0.0)
 
</source>
 
|}
 
  
===Other opcodes===
+
=== Other opcodes ===
 
There are other opcodes that also spawn a ped in different situations, including:
 
There are other opcodes that also spawn a ped in different situations, including:
{| {{prettytable}}
+
 
|
+
* [[0129]], creates a ped as a driver in a vehicle.
{| cellspacing="0" cellpadding="0" class="collapsible collapsed"
+
* [[01C8]], creates a ped as a passenger in a vehicle.
| [[0129]]: || style="padding-left:4px" | Creates a ped as a driver in a vehicle.
+
 
! &nbsp;
 
|-
 
| || colspan=2 style="padding-left:4px" | {{:0129|transcludesection=opcode}}
 
|}
 
|-
 
|
 
{| cellspacing="0" cellpadding="0" class="collapsible collapsed"
 
| [[01C8]]: || style="padding-left:4px" | Creates a ped as a passenger in a vehicle.
 
! &nbsp;
 
|-
 
| || colspan=2 style="padding-left:4px" | {{:01C8|transcludesection=opcode}}
 
|}
 
|}
 
 
There are opcodes that can spawn a random ped without the need to request the model of the ped.
 
There are opcodes that can spawn a random ped without the need to request the model of the ped.
{| {{prettytable}}
+
* [[0376]], creates a random ped.
| [[0376]]: Creates a random ped.
+
* [[0560]], creates a random ped as a driver in a vehicle.
|-
+
* [[0561]], creates a random ped as a passenger in a vehicle.
| [[0560]]: Creates a random ped as a driver in a vehicle.
 
|-
 
| [[0561]]: Creates a random ped as a passenger in a vehicle.
 
|}
 
  
===Pedtype limitation===
+
=== Ped type limitation ===
 
Some pedtypes are limited to be compatible to specific models or else the game may crash.
 
Some pedtypes are limited to be compatible to specific models or else the game may crash.
 
*Pedtype 6 can only be used with models between 0 and 4 (<span style="color:maroon"><b>#null</b></span>, <span style="color:maroon"><b>#cop</b></span>, <span style="color:maroon"><b>#swat</b></span>, <span style="color:maroon"><b>#fbi</b></span>, <span style="color:maroon"><b>#army</b></span>).
 
*Pedtype 6 can only be used with models between 0 and 4 (<span style="color:maroon"><b>#null</b></span>, <span style="color:maroon"><b>#cop</b></span>, <span style="color:maroon"><b>#swat</b></span>, <span style="color:maroon"><b>#fbi</b></span>, <span style="color:maroon"><b>#army</b></span>).
Line 118: Line 62:
  
 
==Release your model==
 
==Release your model==
After the ped is created and the model is no longer needed, release it using opcode [[0249]] or the command ''Model.Destroy''
+
After the ped is created and the model is no longer needed, release it using opcode [[0249]].
{| style="margin:right"
+
 
| width="500px" | <source lang="scm">
+
<syntaxhighlight lang="scm">
 
0249: release_model #BFORI
 
0249: release_model #BFORI
</source>
+
</syntaxhighlight>
| width="100px" style="text-align:left" | or
 
| width="500px" | <source lang="scm">
 
Model.Destroy(#BFORI)
 
</source>
 
|}
 
  
 
==Set your ped==
 
==Set your ped==
You can now add settings and attributes to your ped, like rotating your ped or adding animations to your ped. The [[variable]] <span style="color:blue">0@</span> is the handle of your ped, like an identifier. Use this variable when using opcodes specific to your ped. You can search these opcodes by using Sanny Builder's Opcode Search Tool. Go to ''Tools>IDE Tools>Opcode Search...'' or use the shortcut ''Ctrl+Alt+2''. Then type ''actor'' in the search box to find a list of named opcodes related to it.
+
You can now add settings and attributes to your ped, like rotating your ped or adding animations to your ped. The [[variable]] <span style="color:blue">0@</span> is the handle of your ped, like an identifier. Use this variable when using opcodes specific to your ped. You can search these opcodes by using Sanny Builder's Opcode Search Tool. Go to ''Tools>IDE Tools>Opcode Search...'' or use the shortcut ''Ctrl+Alt+2''. Then type ''actor'' in the search box to find a list of named opcodes related to it. When you no longer need the ped, mark it as no longer needed using opcode [[01C2]] so that the game can remove the ped for you.
  
 
==Full example==
 
==Full example==
<source lang="scm">
+
<syntaxhighlight lang="scm">
 +
:spawn_ped
 
// load model, required to prevent unnecessary crash!
 
// load model, required to prevent unnecessary crash!
 
0247: request_model #BFORI
 
0247: request_model #BFORI
// check if model is loaded
+
038B: load_requested_models
repeat
 
    wait 0
 
    if
 
        0248:   model #BFORI available
 
    then
 
        break
 
    end
 
until false
 
 
// spawn character
 
// spawn character
 
009A: 0@ = create_actor 4 #BFORI at 0.0 0.0 0.0
 
009A: 0@ = create_actor 4 #BFORI at 0.0 0.0 0.0
 
// cleanup
 
// cleanup
 
0249: release_model #BFORI
 
0249: release_model #BFORI
</source>
+
01C2: mark_actor_as_no_longer_needed 0@
 +
004E: end_thread
 +
</syntaxhighlight>
  
 
==External links==
 
==External links==
*{{Icon|3}} [http://spaceeinstein.altervista.org/peds_3.htm Screenshots of all ped models in GTA III]
+
*{{Icon|3}} [http://spaceeinstein.altervista.org/peds_3.php Screenshots of all ped models in GTA III]
*{{Icon|VC}} [http://spaceeinstein.altervista.org/peds_vc.htm Screenshots of all ped models in Vice City]
+
*{{Icon|VC}} [http://spaceeinstein.altervista.org/peds_vc.php Screenshots of all ped models in Vice City]
  
 
[[Category:Mission Scripting]]
 
[[Category:Mission Scripting]]

Latest revision as of 04:49, 27 January 2016

Spawning a ped (also called character or actor) is not as simple as inserting one line. There are steps that need to be taken in order to successfully spawn a ped. This tutorial will show you the basic steps of spawning a ped using a format used in Sanny Builder. These examples are for San Andreas but with minor tweaks can be used for GTA III and Vice City.

Create your script

First, create a script. Here is an example:

004F: create_thread @spawn_ped
:spawn_ped
// add code from tutorial here
004E: end_thread

Load your model

It is very important that the model of your ped has been loaded into the game. If your create a ped with an unavailable model, the game will crash. You can find a list of all peds available to use in the default.ide file for GTA III and Vice City or the peds.ide file for San Andreas. The script uses the ped's IDE number but Sanny Builder supports using the ped's model name with a hash character. Let's try the first ped in the list, BFORI.

0247: request_model #BFORI
038B: load_requested_models

An alternative way to load the models involves more code but the game would not pause for the models to load like the code above. It uses an IF statement with the conditional opcode 0248.

repeat
    wait 0 ms
    if
        0248:   model #BFORI available
    then
        break
    end
until false

There are some ped-spawning opcodes that do not require the ped's model to be explicitly loaded. See below for more information.

Create your ped

Now you can use the primary opcode to create a ped: 009A. The opcode includes the ped's pedtype and the coordinate to spawn the ped. Sanny Builder has a built-in coordinates tool. Go to Tools>IDE Tools>Coords manager... or use the shortcut Ctrl+Alt+1 while the game is running. This will show the current position of your player character.

009A: 0@ = create_actor_pedtype 4 model #BFORI at 0.0 0.0 0.0

Other opcodes

There are other opcodes that also spawn a ped in different situations, including:

  • 0129, creates a ped as a driver in a vehicle.
  • 01C8, creates a ped as a passenger in a vehicle.

There are opcodes that can spawn a random ped without the need to request the model of the ped.

  • 0376, creates a random ped.
  • 0560, creates a random ped as a driver in a vehicle.
  • 0561, creates a random ped as a passenger in a vehicle.

Ped type limitation

Some pedtypes are limited to be compatible to specific models or else the game may crash.

  • Pedtype 6 can only be used with models between 0 and 4 (#null, #cop, #swat, #fbi, #army).
  • Pedtype 16 can only be used with model 5 (#medic).
  • Pedtype 17 can only be used with model 6 (#fireman).

Release your model

After the ped is created and the model is no longer needed, release it using opcode 0249.

0249: release_model #BFORI

Set your ped

You can now add settings and attributes to your ped, like rotating your ped or adding animations to your ped. The variable 0@ is the handle of your ped, like an identifier. Use this variable when using opcodes specific to your ped. You can search these opcodes by using Sanny Builder's Opcode Search Tool. Go to Tools>IDE Tools>Opcode Search... or use the shortcut Ctrl+Alt+2. Then type actor in the search box to find a list of named opcodes related to it. When you no longer need the ped, mark it as no longer needed using opcode 01C2 so that the game can remove the ped for you.

Full example

:spawn_ped
// load model, required to prevent unnecessary crash!
0247: request_model #BFORI
038B: load_requested_models
// spawn character
009A: 0@ = create_actor 4 #BFORI at 0.0 0.0 0.0
// cleanup
0249: release_model #BFORI
01C2: mark_actor_as_no_longer_needed 0@
004E: end_thread

External links