IsActorDamaged

This snippet returns how actor was damaged.

Author: @ajom
Some changes by: @Parazitas

Snippet
PHP:
:isActorDamaged
{
    Use: IF 0AB1: @isActorDamaged 1 ActorHandle: $PLAYER_ACTOR _Returned: DamagedBy 0@
}
0A96: 31@ = actor 0@ struct
0A8E: 30@ = 31@ + 0x760 // DamageID Offset
0A8D: 29@ = read_memory 30@ size 4 virtual_protect 0
IF NOT 29@ == 255 // 255 = not Damaged
THEN
    0085: 28@ = 29@ // (int)
    0A8C: write_memory 30@ size 4 value 255 virtual_protect 0 // clear last damage
    0485:  return_true
    0AB2: ret 1 28@
ELSE 059A:  return_false
END
0AB2: ret 0

List of Damage types ID's
PHP:
(Slot0: No Weapon)                     (Slot2: Handguns)
  0 – Fist                               22 – Pistol
  1 – Brass Knuckles                     23 – Silenced Pistol
                                         24 – Desert Eagle
(Slot1: Melee)                        
  2 – Golf Club                        
  3 – Nitestick                            (Slot3: Shotguns)
  4 – Knife                              25 – Shotgun
  5 – Baseball Bat                       26 – Sawn-Off Shotgun
  6 – Shovel                             27 – SPAS-12
  7 – Pool Cue                            
  15 – Cane                            
                                        (Slot4: Sub-Machineguns)
                                        28 – Micro Uzi
                                      29 – MP5
                                         32 – TEC-9
                                       
 (Slot5: Machineguns)                  (Slot10: Gifts)
  30 – AK47                              14 – Flowers
  31 – M4                              
                                        (Slot9:Special1)
 (Slot6: Rifles)                        42 – Fire Extinguisher
  33 – Country Rifle                     43 – Camera
  34 – Sniper Rifle                    
                                        (Slot11:Special2)
(Slot7: Heavy Weapons)                 44 – NV Goggles
  35 – Rocket Launcher                   45 – IR Goggles
  36 – Heat Seaking RPG                  46 – Parachute
  37 – Flame Thrower                   
  38 – Minigun                            (Slot12:Detonators)
                                         40 – Detonator(for remote explosives)

(Slot8: Projectiles)
  16 – Grenade
  18 – Molotov Cocktail
  39 – Remote Explosives

(No slot: Fired from hunter / hydra / missile launcher)
(This type is stored in the rocket pool as rocket type, but is the continuation of this list)
  19 – Normal rockets
  20 – Heatseeking rockets
  58 – Flares
 

tieuthienthan

Active member
Joined
Nov 6, 2019
Messages
43
Reaction score
10
Location
Vietnam
add more DamagedByActor return value please
I tried the below memory address but it doesn't work
Code:
CPed +0x764 = [dword] Pointer to the ped that damaged you
 

ajom

Well-known member
Joined
Apr 14, 2020
Messages
389
Solutions
2
Reaction score
268
Location
Pluto
Advanced Snippet Version:
Code:
:ActorGotDamaged // if 0AB1: @ActorGotDamaged 1 _ActorHandle 0@ _Store: _DamageID 30@ _Entity_Type 28@ _Entity_Handle 29@
    0A96: 0@ = ped 0@ struct
    0@ += 0x760 // Damaged By Weapon ID
    0A8D: 31@ = read_memory 0@ size 4 virtual_protect false
    0@ += 4 // Actor Struct of the Damage Dealer
    0A8D: 29@ = read_memory 0@ size 4 virtual_protect false
    if 31@ <> 255 // 255 = not Damaged
    then
            // Clear Damage
        0A8C: write_memory 0@ size 4 value 0 virtual_protect false // 0 = null actor pointer, AKA no actor damager
        0@ -= 4
        0A8C: write_memory 0@ size 4 value 255 virtual_protect false // 255 = not Damaged
            //
    
            // Get Entity Type
        0A8E: 28@ = 29@ + 0x36 // Subject type
        0A8D: 28@ = read_memory 28@ size 4 virtual_protect false
        0B10: 28@ = 28@ AND 7 // extract only the first 3 bits
            //
    
            // Get Entity Handle
        if 28@ == 0 // was Object
        then 0AEC: 29@ = object_struct 29@ handle
        else
            if 28@ == 2 // was Vehicle
            then 0AEB: 29@ = vehicle_struct 29@ handle
            else
                if 28@ == 3 // was Pedestrian
                then 0AEA: 29@ = ped_struct 29@ handle
                end
            end
        end
            //
    
        0485: return_true
    else 059A: return_false
    end
