Amocheck?

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 in advance!

1 Like

Might want to actually type the native properly if you want it to work.

you mean this one?:

natives.WEAPON.GET_AMMO_IN_PED_WEAPON(plyPed, WeaponHash)  

Edit:

Ammo =natives.WEAPON.GET_AMMO_IN_PED_WEAPON(GetPlayerFromServerId(source), 0xFBA1FB98);

so I modified the script a little and now it seems to start properly but it doesn’t work how it should of worked :confused:

natives_universal.lua:

if Ammo == 0 then;
    REMOVE_WEAPON_FROM_PED(GetPlayerFromServerId(source), 0xFBA1FB98);
end;

fxmanifest.lua:

resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937'


fx_version 'adamant'
games { 'gta5' }

author 'yeetthispfp#6994'

client_scripts {
    'natives_universal.lua'
}

No, why are you trying to use the “raw” version of the native? This is why it’s not working…

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 :confused: (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 :confused: 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

Maybe something like this.

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)

Seems like it wouldn’t crash anymore but now I am at the start again and it doesn’t do jack :confused:

Just for me to understand.

When the ammo of the weapon that the player is holding is 0, the weapon should be removed?
Is that correct?

10-4 it should be removed when the players weapon reaches 0 but in that case as I tried it out and it reached 0 sadly nothing happend

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?