Difference between revisions of "0491"

From GTAMods Wiki
Jump to navigation Jump to search
(highlight)
m
 
Line 2: Line 2:
 
| games      = {{Icon|SA}}
 
| games      = {{Icon|SA}}
 
| command    = HAS_CHAR_GOT_WEAPON
 
| command    = HAS_CHAR_GOT_WEAPON
| description = Checks if the character has the specified weapon
+
| description = Checks if the character has the specified [[weapon]]
 
| syntax1    = 0491:   actor [''char handle''] has_weapon [''int'']
 
| syntax1    = 0491:   actor [''char handle''] has_weapon [''int'']
 
| p1t        = [''char handle'']
 
| p1t        = [''char handle'']
 
| p1d        = The handle of the character
 
| p1d        = The handle of the character
 
| p2t        = [''int'']
 
| p2t        = [''int'']
| p2d        = [[Weapon#San Andreas|Weapon number]]
+
| p2d        = [[Weapon#San Andreas|Weapon type]]
 
}}
 
}}
  
Line 17: Line 17:
 
<span class="nl">:opcode_0491</span>
 
<span class="nl">:opcode_0491</span>
 
<span class="c1">// 0@ - input param (char handle)</span>
 
<span class="c1">// 0@ - input param (char handle)</span>
<span class="c1">// 1@ - input param (weapon number)</span>
+
<span class="c1">// 1@ - input param (weapon type)</span>
 
05E6: <span class="nv">0@</span> = actor <span class="nv">0@</span> struct
 
05E6: <span class="nv">0@</span> = actor <span class="nv">0@</span> struct
<span class="nv">0@</span> += <span class="m">0x408</span>  <span class="c1">// weapons offset</span>
+
<span class="nv">0@</span> += <span class="m">0x408</span>  <span class="c1">// weapon structs base offset</span>
 
<span class="nv">2@</span> = <span class="m">0</span>  <span class="c1">// index</span>
 
<span class="nv">2@</span> = <span class="m">0</span>  <span class="c1">// index</span>
 
<span class="k">while</span> <span class="nv">2@</span> < <span class="m">10</span>
 
<span class="k">while</span> <span class="nv">2@</span> < <span class="m">10</span>
     05E0: <span class="nv">3@</span> = read_memory <span class="nv">0@</span> size <span class="m">4</span> virtual_protect <span class="m">0</span>  <span class="c1">// read weapon number</span>
+
     [[0A8D|05E0]]: <span class="nv">3@</span> = read_memory <span class="nv">0@</span> size <span class="m">4</span> virtual_protect <span class="m">0</span>  <span class="c1">// read weapon type</span>
 
     <span class="k">if</span>
 
     <span class="k">if</span>
         003B:  <span class="nv">3@</span> == <span class="nv">1@</span>  <span class="c1">// weapon number matches</span>
+
         003B:  <span class="nv">3@</span> == <span class="nv">1@</span>  <span class="c1">// weapon type matches</span>
 
     <span class="k">then</span>
 
     <span class="k">then</span>
         05F6: ret <span class="m">0</span>
+
         [[0AB2|05F6]]: ret <span class="m">0</span>
 
     <span class="k">end</span>
 
     <span class="k">end</span>
     <span class="nv">0@</span> += <span class="m">0x18</span>  <span class="c1">// iterate weapon struct</span>
+
     <span class="nv">0@</span> += <span class="m">0x18</span>  <span class="c1">// increment weapon struct</span>
     <span class="nv">2@</span> += <span class="m">1</span>  <span class="c1">// iterate index</span>
+
     <span class="nv">2@</span> += <span class="m">1</span>  <span class="c1">// increment index</span>
 
<span class="k">end</span>
 
<span class="k">end</span>
05F6: ret <span class="m">0</span>
+
[[0AB2|05F6]]: ret <span class="m">0</span>
 
}}
 
}}
  
Line 38: Line 38:
 
<span class="c1">// ...</span>
 
<span class="c1">// ...</span>
 
<span class="k">if</span>
 
<span class="k">if</span>
     05F5: call_scm_func <span class="nl">@opcode_0491</span> inputs <span class="m">2</span> char_handle [char handle] weapon [int]
+
     [[0AB1|05F5]]: call_scm_func <span class="nl">@opcode_0491</span> inputs <span class="m">2</span> char_handle [char handle] weapon [int]
 
<span class="k">then</span>
 
<span class="k">then</span>
 
     <span class="c1">// [RETURNED TRUE]</span>
 
     <span class="c1">// [RETURNED TRUE]</span>

Latest revision as of 19:43, 7 July 2017

San Andreas HAS_CHAR_GOT_WEAPON


Description
Checks if the character has the specified weapon
Syntax
0491:   actor [char handle] has_weapon [int]
Parameter
[char handle]
The handle of the character
[int]
Weapon type

This conditional opcode returns true if the character has the specified weapon.

For Vice City

This opcode does not exist in Vice City but it is possible to check if the character has the specified weapon. The following example, using Sanny Builder with CLEO for Vice City in an external script (not the main one) and tested on US v1.0, should work similarly to this opcode. Place this at the end of the file:

:opcode_0491
// 0@ - input param (char handle)
// 1@ - input param (weapon type)
05E6: 0@ = actor 0@ struct
0@ += 0x408  // weapon structs base offset
2@ = 0  // index
while 2@ < 10
    05E0: 3@ = read_memory 0@ size 4 virtual_protect 0  // read weapon type
    if
        003B:   3@ == 1@  // weapon type matches
    then
        05F6: ret 0
    end
    0@ += 0x18  // increment weapon struct
    2@ += 1  // increment index
end
05F6: ret 0

Use this line as a substitute for opcode 0491. This can be placed anywhere within the external script as a conditional statement:

// ...
if
    05F5: call_scm_func @opcode_0491 inputs 2 char_handle [char handle] weapon [int]
then
    // [RETURNED TRUE]
else
    // [RETURNED FALSE]
end
// ...

Be careful if you want to modify the example because the loop does not have a wait in order to minimize any delays. Alternatively, the loop can be unrolled to result in the same behavior.

Keywords

has, actor, character, got, weapon

See also

  • Vice City 0490, checks if the player has the specified weapon