Difference between revisions of "01B2"

From GTAMods Wiki
Jump to navigation Jump to search
m (Reverted edits by Krasiejow (Talk) to last revision by Spaceeinstein)
(updating page)
Line 1: Line 1:
{{OpCode
+
{{Icon|trilogy}}
| ini        = 01B2=3,%1d% %2d% %3d%
+
<hr />
| description = Gives a weapon to a character
+
'''Description'''
| p1          = Existing actor handle
+
: Gives a weapon to a character
| p2          = [[Weapon]] number
+
'''Syntax'''
| p3          = Ammo
+
: 01B2: give_actor [''char handle''] weapon [''int1''] ammo [''int2'']
| game        = [[GTA 3]], [[Vice City]], [[San Andreas]]
+
'''Parameter'''
| native      = [[GIVE_WEAPON_TO_CHAR]]
+
: [''char handle'']
}}
+
:: The handle of the character
This gives a weapon to a character. Using this opcode requires [[0247]] or else the weapon might not be visible which can crash the game.
+
: [''int1'']
 +
:: [[Weapon#Lists of Weapons|Weapon number]]
 +
: [''int2'']
 +
:: Ammo
 +
'''Native analog'''
 +
: [[GIVE_WEAPON_TO_CHAR]]
 +
 
 +
This opcode gives a weapon to a character to wield. Using this opcode requires loading the weapon model through [[0247]] or else the weapon might not be visible which can crash the game. If the character is killed, the weapon it drops does not equal to the ammo count set with this opcode; it will drop only one clip of ammo.
 +
 
 +
== Example ==
 +
The following exmaple, using Sanny Builder, will spawn a character holding a pistol close to the player character. The values used here are for Vice City and should be changed if used for other games.
  
==Example==
 
This will be only shown as an example on how to assign a weapon to a character and shouldn't be copied verbatim. There are other ways of doing this. The following code uses the [[Sanny Builder]].
 
 
<source lang="scm">
 
<source lang="scm">
:LoadModel
+
// set constants
0247: load_model #BFORI
+
const
0247: load_model #COLT45
+
CHAR_MODEL = #BFORI
   
+
WEAP_MODEL = #COLT45
:CheckModel
+
WEAP_NUMBER = 17 // each game is different! see weapons page for the proper number to use!
0001: wait 0 ms
+
SPAWNED_CHAR = 0@
00D6: if and
+
X_POS = 1@
0248:  model #BFORI available
+
Y_POS = 2@
0248:  model #COLT45 available
+
Z_POS = 3@
004D: jump_if_false @CheckModel
+
end
009A: 0@ = create_actor_pedtype 4 model #BFORI at 0.0 0.0 0.0
+
 
01B2: give_actor 0@ weapon 22 ammo 100
+
// load models, required to prevent unnecessary crash!
0249: release_model #BFORI
+
0247: request_model CHAR_MODEL
0249: release_model #COLT45
+
0247: request_model WEAP_MODEL
004E: end_thread
+
// check if models are loaded
 +
repeat
 +
    wait 0
 +
    if and
 +
        0248:  model CHAR_MODEL available
 +
        0248:  model WEAP_MODEL available
 +
    then
 +
        break
 +
    end
 +
until false
 +
// spawn character with weapon
 +
00A0: store_actor $PLAYER_ACTOR position_to X_POS Y_POS Z_POS
 +
X_POS += 4.0
 +
009A: SPAWNED_CHAR = create_actor 4 CHAR_MODEL at X_POS Y_POS Z_POS
 +
01B2: give_actor SPAWNED_CHAR weapon WEAP_NUMBER ammo 100
 +
// cleanup
 +
0249: release_model CHAR_MODEL
 +
0249: release_model WEAP_MODEL
 +
01C2: remove_references_to_actor CHAR_MODEL
 
</source>
 
</source>
  
==Keywords==
+
== Keywords ==
 
give, assign, actor, character, weapon
 
give, assign, actor, character, weapon
 +
 +
[[Category:OpCodes]]

Revision as of 06:47, 22 August 2011

GTA III Vice City San Andreas


Description

Gives a weapon to a character

Syntax

01B2: give_actor [char handle] weapon [int1] ammo [int2]

Parameter

[char handle]
The handle of the character
[int1]
Weapon number
[int2]
Ammo

Native analog

GIVE_WEAPON_TO_CHAR

This opcode gives a weapon to a character to wield. Using this opcode requires loading the weapon model through 0247 or else the weapon might not be visible which can crash the game. If the character is killed, the weapon it drops does not equal to the ammo count set with this opcode; it will drop only one clip of ammo.

Example

The following exmaple, using Sanny Builder, will spawn a character holding a pistol close to the player character. The values used here are for Vice City and should be changed if used for other games.

// set constants
const
CHAR_MODEL = #BFORI
WEAP_MODEL = #COLT45
WEAP_NUMBER = 17  // each game is different! see weapons page for the proper number to use!
SPAWNED_CHAR = 0@
X_POS = 1@
Y_POS = 2@
Z_POS = 3@
end

// load models, required to prevent unnecessary crash!
0247: request_model CHAR_MODEL
0247: request_model WEAP_MODEL
// check if models are loaded
repeat
    wait 0
    if and
        0248:   model CHAR_MODEL available
        0248:   model WEAP_MODEL available
    then
        break
    end
until false
// spawn character with weapon
00A0: store_actor $PLAYER_ACTOR position_to X_POS Y_POS Z_POS
X_POS += 4.0
009A: SPAWNED_CHAR = create_actor 4 CHAR_MODEL at X_POS Y_POS Z_POS
01B2: give_actor SPAWNED_CHAR weapon WEAP_NUMBER ammo 100
// cleanup
0249: release_model CHAR_MODEL
0249: release_model WEAP_MODEL
01C2: remove_references_to_actor CHAR_MODEL

Keywords

give, assign, actor, character, weapon