function disableGunOnSwitch ( prevSlot, newSlot )
local weaponID = getPedWeapon(getLocalPlayer(), newSlot)
outputChatBox(tostring(getPedAmmoInClip(getLocalPlayer(), newSlot)))
if ((getElementData(source, "cf:"..tostring(weaponID)) or getElementData(source, "r:cf:"..tostring(weaponID)) or getPedAmmoInClip(getLocalPlayer(), newSlot) < 20) and not (weaponID==2 or weaponID==3 or weaponID==4 or weaponID==5 or weaponID==6 or weaponID==7 or weaponID==9 or weaponID==15 or weaponID == 0)) then
outputChatBox("Should not fire")
toggleControl ("fire", false)
else
outputChatBox("Should fire")
toggleControl("fire", true)
end
end
addEventHandler ( "onClientPlayerWeaponSwitch", getLocalPlayer(), disableGunOnSwitch )
addEvent ( "onClientPlayerWeaponCheck", true )
addEventHandler ( "onClientPlayerWeaponCheck", getLocalPlayer(), disableGunOnSwitch )
This is the code. It should work but it doesn't. What the function should do is that it doesn't allow you to shoot when you have only one bullet left but it's not working. The conditions are working because the outputChatBox says "Should not fire" in the game but I can fire anyway. What am I doing wrong?