Difference between revisions of "0491"

From GTAMods Wiki
Jump to navigation Jump to search
(Created page with "{{Icon|SA}} '''HAS_CHAR_GOT_WEAPON''' <hr /> '''Description''' : Checks if the character has the specified weapon '''Syntax''' : 0491:   actor [''char handle''] has_weapo...")
 
m
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
{{Icon|SA}} '''HAS_CHAR_GOT_WEAPON'''
+
{{OpCode
<hr />
+
| games      = {{Icon|SA}}
'''Description'''
+
| command    = HAS_CHAR_GOT_WEAPON
: Checks if the character has the specified weapon
+
| description = Checks if the character has the specified [[weapon]]
'''Syntax'''
+
| syntax1    = 0491: &nbsp; actor [''char handle''] has_weapon [''int'']
: 0491: &nbsp; actor [''char handle''] has_weapon [''int'']
+
| p1t        = [''char handle'']
'''Parameter'''
+
| p1d        = The handle of the character
: [''char handle'']
+
| p2t        = [''int'']
:: The handle of the character
+
| p2d        = [[Weapon#San Andreas|Weapon type]]
: [''int'']
+
}}
:: [[Weapon#San Andreas|Weapon number]]
 
  
This conditional opcode returns true if the character has the specified weapon. It supersedes [[Vice City]]'s opcode [[0490]].
+
This conditional opcode returns true if the character has the specified weapon.
  
 
== For Vice City ==
 
== 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. The while loop may slow down your script so you should change the code if time is really important for you. Place this at the end of the file:
+
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:
<syntaxhighlight lang="scm">
+
{{Pre|class=sb-code|1=
:opcode_0491
+
<span class="nl">:opcode_0491</span>
// 0@ - input param (char handle)
+
<span class="c1">// 0@ - input param (char handle)</span>
// 1@ - input param (weapon number)
+
<span class="c1">// 1@ - input param (weapon type)</span>
05E6: 0@ = actor 0@ struct
+
05E6: <span class="nv">0@</span> = actor <span class="nv">0@</span> struct
0@ += 0x408  // weapons offset
+
<span class="nv">0@</span> += <span class="m">0x408</span> <span class="c1">// weapon structs base offset</span>
2@ = 0  // index
+
<span class="nv">2@</span> = <span class="m">0</span> <span class="c1">// index</span>
while 2@ < 10
+
<span class="k">while</span> <span class="nv">2@</span> < <span class="m">10</span>
     05E0: 3@ = read_memory 0@ size 4 virtual_protect 0  // read weapon number
+
     [[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>
     if
+
     <span class="k">if</span>
         003B:  3@ == 1@  // weapon number matches
+
         003B:  <span class="nv">3@</span> == <span class="nv">1@</span> <span class="c1">// weapon type matches</span>
     then
+
     <span class="k">then</span>
         05F6: ret 0
+
         [[0AB2|05F6]]: ret <span class="m">0</span>
     end
+
     <span class="k">end</span>
     0@ += 0x18  // iterate weapon struct
+
     <span class="nv">0@</span> += <span class="m">0x18</span> <span class="c1">// increment weapon struct</span>
     2@ += 1  // iterate index
+
     <span class="nv">2@</span> += <span class="m">1</span> <span class="c1">// increment index</span>
end
+
<span class="k">end</span>
05F6: ret 0
+
[[0AB2|05F6]]: ret <span class="m">0</span>
</syntaxhighlight>
+
}}
  
 
Use this line as a substitute for opcode 0491. This can be placed anywhere within the external script as a conditional statement:
 
Use this line as a substitute for opcode 0491. This can be placed anywhere within the external script as a conditional statement:
<syntaxhighlight lang="scm">
+
{{Pre|class=sb-code|1=
// ...
+
<span class="c1">// ...</span>
if
+
<span class="k">if</span>
     05F5: call_scm_func @opcode_0491 inputs 2 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]
then
+
<span class="k">then</span>
     // [RETURNED TRUE]
+
     <span class="c1">// [RETURNED TRUE]</span>
else
+
<span class="k">else</span>
     // [RETURNED FALSE]
+
     <span class="c1">// [RETURNED FALSE]</span>
end
+
<span class="k">end</span>
// ...
+
<span class="c1">// ...</span>
</syntaxhighlight>
+
}}
 +
 
 +
Be careful if you want to modify the example because the loop does not have a [[0001|wait]] in order to minimize any delays. Alternatively, the loop can be unrolled to result in the same behavior.
  
 
== Keywords ==
 
== Keywords ==
 
has, actor, character, got, weapon
 
has, actor, character, got, weapon
  
[[Category:OpCodes]]
+
== See also ==
[[Category:Code Snippets]]
+
* {{Icon|VC}} [[0490]], checks if the player has the specified weapon

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