Jump to content

How to keep weapon with no ammo


kewizzle

Recommended Posts

Heres what i tried

addEventHandler( "onWeaponFire", root, 
function () 
getPedTotalAmmo(source) 
if PedAmmo = 0 then 
getWeaponInSlot(1) or 
getWeaponInSlot(2) or 
getWeaponInSlot(3) or 
getWeaponInSlot(4) or 
getWeaponInSlot(5) or 
getWeaponInSlot(6) or 
getWeaponInSlot(7) or 
getWeaponInSlot(8) or 
getWeaponInSlot(9) or 
getWeaponInSlot(10) or 
getWeaponInSlot(11) or 
getWeaponInSlot(12) then 
giveWeapon(source, weapon, 0) 
end 
  

Link to comment
local invalidWeapons = -- Define a table with the weapons that won't be checked. 
    { 
        [ 0 ] = true, 
        [ 1 ] = true, 
        [ 2 ] = true, 
        [ 3 ] = true, 
        [ 4 ] = true, 
        [ 5 ] = true, 
        [ 6 ] = true, 
        [ 7 ] = true, 
        [ 8 ] = true, 
        [ 9 ] = true, 
        [ 10 ] = true, 
        [ 11 ] = true, 
        [ 12 ] = true, 
        [ 14 ] = true, 
        [ 15 ] = true, 
        [ 16 ] = true, 
        [ 17 ] = true, 
        [ 18 ] = true, 
        [ 39 ] = true, 
        [ 44 ] = true, 
        [ 45 ] = true, 
        [ 46 ] = true, 
        [ 40 ] = true 
    } 
  
addEventHandler ( "onClientPlayerWeaponFire", localPlayer, -- Add the event handler. 
    function ( weapon ) 
        if ( not invalidWeapons [ weapon ] ) then -- If the weapon the player used is not in the invalidWeapons table.. 
            if ( getPedTotalAmmo ( localPlayer ) == 1 ) then -- Check if the weapon ammo is equal to 1, then.. 
                toggleControl ( "fire", false ) -- Disable the fire control, so the player can no longer fire. 
            end -- End the ammo check 
        end -- End the invalid weapon check 
    end -- End the function 
) 
  
addEventHandler ( "onClientPlayerWeaponSwitch", localPlayer, -- Add the event handler. 
    function ( ) 
        toggleControl ( "fire", true ) -- Enable the fire control. 
        local weapon = getPedWeapon ( localPlayer ) -- Get the player current weapon. 
        if ( not invalidWeapons [ weapon ] ) then -- If the weapon the player is not in the invalidWeapons table..  
            if ( getPedTotalAmmo ( localPlayer ) == 1 ) then -- Check if the weapon ammo is equal to 1, then.. 
                toggleControl ( "fire", false ) -- Disable the fire control, so the player can no longer fire. 
            end -- End the ammo check 
        end -- End the invalid weapon check 
    end -- End the function 
) 

  • Like 1
Link to comment

Yes when i give the weapon back with ammo wont shoot till i switch weapons and switch back but thats okay whos gonna stay on the same weapon while having zombies chase them lol theyll probably switch weapons on the way to get ammo anyway but thanks works perfect and i understand the script now i read through it and the side notes.

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...