[SOLVED] HasPedBeenDamageByWeapon

Hello, I’d like to detect when a player is being damaged by fall and this is what I came up with based on another script :

Citizen.CreateThread(function()
	while true do
		Wait(1)
		local myPed = GetPlayerPed(-1)
		if HasPedBeenDamagedByWeapon(myPed,GetHashKey("WEAPON_FALL"),true) then
			ShowNotification("~r~yep")
		end
	end
end)

function ShowNotification(text)
	SetNotificationTextEntry("STRING")
	AddTextComponentString(text)
	DrawNotification(false, false)
end

I just want to know how to use HasPedBeenDamagedByWeapon, thanks.

1 Like

There’s a function for it

function HasPedBeenDamagedByWeapon(ped, weaponHash, weaponType)
    return _in(0x2D343D2219CD027A, ped, weaponHash, weaponType, _r)

Thank you, but what do I need to put as weaponType ?
(I don’t have lot of skills in scripting)

This might help you further, the weapontype is what kind of weapon it is.

I understand, but how do I get the weapon type of WEAPON_FALL ? Or any other weapon I might need in the future like WEAPON_BLEEDING or WEAPON_DROWNING ?

Could you please fix this so it could work with any type of weapon I enter ?

Citizen.CreateThread(function()
	while true do
		Wait(1)
		local myPed = GetPlayerPed(-1)
		if HasPedBeenDamagedByWeapon(myPed, GetHashKey("WEAPON_FALL"), GetWeaponType("weapon_fall")) then
			ShowNotification("~r~yep")
		end
	end
end)

function ShowNotification(text)
	SetNotificationTextEntry("STRING")
	AddTextComponentString(text)
	DrawNotification(false, false)
end

function HasPedBeenDamagedByWeapon(ped, weaponHash, weaponType)
    return _in(0x2D343D2219CD027A, ped, weaponHash, weaponType, _r)
end
1 Like
Citizen.CreateThread(function()
	while true do
		Wait(1)
		local playerPed = GetPlayerPed(-1)
		local weapon = GetHashKey("WEAPON_FALL")
		if HasPedBeenDamagedByWeapon(playerPed, weapon, -842959696) then
			ShowNotification("~r~yep")
		end
	end
end)

function ShowNotification(text)
	SetNotificationTextEntry("STRING")
	AddTextComponentString(text)
	DrawNotification(false, false)
end

Thank you very much, it works ! I didn’t expected to receive so much replies by so much people in a few minutes.

but I still need a bit of explanation on how did you find “-842959696”, if I change “WEAPON_FALL” to “WEAPON_PISTOL” or anything will it be the same Type or will I need to find a new one ?

You have to find a new one.

You can find some here

Nice ! Alright, I got every information I needed, thanks again.

No problem, just take a new look at the link I changed it.

After testing it a bit more, I realized that I needed something to reset HasPedBeenDamageByWeapon. (I want players to die only for extreme reasons, so when you fall you will be knock out, so when I fall I get unconscious but then when I drown I’m still knocked uncounscious)

Any idea on how to solve this problem ?

complentary questions : how do I detect how much damage ped has received ?

If you could explain what exactly you are trying I can maybe help you.

Alright, I’d like the players not to die when they fall from not too high, or in melee combat etc… So I’d like to detect how they are going to die, for this case I’d like to detect if the cause of death is by weapon_fall, and if it is they will be knocked uncounscious for 15 to 30 seconds.

So if HasPedBeenDamagedByWeapon, then they will be knocked uncouscious. But HasBeen keeps the information trough the whole session, so if you fall a first time, you will fall uncouscious as expected, but then when you’re close to die from any other cause you will still fall uncouscious.

I think HasPedBeenDamagedByWeapon is not the right function to use for this, exept if I can reset it after it is detected.

Anyway I’m just dumb, tried IsPedFalling before but I don’t know why I fcked it up so I belevied that when you hit the ground to game didn’t considered you falling. But it works fine.

IsPedFalling(GetPlayerPed(-1))

1 Like

This link is broken. Are there any others?

(EDIT) Found a good working link for anyone that needs it:
https://wiki.■■■■■■■■■■■/index.php?title=Weapons_Models

Hello i have this problem… i have been trying some of your guys sugestions, but somehow it still doesn’t work… with the native!

Im trying this:
local playerPed = GetClosestPlayer()|
if HasPedBeenDamagedByWeapon(playerPed,736523883,0) then
print(“TEST”)
(Trying to do SMG as a Weapon.)
(vRP)

And yessss… i have defined my GetClosestPlayer() value