Jump to content

make rifle reload slower


Fist

Recommended Posts

Or disable the "fire" when he try to shut during the dalay

 

You'll need these functions :


event :  "onPlayerWeaponFire" -- when a player shoots
setTimer() -- to set a delay (1000 for 1 seconde)
setControlState() -- to disable the  fire when he shoots
setElementData() 
getElementData()
event : "onPedWeaponSwitch" -- Like this, the player can shoot with others weapons  during the delay 

-- Don't forget to set back off the control state when he re-switch to the rifle

Good luck 9_9

Edited by Gordon_G
Link to comment
19 minutes ago, Gordon_G said:

Or disable the "fire" when he try to shut during the dalay

 

You'll need these functions :


event :  "onPlayerWeaponFire" -- when a player shoots
setTimer() -- to set a delay (1000 for 1 seconde)
setControlState() -- to disable the  fire when he shoots
setElementData() 
getElementData()
event : "onPedWeaponSwitch" -- Like this, the player can shoot with others weapons  during the delay 

-- Don't forget to set back off the control state when he re-switch to the rifle

Good luck 9_9

yeah ik that be actually easier, but it doesn't look that good 'cause it will show in hud that it reloaded but you still can't shoot. By the way, you know how i can add fake bullet into gun when he runs out of ammo ? That fake bullet wouldn't be possible to shoot but just for that you still could hold empty gun in your hands.

@NeXuS™ @Gordon_G i tried like this but it gives me warning that it expected element at first argument of setWeaponAmmo. Weird...

addEventHandler("onPlayerWeaponFire", root, function(weapon)
	if (weapon == 33) then
		if isTimer(delay_timer) then killTimer(delay_timer) end
		local o_ammo = getPedTotalAmmo(source,33);
		local delay_timer = setTimer(function(source)
			setWeaponAmmo(source,33,o_ammo,0);
		end,500,0);
		setTimer(function(source)
			if isTimer(delay_timer) then killTimer(delay_timer) end
		end,1000,1);
	end
end);

 

Edited by Fist
Link to comment
5 minutes ago, Gordon_G said:

Oh, i'm so stupid. 

Do it client-sided, it will be easier I think because no need to killTimer...


"onClientPlayerWeaponFire"
"onClientPlayerWeaponSwitch"

 

i tried both sides, almost same problem. I can't set ammo it says i'm giving invalid source or weapon.

Link to comment
function rifleReloadCheck(_,weapon)
if weapon ~= 33 then toggleControl ( "fire", true ) else toggleControl ( "fire", false ) end -- check if the player  have a rifle in hands during the reloading, if it's not, enable the control state, else, disable
end

function rifleReloadTime(weapon,ammo)
  if weapon == 33 then -- Check player's weapon
    toggleControl ( "fire", false ) -- disable the shoot
    addEventHandler("onClientPlayerWeaponFire", getLocalPlayer(),rifleReloadCheck) -- add a check to avoid the player can't shot with other weapon during reloading
    setTimer(function(source) -- Timer to disable the  check, and toggle back the fire control
      toggleControl ( "fire", true )
      removeEventHandler( "onClientPlayerWeaponFire", getLocalPlayer(), rifleReloadCheck)
    end,1000,1,source)
  end
end
addEventHandler("onClientPlayerWeaponFire", getlocalPlayer(), rifleReloadTime)

I did'nt try but, I think it's correct

@Fist

Edited by Gordon_G
Link to comment
37 minutes ago, Gordon_G said:

function rifleReloadCheck(_,weapon)
if weapon ~= 33 then toggleControl ( "fire", true ) else toggleControl ( "fire", false ) end -- check if the player  have a rifle in hands during the reloading, if it's not, enable the control state, else, disable
end

function rifleReloadTime(weapon,ammo)
  if weapon == 33 then -- Check player's weapon
    toggleControl ( "fire", false ) -- disable the shoot
    addEventHandler("onClientPlayerWeaponFire", getLocalPlayer(),rifleReloadCheck) -- add a check to avoid the player can't shot with other weapon during reloading
    setTimer(function(source) -- Timer to disable the  check, and toggle back the fire control
      toggleControl ( "fire", true )
      removeEventHandler( "onClientPlayerWeaponFire", getLocalPlayer(), rifleReloadCheck)
    end,1000,1,source)
  end
end
addEventHandler("onClientPlayerWeaponFire", getlocalPlayer(), rifleReloadTime)

I did'nt try but, I think it's correct

@Fist

ehh ok, this will do ok for 1sec delay you can't notice anyway that it does actually load ammo. Thanks!

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