Difference between revisions of "01B2"

From GTAMods Wiki
Jump to navigation Jump to search
m (Example)
m
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
{{OpCode
 
{{OpCode
| ini        = 01B2=3,%1d% %2d% %3d%
+
| games      = {{Icon|t}}
| description = Gives a weapon to a character
+
| command    = GIVE_WEAPON_TO_CHAR
| p1          = Existing actor handle
+
| description = Gives the [[weapon]] to the character
| p2          = [[Weapon]] number
+
| syntax1    = 01B2: give_actor [''char handle''] weapon [''int1''] ammo [''int2'']
| p3          = Ammo
+
| p1t        = [''char handle'']
| game        = [[GTA 3]], [[Vice City]], [[San Andreas]]
+
| p1d        = The handle of the character
 +
| p2t        = [''int1'']
 +
| p2d        = [[Weapon#Lists of weapons|Weapon type]]
 +
| p3t        = [''int2'']
 +
| p3d        = Ammo
 
| native      = [[GIVE_WEAPON_TO_CHAR]]
 
| native      = [[GIVE_WEAPON_TO_CHAR]]
 
}}
 
}}
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.
 
  
==Example==
+
This opcode adds to the character's weapon ammo and sets the weapon as the current one for the character. If the character does not have the weapon, the weapon is given to it and replaces any weapon of the same slot. Using this opcode requires loading the weapon model through [[0247]] or else the weapon might not be visible which can crash the game. When the character dies, it drops the weapon as a [[0213#Weapons|pickup type 4 with predefined ammo count]].
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">
 
:LoadModel
 
0247: load_model #BFORI
 
0247: load_model #COLT45
 
 
:CheckModel
 
0001: wait 0 ms
 
00D6: if and
 
0248:  model #BFORI available
 
0248:  model #COLT45 available
 
004D: jump_if_false @LoadModel
 
009A: 0@ = create_actor_pedtype 4 model #BFORI at 0.0 0.0 0.0
 
01B2: give_actor 0@ weapon 22 ammo 100
 
0249: release_model #BFORI
 
0249: release_model #COLT45
 
004E: end_thread
 
</source>
 
  
==Keywords==
+
== Example ==
 +
The following example 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.
 +
{{Pre|class=sb-code|1=
 +
<span class="c1">// set constants</span>
 +
<span class="k">const</span>
 +
CHAR_MODEL = <span class="nt">#BFORI</span>  <span class="c1">// set your character model</span>
 +
WEAP_MODEL = <span class="nt">#COLT45</span>  <span class="c1">// set your weapon model</span>
 +
WEAP_TYPE = <span class="m">17</span>  <span class="c1">// set your weapon type</span>
 +
SPAWNED_CHAR = <span class="nv">0@</span>
 +
X_POS = <span class="nv">1@</span>
 +
Y_POS = <span class="nv">2@</span>
 +
Z_POS = <span class="nv">3@</span>
 +
<span class="k">end</span>
 +
 
 +
<span class="c1">// load models, required to prevent unnecessary crash!</span>
 +
[[0247]]: request_model CHAR_MODEL
 +
[[0247]]: request_model WEAP_MODEL
 +
[[038B]]: load_requested_models
 +
<span class="c1">// spawn character with weapon</span>
 +
[[00A0]]: store_actor <span class="nv">$PLAYER_ACTOR</span> position_to X_POS Y_POS Z_POS
 +
X_POS += <span class="m">4.0</span>
 +
[[009A]]: SPAWNED_CHAR = create_actor <span class="m">4</span> CHAR_MODEL at X_POS Y_POS Z_POS
 +
01B2: give_actor SPAWNED_CHAR weapon WEAP_TYPE ammo <span class="m">100</span>
 +
<span class="c1">// cleanup</span>
 +
[[0249]]: release_model CHAR_MODEL
 +
[[0249]]: release_model WEAP_MODEL
 +
[[01C2]]: remove_references_to_actor SPAWNED_CHAR
 +
}}
 +
 
 +
== Keywords ==
 
give, assign, actor, character, weapon
 
give, assign, actor, character, weapon
 +
 +
== See also ==
 +
* {{Icon|3}} {{Icon|SA}} [[017B]], sets the character's weapon ammo
 +
* {{Icon|3}} {{Icon|VC}} [[01B1]], gives the weapon to the player
 +
 +
[[Category:Code Snippets]]

Latest revision as of 19:28, 7 July 2017

GTA III Vice City San Andreas GIVE_WEAPON_TO_CHAR


Description
Gives the weapon to the character
Syntax
01B2: give_actor [char handle] weapon [int1] ammo [int2]
Parameter
[char handle]
The handle of the character
[int1]
Weapon type
[int2]
Ammo
Native analog
GIVE_WEAPON_TO_CHAR

This opcode adds to the character's weapon ammo and sets the weapon as the current one for the character. If the character does not have the weapon, the weapon is given to it and replaces any weapon of the same slot. Using this opcode requires loading the weapon model through 0247 or else the weapon might not be visible which can crash the game. When the character dies, it drops the weapon as a pickup type 4 with predefined ammo count.

Example

The following example 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  // set your character model
WEAP_MODEL = #COLT45  // set your weapon model
WEAP_TYPE = 17  // set your weapon type
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
038B: load_requested_models
// 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_TYPE ammo 100
// cleanup
0249: release_model CHAR_MODEL
0249: release_model WEAP_MODEL
01C2: remove_references_to_actor SPAWNED_CHAR

Keywords

give, assign, actor, character, weapon

See also

  • GTA III San Andreas 017B, sets the character's weapon ammo
  • GTA III Vice City 01B1, gives the weapon to the player