0491

From GTAMods Wiki
Revision as of 08:01, 29 July 2015 by Spaceeinstein (talk | contribs) (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...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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 number

This conditional opcode returns true if the character has the specified weapon. It supersedes Vice City's opcode 0490.

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:

:opcode_0491
// 0@ - input param (char handle)
// 1@ - input param (weapon number)
05E6: 0@ = actor 0@ struct
0@ += 0x408  // weapons offset
2@ = 0  // index
while 2@ < 10
    05E0: 3@ = read_memory 0@ size 4 virtual_protect 0  // read weapon number
    if
        003B:   3@ == 1@  // weapon number matches
    then
        05F6: ret 0
    end
    0@ += 0x18  // iterate weapon struct
    2@ += 1  // iterate 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
// ...

Keywords

has, actor, character, got, weapon