Jump to content

not to takeweapon when ammo reaches 0


-Blaze-

Recommended Posts

Posted

You can do a check for ammo, if it's 0 then set it too 1 perhaps, except you'll have the problem that will be infinite ammo. but to cancel that you can say on weapon fire cancel if ammo is 1. so he can only shoot when ammo is more then 1.

Posted

you mean something like this?

   function donttakemygun() 
   local currentweapon = getPedWeapon (getLocalPlayer()) 
   local currentammo = getWeaponAmmo (currentweapon) 
   if (currentammo < 2) then 
   toggleControl ("fire", false ) -- disable the fire key 
   end 
   end 
   addEventHandler("onClientRender", getLocalPlayer(), donttakemygun) 

or

     function donttakemygun() 
    local currentammo = getPedTotalAmmo (getLocalPlayer()) 
   if (currentammo < 2) then 
   toggleControl ("fire", false ) -- disable the fire key 
   end 
   end 
   addEventHandler("onClientRender", getLocalPlayer(), donttakemygun) 

none of them seem to work.

Posted
you mean something like this?
   function donttakemygun() 
   local currentweapon = getPedWeapon (getLocalPlayer()) 
   local currentammo = getWeaponAmmo (currentweapon) 
   if (currentammo < 2) then 
   toggleControl ("fire", false ) -- disable the fire key 
   end 
   end 
   addEventHandler("onClientRender", getLocalPlayer(), donttakemygun) 

or

     function donttakemygun() 
    local currentammo = getPedTotalAmmo (getLocalPlayer()) 
   if (currentammo < 2) then 
   toggleControl ("fire", false ) -- disable the fire key 
   end 
   end 
   addEventHandler("onClientRender", getLocalPlayer(), donttakemygun) 

none of them seem to work.

You could try to use onClientPlayerWeaponFire handler and see how it works , i'm gonna give you 2 scripts and you-ll see what's better. onClientPlayerWeaponFire triggers the function every time the player shoots so its better in this situation.

#1 Uses toggleControl

function dontTakeMyGun() --the function 
local currentammo = getPedTotalAmmo(getLocalPlayer()) --set the variable "currentammo" 
    if (currentammo < 2) then --if ammo <2 then do 
        toggleControl ("fire", false ) --toggle bind 
    end 
end 
addEventHandler("onClientPlayerWeaponFire", getLocalPlayer(), dontTakeMyGun) --Triggers the function every time the peds fire 

#2 Uses cancelEvent (see the comment on it to see what it means)

function dontTakeMyGun() --the function 
local currentammo = getPedTotalAmmo(getLocalPlayer()) --set the variable "currentammo" 
    if (currentammo < 2) then --if ammo <2 then do 
        cancelEvent(true) --cancels the event which in this case is onClientPlayerWeaponFire so you can't shoot 
    end 
end 
addEventHandler("onClientPlayerWeaponFire", getLocalPlayer(), dontTakeMyGun) --Triggers the function every time the peds fire 

Posted

thanks ImSteady , the second one worked.

Yes TAPL , realized that when i tried it .

Umm, I lose my last shot when I aim and press tab.

Is there a way to stop that?

Posted
thanks ImSteady , the second one worked.

Yes TAPL , realized that when i tried it .

Umm, I lose my last shot when I aim and press tab.

Is there a way to stop that?

Tab is set to fire. Go to Settings>Binds and see Action: Tab, unbind it.

And what do you mean by

I lose my last shot
? You mean you can't shoot at 2 bullets left ?

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