I’ve added addon weapons to my server and I can’t find a way to get the weapons hashes, is there any way that I can print the hash of the weapon I’m holding in the console or any other way?
local exist, weapon = GetCurrentPedWeapon(PlayerPedId())
print (weapon) ----current weapon hash
Thanks, I tried your code but it seems to only print the number “1” every time
What is yr code fully ?
And what weapon u use?
I actually went for a different approach, since I knew the name of the gun, I used this instead, you just replace WEAPON_M4 by whatever gun you need:
RegisterCommand(‘getgun’, function()
weapon = GetHashKey(“WEAPON_M4”)
print (weapon)
end)
it prints 1 every time bec fivem has no weapon called ‘WEAPON_M4’
I’ve tried it with weapons from the game and it still printed “1”
The reason I have an m4 is because I have addon weapons in my server, my new code worked, it gave me the hash of the addon weapons I added
nice weapon collection and gl with ur server and I am sure that my code works but u might be make mistake by wrong bec I am using this code elsewhere but I might there is some issue in the copy u did.
any way if u want any additional help feel free to contact me
Thanks a lot man, it may have been a mistake from my end. Thanks man I sure will contact you if I need any help.
I’m not completely done with the script but… It has all of the built in weapons hashes. This is for my test server. It gives all weapons to the player. I haven’t finished all of the weapon attachments yet. Markers is in sandy ammo nation behind the counter.
this may help
esx_giveallweapons.zip (3.1 KB)
RegisterCommand('getgun', function()
-- Get the player's Ped (player character)
local playerPed = PlayerPedId()
-- Get the current weapon the player is holding
local _, currentWeapon = GetCurrentPedWeapon(playerPed, true)
-- Print the hash of the current weapon
if currentWeapon then
print("Weapon Hash: " .. currentWeapon)
-- Optional: Notify the player with the weapon hash (in-game notification)
TriggerEvent('QBCore:Notify', "Weapon Hash: " .. currentWeapon)
else
print("No weapon in hand")
-- Optional: Notify the player in case no weapon is held
TriggerEvent('QBCore:Notify', "You are not holding a weapon")
end
end, false)