Difference between revisions of "Spawn a ped"

From GTAMods Wiki
Jump to navigation Jump to search
(External link)
m (External links: better site)
Line 75: Line 75:
  
 
==External links==
 
==External links==
*{{Icon|3}} [http://spaceeinstein.wikispaces.com/List+of+peds+%28GTA+3%29 Screenshots of all ped models in GTA III]
+
*{{Icon|3}} [http://spaceeinstein.webs.com/Peds_3.html Screenshots of all ped models in GTA III]
 
*{{Icon|VC}} [http://public.sannybuilder.com/vc_actors/ Screenshots of all available ped models in Vice City]
 
*{{Icon|VC}} [http://public.sannybuilder.com/vc_actors/ Screenshots of all available ped models in Vice City]
  
 
[[Category:Mission Scripting]]
 
[[Category:Mission Scripting]]

Revision as of 22:55, 17 April 2010

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 3 and Vice City.

Create your thread

First, learn how to create a thread. Create an example thread:

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

Load your model

It is very important to load the model of your ped. You can find a list of all peds available to use in the default.ide file for GTA 3 and Vice City or the peds.ide file for San Andreas. Use opcode 0247 or the command Model.Load to load your ped model. The script normally uses the ped's ID number but Sanny Builder support using the ped's model name. Let's try the first ped in the list, BFORI.

 0247: load_model #BFORI

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

Check if the model is loaded

Next, you have to check if the model is loaded using an 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.

 :CheckModel
 0001: wait 0 ms
 00D6: if
 0248:   model #BFORI available
 004D: jump_if_false @CheckModel

Create your ped

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 for San Andreas. 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 (usually CJ).

 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.

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

 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.

Example

 :LoadModel
 Model.Load(#BFORI)
 Model.Load(#COLT45)
 
 :CheckModel
 wait 0 ms
 if and
 Model.Available(#BFORI)
 Model.Available(#COLT45)
 else_jump @CheckModel
 Actor.Create(0@, 4, #BFORI, 0.0, 0.0, 0.0)
 Model.Destroy(#BFORI)
 Model.Destroy(#COLT45)
 01B2: give_actor 0@ weapon 22 ammo 100
 Actor.Angle(0@) = 90.0
 01C9: actor 0@ kill_actor $PLAYER_ACTOR
 end_thread

External links