[SOLVED] HasPedBeenDamageByWeapon


#1

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.


#2

There’s a function for it

https://pastebin.com/6NUMX5s3

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


#3

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


#4

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


#5

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

#6
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

#7

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 ?


#8

You have to find a new one.

You can find some here


#9

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


#10

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


#11

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 ?


#12

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


#13

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.


#14

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))