What is the best way to look for when a ped takes out a weapon ? lua

so i were trying to look if a ped takes out a weapon then what weapon it is ? but only whay i cud think of were scanning every second but that wud probely make it not so great to use short told i am wondering if there is any naive or somfing that you cud lissen for ?

Solved
by spike

This is a line from the mugging script im in the process of putting together…

if IsPedArmed(GetPlayerPed(-1), 7) and IsPedArmed(GetPlayerPed(-1), 4) then

The first check is to make sure the player is armed with something other then his fists… Second check is to make sure the player is equipped with anything other then explosive and melee weapons. So this works for me to make sure the player has a gun equiped before i make the NPC put hands up to start the mugging.

The flags are all explained on the FiveM Native Reference - IsPedArmed

hope this helped.

SpikE

https://runtime.fivem.net/doc/natives/#_0x475768A975D5AD17

(IsPedArmed)

Try that. I’m not 100% sure though.

Are you trying to see when a NPC takes out a weapon or player on the server takes out a weapon?

Player

Il try when i get home thx

This is a line from the mugging script im in the process of putting together…

if IsPedArmed(GetPlayerPed(-1), 7) and IsPedArmed(GetPlayerPed(-1), 4) then

The first check is to make sure the player is armed with something other then his fists… Second check is to make sure the player is equipped with anything other then explosive and melee weapons. So this works for me to make sure the player has a gun equiped before i make the NPC put hands up to start the mugging.

The flags are all explained on the FiveM Native Reference - IsPedArmed

hope this helped.

SpikE

so i had

local ped = GetPlayerPed(-1)
if IsPedArmed(ped, 7) then

but nothing happend so glad you came with this dont know that i did rong but your line worked thx

Glad it helped you get it sorted… but looking at what you had and what i had only difference is mine was on one line vs 2 like yours… but both should work. I am learning that Lua has some interesting quirks as i learn it :smiley:

Good Luck with your script

SpikE