Hello everyone I tried to code a script what should check if the ammo is empty (In this case of a throwable I tried to apply it to) buuuut it don’t want to work for some reason this is the Code I tried to use(I used this example with this Weapon add-on: [RELEASE] Flashbang sadly I always receive this error:
Error loading script client.lua in resource amocheck: @amocheck/client.lua:1: attempt to call a nil value (global 'GET_AMMO_IN_PED_WEAPON')
stack traceback:
@amocheck/client.lua:1: in main chunk
This is the client script:
Ammo = GET_AMMO_IN_PED_WEAPON(GetPlayerFromServerId(source), `0xFBA1FB98`);
if Ammo == 0 then;
REMOVE_WEAPON_FROM_PED(GetPlayerFromServerId(source), `0xFBA1FB98`);
end;
Thanks for the answer didn’t notice it well anyway I rewrite the code a little it starts without any troubles again but it doesn’t do what it should do again (Sorry this is my first try to make a plugin haha) this is the new code I made:
client.lua
for _, ped in ipairs(GetPlayers()) do
local Ammo =
GetAmmoInPedWeapon(
ped,
0xFBA1FB98
)
if Ammo == 0 then;
RemoveWeaponFromPed(
ped,
0xFBA1FB98
)
end;
You seem to need a thread for this, and a way to trigger the native.
I’m not fully sure if I understood your issue, but hopefully, this is somewhat helpful.
First, we need to get the weapon hash from the weapon that the player is using.
local check, hash = GetCurrentPedWeapon(PlayerPedId(), 1)
Secondly, we run the native that you mentioned.
local ammo = GetAmmoInPedWeapon(PlayerPedId(), hash)
If you want, you can create a variable for PlayerPedId() before all of this.
Learn more about threads here.
Learn more about key mapping here.
Thanks for the answer but sadly it didn’t worked I don’t get a script error but currently it crashed my whole PC trying to execute this I must have made a mistake while doing this could you please look into it @Re1ease1 ?
a = 10
while( a < 20 )
do
Citizen.CreateThread(function()
Citizen.Wait(10000)
local check, hash = GetCurrentPedWeapon(PlayerPedId(), 1)
local Ammo = GetAmmoInPedWeapon(PlayerPedId(), hash)
if Ammo == 0 then;
RemoveWeaponFromPed(PlayerPedId(), hash)
end;
end)
a = a
end
Citizen.CreateThread(function()
Citizen.Wait(2000)
local ped = PlayerPedId()
local check, hash = GetCurrentPedWeapon(ped, 1)
local ammo = GetAmmoInPedWeapon(ped, hash)
if ammo < 1 then
RemoveWeaponFromPed(ped, hash)
end
end)
I tested the below code on a server and it’s working the way you describe.
However, what it does is that it “unwields” the weapon while the ammo is 0.
If you fully want to remove the weapon then I assume you’d want to look into your framework of removing an item/weapon.
Citizen.CreateThread(function()
while true do
Citizen.Wait(5)
local ped = PlayerPedId()
if IsPedArmed(ped, 4|2) then
local check, hash = GetCurrentPedWeapon(ped, 1)
local ammo = GetAmmoInPedWeapon(ped, hash)
if ammo < 1 then
RemoveWeaponFromPed(ped, hash)
end
else
Citizen.Wait(100)
end
end
end)
So I tried the code it practically work but it doesn’t remove 100% the weapon off my inventory it is still a ghost in my inventory and I checked my framework in that case I got ESX but to use the
xPlayer.removeWeapon(weaponName)
and then now I require the weapon name do you think it would accept the hash or do I need to figure a way out how to get the weapon name?