ret 3 _DamageID 31@ _Entity_Type 28@ _Entity_Handle 29@


Demonstration:
Code:
{$CLEO}
0000: damage detector by AJOM

while true
    wait 0
    if 0AB1: @ActorGotDamaged 1 _ActorHandle $PLAYER_ACTOR _Store: _DamageID 0@ _Entity_Type 1@ _Entity_Handle 2@
    then
        if 1@ == 0 // was Object
        then 0AD1: show_formatted_text_highpriority "You got Damaged by an Object!~n~Damage ID: %d~n~Handle: %d" time 2000 0@ 2@
        else
            if 1@ == 1 // was Building
            then 0AD1: show_formatted_text_highpriority "You got Damaged by a Building!~n~Damage ID: %d" time 2000 0@
            else
                if 1@ == 2 // was Vehicle
                then 0AD1: show_formatted_text_highpriority "You got Damaged by a Vehicle!~n~Damage ID: %d~n~Handle: %d" time 2000 0@ 2@
                else
                    if 1@ == 3 // was Pedestrian
                    then 0AD1: show_formatted_text_highpriority "You got Damaged by a Pedestrian!~n~Damage ID: %d~n~Handle: %d" time 2000 0@ 2@
                    else 0AD1: show_formatted_text_highpriority "You got Damaged by an Unknown Entity Type!~n~Damage ID: %d" time 2000 0@
                    end
                end
            end
        end
    end
end

This Snippet was based from this topic.
 
Last edited:

tieuthienthan

Active member
Joined
Nov 6, 2019
Messages
43
Reaction score
10
Location
Vietnam
I tried that, don't know if it works or not but the snippet cause a massive fps drop (~4 fps)
I'm using it with OpcodeX's for all peds snippet to find all the actor damaged by $PLAYER_ACTOR
ForAllPeds:
Code:
:ForAllPeds
    0A8D: 29@ = read_memory 0xB74490 size 4 virtual_protect 0
    000A: 29@ += 0x4
    0A8D: 29@ = read_memory 29@ size 4 virtual_protect 0
    for 30@ = 0 to 35584 step 0x100
        0A8D: 31@ = read_memory 29@ size 1 virtual_protect 0
        000A: 29@ += 0x1
        if and
            0029:  31@ >= 0x00
            001B:  0x80 > 31@
        then
            005A: 31@ += 30@
            // your code
        end
    end
    return


My code:


Code:
while true
    wait 0
    ForAllPeds()
end

:ForAllPeds
    0A8D: 29@ = read_memory 0xB74490 size 4 virtual_protect 0
    000A: 29@ += 0x4
    0A8D: 29@ = read_memory 29@ size 4 virtual_protect 0
    for 30@ = 0 to 35584 step 0x100
        0A8D: 31@ = read_memory 29@ size 1 virtual_protect 0
        000A: 29@ += 0x1
        if and
            0029:  31@ >= 0x00
            001B:  0x80 > 31@
        then
            005A: 31@ += 30@
            if and
                056D:   actor 31@ defined
                803B:   31@ == $PLAYER_ACTOR     
            then
                if
                    0AB1: @IsActorDamaged 1 _ActorHandle 31@ _Store_DamageID 28@ _Store_Dealer_ActorHandle 27@
                then
                    0AD1: "Someone is attacked! Weapon %d~n~Dealer:%d" 500 28@ 27@ // just test if the snippet returns the correct dealer's actor handle before checking if it is $PLAYER_ACTOR
                end
            end         
        end
    end
    return

