Página 1 de 1

Checar se está segurando arma de fogo

Enviado: 18 Nov 2018, 01:15
por Junior_Djjr
Descrição

Normalmente quando alguém vai checar se o char/actor está com alguma arma de fogo (arma perigosa em geral), ele pega o ID da arma atual e checa se está entre 22 e 38. Isto não é legal!!!!!!!
Além de que é possível mudar o funcionamento de uma arma (por exemplo deixá-la de ser de fogo) pelo weapon.dat, se alguém adicionou arma sem substituir, que atualmente é um ato comum, o ID da arma será acima de 70, assim não retornará verdadeiro.
Então checar se é acima de 70? NÃO!!! Pois a pessoa pode ter adicionado uma arma não perigosa também.

Eis a verdadeira solução:


Exemplo de uso

gta3script:

Código: Selecionar tudo

SCRIPT_START
{
    LVAR_INT scplayer

    GET_PLAYER_CHAR 0 scplayer

    WHILE TRUE
        WAIT 0
        IF CLEO_CALL IsCharHoldingDangerousWeapon 0 (scplayer)
            PRINT_STRING_NOW "TRUE" 1
        ENDIF
    ENDWHILE
}
SCRIPT_END

{
    /*
        Return true if char is holding any fire or explosion weapon - By Junior_Djjr
        Use: IF CLEO_CALL IsCharHoldingDangerousWeapon 0 (hChar)()
    */
    LVAR_INT hChar // In
    LVAR_INT iWeaponType pWeaponInfo iFireType

    CONST_INT WEAPON_FIRE_MELEE         0
    CONST_INT WEAPON_FIRE_INSTANT_HIT   1
    CONST_INT WEAPON_FIRE_PROJECTILE    2
    CONST_INT WEAPON_FIRE_AREA_EFFECT   3
    CONST_INT WEAPON_FIRE_CAMERA        4
    CONST_INT WEAPON_FIRE_USE           5

    IsCharHoldingDangerousWeapon:
    GET_CURRENT_CHAR_WEAPON hChar (iWeaponType)
    // GetWeaponInfo (we can ignore skill (1) here)
    CALL_FUNCTION_RETURN 0x743C60 2 2 (1 iWeaponType)(pWeaponInfo)
    READ_MEMORY pWeaponInfo 4 FALSE (iFireType)
    IF iFireType = WEAPON_FIRE_INSTANT_HIT
    OR iFireType = WEAPON_FIRE_PROJECTILE
        RETURN_TRUE
    ELSE
        RETURN_FALSE
    ENDIF
    CLEO_RETURN 0 ()
}
Necessário WHILE TRUE

Sanny Builder:

Código: Selecionar tudo

{$cleo}
0000:

while true
    wait 0
    if 0AB1: call_scm_func @IsCharHoldingDangerousWeapon 1 $PLAYER_ACTOR
    then
        0ACD: show_text_highpriority "TRUE" time 1
    end
end

/*
    Return true if char is holding any fire or explosion weapon - By Junior_Djjr
    Use: 0AB1: call_scm_func @IsCharHoldingDangerousWeapon 1 $PLAYER_ACTOR
*/
const
    WEAPON_FIRE_MELEE         0
    WEAPON_FIRE_INSTANT_HIT   1
    WEAPON_FIRE_PROJECTILE    2
    WEAPON_FIRE_AREA_EFFECT   3
    WEAPON_FIRE_CAMERA        4
    WEAPON_FIRE_USE           5
end

:IsCharHoldingDangerousWeapon
0470: 1@ = actor 0@ current_weapon
// GetWeaponInfo (we can ignore skill (1) here)
0AA7: call_function_return 0x743C60 num_params 2 pop 2 1 1@ -> 1@
0A8D: 1@ = read_memory 1@ size 4 virtual_protect false
if or
1@ = WEAPON_FIRE_INSTANT_HIT
1@ = WEAPON_FIRE_PROJECTILE
0AB2: ret 0

Somente GTA SA 1.0 US