Jump to content

Save Weapon


Recommended Posts

Posted
can you give us more info what do you want to do ?

when the weapon bullets is 0 ....it disappear...so he want to keep the weapon with the player when the weapon bullets is 0

2vjs7it.jpg
Posted

just you need to check everytime when they use the weapon to see if the ammo is 1, if yes just disable the fire control.

Note : you need to do the same thing when they switch weapons.

So all what you need is

onClientPlayerWeaponFire 
onClientPlayerWeaponSwitch 
getPedTotalAmmo() 
toggleControl() 

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

Posted
just you need to check everytime when they use the weapon to see if the ammo is 1, if yes just disable the fire control.

Note : you need to do the same thing when they switch weapons.

So all what you need is

onClientPlayerWeaponFire 
onClientPlayerWeaponSwitch 
getPedTotalAmmo() 
toggleControl() 

Why when 1 ammo?

Just check when the weapon is gone, client side with onClientRender. ToggleControl -> add ammo for that weapon. Pretty simple and better.

Posted

Why you need to use "onClientRender" event simply it can be done using this two events "onClientPlayerWeaponFire" and

"onClientPlayerWeaponSwitch" .

-- Example

addEventHandler ( "onClientPlayerWeaponFire", localPlayer,  
    function ( weapon ) 
        if ( getPedTotalAmmo ( localPlayer ) == 1 ) then  
            toggleControl ( "fire", false )  
        end  
    end  
) 
  
addEventHandler ( "onClientPlayerWeaponSwitch", localPlayer,  
    function ( ) 
        toggleControl ( "fire", true )  
        if ( getPedTotalAmmo ( localPlayer ) == 1 ) then  
            toggleControl ( "fire", false )  
        end  
    end  
) 

Do not yield your back to your enemy, might feel something strange in your ass.

Two things are infinite the universe and human stupidity and i'm not sure about the universe.

UF: IsTextInGridList | GetGridListRowIndexFromText | Table.removeValue | removeHex | dxDrawTriangle

Skype: SaSuki102 | About Me | Youtube channel | Lua Tips & Tricks | Lua Strings | Lua Tables | Lua Operators

  • Moderators
Posted

Doesn't work with all weapons, some weapons (minigun/spray can) do have a fire rate of 1 bullet per frame. They will always fire 1 more bullet ahead of the toggleControl block.

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

Posted

Why when 1 ammo?

Just check when the weapon is gone, client side with onClientRender. ToggleControl -> add ammo for that weapon. Pretty simple and better.

Yeah, better to run it 30-60 times per second than once every time he tries to fire. :roll:

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

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