:IsActorDamaged // if 0AB1: @IsActorDamaged 1 _ActorHandle 0@ _Store_DamageID 30@ _Store_Dealer_ActorHandle 29@
0A96: 31@ = actor 0@ struct
31@ += 0x760 // Damaged By Weapon ID
0A8D: 30@ = read_memory 31@ size 4 virtual_protect false
31@ += 4 // Actor Struct of the Damage Dealer
0A8D: 29@ = read_memory 31@ size 4 virtual_protect false
if 30@ <> 255 // 255 = not Damaged
then
    0A8C: write_memory 31@ size 4 value 0 virtual_protect false // 0 = null actor pointer, AKA no actor damager
    31@ -= 4
    0A8C: write_memory 31@ size 4 value 255 virtual_protect false // 255 = not Damaged
    if 29@ <> 0
    then 0AEA: 29@ = actor_struct 29@ handle
    end
    0485: return_true
else 059A: return_false
end
ret 2 _DamageID 30@ _Dealer_ActorHandle 29@
@ajom please send help
 

ajom

Well-known member
Joined
Apr 14, 2020
Messages
389
Solutions
2
Reaction score
268
Location
Pluto
I tried that, don't know if it works or not but the snippet cause a massive fps drop (~4 fps)
I'm using it with OpcodeX's for all peds snippet to find all the actor damaged by $PLAYER_ACTOR
ForAllPeds:
Code:
:ForAllPeds
    0A8D: 29@ = read_memory 0xB74490 size 4 virtual_protect 0
    000A: 29@ += 0x4
    0A8D: 29@ = read_memory 29@ size 4 virtual_protect 0
    for 30@ = 0 to 35584 step 0x100
        0A8D: 31@ = read_memory 29@ size 1 virtual_protect 0
        000A: 29@ += 0x1
        if and
            0029:  31@ >= 0x00
            001B:  0x80 > 31@
        then
            005A: 31@ += 30@
            // your code
        end
    end
    return


My code:


Code:
while true
    wait 0
    ForAllPeds()
end

:ForAllPeds
    0A8D: 29@ = read_memory 0xB74490 size 4 virtual_protect 0
    000A: 29@ += 0x4
    0A8D: 29@ = read_memory 29@ size 4 virtual_protect 0
    for 30@ = 0 to 35584 step 0x100
        0A8D: 31@ = read_memory 29@ size 1 virtual_protect 0
        000A: 29@ += 0x1
        if and
            0029:  31@ >= 0x00
            001B:  0x80 > 31@
        then
            005A: 31@ += 30@
            if and
                056D:   actor 31@ defined
                803B:   31@ == $PLAYER_ACTOR    
            then
                if
                    0AB1: @IsActorDamaged 1 _ActorHandle 31@ _Store_DamageID 28@ _Store_Dealer_ActorHandle 27@
                then
                    0AD1: "Someone is attacked! Weapon %d~n~Dealer:%d" 500 28@ 27@ // just test if the snippet returns the correct dealer's actor handle before checking if it is $PLAYER_ACTOR
                end
            end        
        end
    end
    return

:IsActorDamaged // if 0AB1: @IsActorDamaged 1 _ActorHandle 0@ _Store_DamageID 30@ _Store_Dealer_ActorHandle 29@
0A96: 31@ = actor 0@ struct
31@ += 0x760 // Damaged By Weapon ID
0A8D: 30@ = read_memory 31@ size 4 virtual_protect false
31@ += 4 // Actor Struct of the Damage Dealer
0A8D: 29@ = read_memory 31@ size 4 virtual_protect false
if 30@ <> 255 // 255 = not Damaged
then
    0A8C: write_memory 31@ size 4 value 0 virtual_protect false // 0 = null actor pointer, AKA no actor damager
    31@ -= 4
    0A8C: write_memory 31@ size 4 value 255 virtual_protect false // 255 = not Damaged
    if 29@ <> 0
    then 0AEA: 29@ = actor_struct 29@ handle
    end
    0485: return_true
else 059A: return_false
end
ret 2 _DamageID 30@ _Dealer_ActorHandle 29@
@ajom please send help
Snippet Got Updated.
 
Top