Project-Sloth / ps-fuel

A NoPixel inspired functionality fuel system that uses PolyZones that target specific areas that allow you to have the abilitity to refuel your vehicles.
GNU General Public License v3.0
63 stars 48 forks source link

Jerry Cans not working as intended #60

Closed Nanorithm closed 3 months ago

Nanorithm commented 3 months ago

First of all, buying a jerry can gives me an item with 0 munitions in the metadata. When I'm refilling a jerrycan, it goes through the animation, and the metadata in the inventory does update to 4500, but when I go to use it on a car it is saying that it is empty. I tried debugging a bit myself and it seems that GetAmmoInPedWeapon(ped, 883325847) is returning 0 even though the can has 4500 munitions in metadata.

I provided a video of the issue here in case that was unclear.

Also as shown in the video, when pulling out a jerry can, it swaps the player back to unarmed and I have to do it twice. This actually only works when I manually restart qb-smallresources otherwise it is an endless loop of just dropping the prop on the ground.


For reference: My qb-weapons/client/main snippet:

CreateThread(function()
  while true do
      local ped = PlayerPedId()
      local idle = 1
      if (IsPedArmed(ped, 7) == 1 and (IsControlJustReleased(0, 24) or IsDisabledControlJustReleased(0, 24))) or IsPedShooting(PlayerPedId()) then
          local weapon = GetSelectedPedWeapon(ped)
          local ammo = GetAmmoInPedWeapon(ped, weapon)
          if weapon == GetHashKey("WEAPON_PETROLCAN")  then
              idle = 1000
          end
          TriggerServerEvent("weapons:server:UpdateWeaponAmmo", CurrentWeaponData, tonumber(ammo))
          if MultiplierAmount > 0 then
              TriggerServerEvent("weapons:server:UpdateWeaponQuality", CurrentWeaponData, MultiplierAmount)
              MultiplierAmount = 0
          end
      end
      Wait(idle)
  end
end)

My qb-smallresources/client/ignore snippet:

RegisterNetEvent('QBCore:Client:DrawWeapon', function()
  local sleep
  while true do
      sleep = 500
      local ped = PlayerPedId()
      local weapon = GetSelectedPedWeapon(ped)
      if weapon ~= `WEAPON_UNARMED` then
          if IsPedArmed(ped, 6) then
              sleep = 0
              DisableControlAction(1, 140, true)
              DisableControlAction(1, 141, true)
              DisableControlAction(1, 142, true)
          end

          if weapon == `WEAPON_FIREEXTINGUISHER` then
              if IsPedShooting(ped) then
                  SetPedInfiniteAmmo(ped, true, weapon)
              end
          end
      else
          break
      end
      Wait(sleep)
  end
end)

My qb-inventory/client/main snippet:

RegisterNetEvent('inventory:client:UseWeapon', function(weaponData, shootbool)
    local ped = PlayerPedId()
    local weaponName = tostring(weaponData.name)
    local weaponHash = joaat(weaponData.name)
    if currentWeapon == weaponName then
        SetCurrentPedWeapon(ped, `WEAPON_UNARMED`, true)
        RemoveAllPedWeapons(ped, true)
        TriggerEvent('weapons:client:SetCurrentWeapon', nil, shootbool)
        currentWeapon = nil
    elseif weaponName == "weapon_stickybomb" or weaponName == "weapon_pipebomb" or weaponName == "weapon_smokegrenade" or weaponName == "weapon_flare" or weaponName == "weapon_proxmine" or weaponName == "weapon_ball"  or weaponName == "weapon_molotov" or weaponName == "weapon_grenade" or weaponName == "weapon_bzgas" then
        GiveWeaponToPed(ped, weaponHash, 1, false, false)
        SetPedAmmo(ped, weaponHash, 1)
        SetCurrentPedWeapon(ped, weaponHash, true)
        TriggerEvent('weapons:client:SetCurrentWeapon', weaponData, shootbool)
        currentWeapon = weaponName
    elseif weaponName == "weapon_snowball" then
        GiveWeaponToPed(ped, weaponHash, 10, false, false)
        SetPedAmmo(ped, weaponHash, 10)
        SetCurrentPedWeapon(ped, weaponHash, true)
        TriggerServerEvent('inventory:server:snowball', 'remove')
        TriggerEvent('weapons:client:SetCurrentWeapon', weaponData, shootbool)
        currentWeapon = weaponName
    else
        TriggerEvent('weapons:client:SetCurrentWeapon', weaponData, shootbool)
        local ammo = tonumber(weaponData.info.ammo) or 0

        if weaponName == "weapon_fireextinguisher" then
          ammo = 4000
        end

        GiveWeaponToPed(ped, weaponHash, ammo, false, false)
        SetPedAmmo(ped, weaponHash, ammo)
        SetCurrentPedWeapon(ped, weaponHash, true)

        if weaponData.info.attachments then
            for _, attachment in pairs(weaponData.info.attachments) do
                GiveWeaponComponentToPed(ped, weaponHash, joaat(attachment.component))
            end
        end

        currentWeapon = weaponName
    end
end)

I am currently using the following related scripts:

I'm using v1.0.1 from the releases section.

MonkeyWhisper commented 3 months ago

Thanks, feel free to send a PR to fix this. This script is outdated and some small things like so will prob not work correctly after so many QBCore changes.

Nanorithm commented 3 months ago

I believe I was able to fix it, the only bug I'm running into is that I can't find a way to update the item durability when calling the ps-fuel:client:refuelCan event since it's possible the player can have multiple cans in their inventory and the wrong one could get updated, but it updates properly in all other instances. So as it stands now, it will have the old durability until the gas can is used again but the durability is directly linked to the percentage that the can is filled.

I'll make a PR when I clean up my code some more haha