citizenfx / fivem

The source code for the Cfx.re modification frameworks, such as FiveM, RedM and LibertyM, as well as FXServer.
https://cfx.re/
3.58k stars 2.12k forks source link

Vehicle Weapon Ammo #2300

Open CaMoTraX opened 11 months ago

CaMoTraX commented 11 months ago

What happened?

SetVehicleWeaponCapacity and GetVehicleWeaponCapacity

Booth not working properly. Tried using them on a spawned vehicle and nothing worked. But when i put this code into a loop:

` Citizen.CreateThread(function()

while true do Wait(100)

    local ped = GetPlayerPed(-1)
    local veh = GetVehiclePedIsIn( ped, false )
    local slot, hash = GetCurrentPedVehicleWeapon( ped )

    SetVehicleWeaponCapacity(veh, slot, 100)
    print( GetVehicleWeaponCapacity( veh, slot ) )

end end) `

It sets the capacity to 100 ONCE, but it should refill it every 100ms. This also just work with the loop already running and then spawning the vehicle. It won't work on already spawned vehicles. GetVehicleWeaponCapacity also return wrong values.

Getting this fixed would be awesome, due i want to limit vehicle weapons ammo.

Expected result

SetVehicleWeaponCapacity(veh, slot, 100) = Ammo of that slot 100, no matter if already spawned.

Reproduction steps

Spawn a vehicle ( dune3 ) and get in.

Exececute: local ped = GetPlayerPed(-1) local veh = GetVehiclePedIsIn( ped, false ) local slot, hash = GetCurrentPedVehicleWeapon( ped )

SetVehicleWeaponCapacity(veh, slot, 10) print( GetVehicleWeaponCapacity( veh, slot ) )

It should return 10 ammo, try to shoot and get out of ammo. Check your ammo using the print. It will stay the same.

Importancy

Slight inconvenience

Area(s)

FiveM, OneSync, Natives

Specific version(s)

FiveM b2802, FXServer 6683

Additional information

No response

gottfriedleibniz commented 9 months ago

The issue here is that GetCurrentPedVehicleWeapon does not return the "weaponIndex" - it just returns true/false and the weapon hash. Neither of which can be used with GetVehicleWeaponCapacity/SetVehicleWeaponCapacity

Referencing the decompiled game scripts it seems everything is hard coded based on model, e.g., "if the model is dune3 let slot = 1". All of this data can be referenced from CVehicleWeaponHandlingData within the vehicles HandlingData, which, unfortunately cannot be accessed via native at this time.