Jump to content

Automatically reload the weapon


Recommended Posts

Client-Side:
 

-- Function to check ammo and reload
function checkAmmoAndReload()
    -- Get the player's current weapon
    local weapon = getPedWeapon(localPlayer)
    
    -- Get the ammo in the player's clip
    local ammoInClip = getPedAmmoInClip(localPlayer)
    
    -- Get the total ammo the player has for the current weapon
    local totalAmmo = getPedTotalAmmo(localPlayer)
    
    -- If the clip is empty but the player has more ammo, reload the weapon
    if ammoInClip == 0 and totalAmmo > 0 then
        triggerServerEvent("onPlayerReloadWeapon", localPlayer)
    end
end

-- Event handler for when the player fires a weapon
addEventHandler("onClientPlayerWeaponFire", localPlayer, checkAmmoAndReload)

Server-Side:
 

-- Event to handle weapon reloading
addEvent("onPlayerReloadWeapon", true)
addEventHandler("onPlayerReloadWeapon", root, function()
    -- Get the player's current weapon
    local weapon = getPedWeapon(source)
    
    -- Reload the weapon
    setPedWeaponSlot(source, getPedWeaponSlot(source))
end)

 

I don't know if it's working, I just asked DeepSeek and this is the result.. Have fun :)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...