Jump to content

How to block a gun's fire without reload


Hero192

Recommended Posts

Hello everyone, anyone can give me a hand on this

I've scripted a tazer system but I just want to block the tazer(silenced) shoot untill the timers end whole code is fine exept this line cause bug , the bug is the cop need to reload the gun but I won't that, I just want to block is fire for a moment then make him able to shoot without RELOAD

--Server side:(because the system is scripted in server side)

if (isTimer (timers[source] )) then  
--WHAT I've to add here ? to "BLOCK" the Silenced gun fire without letting the cop reload for shoot 
return outputChatBox("Your tazer is still on cooldown.", attacker, 255,0,0)  
end 

I won't use toggleControl fire, because the cop will be forced to RELOAD.

~Regards, much thanks !

Link to comment

Okay i'll try, I still have one more problem, It's about sound client side,

I want the sound plays for 5 seconds the normal sound time is about 1 or 2 seconds,

I tried that but not working just plays it for the normal fire timer

function onTaserSound(attacker) 
   local sound = playSound("taser/Fire.wav") 
   outputDebugString("Sound started.", 3) -- This message appear 
   setSoundVolume(sound, 0.5) 
   setTimer ( function() 
   if sound and isElement(sound) then 
   outputDebugString("sound will be stopped after 4secs.", 3) --This doesn't appear in debugscript 3 
        stopSound(sound) 
        end 
    end, 5000, 1) 
end     
addEvent("onStartTaserSound", true) 
addEventHandler("onStartTaserSound", localPlayer, onTaserSound) 

Link to comment
Nope, you should cancel it client sided too. Create a new function in your client with "onClientPlayerDamage" ( or something like that ) and do the same checks, if the weapon is 23 and the shooter is a cop, just cancel the event.

I did that, but If I canceled the event, the cop can't even tase wanted, and I need to cancel the fire only if the timer is still running.

Any idea?

if (isTimer (timers[source] )) then --If the timer still running then let's block cop tazer's fire 
--WHAT I've to add here ? to "BLOCK" the Silenced gun fire without letting the cop reload for shoot 
end 

Link to comment

Listen ,I have already the timer in server side which this code is part of server side so it's hard to check a timer in client side that it's already created in server side.

SO, is there's anyway to Block the fire I won't cancel the Event and there's a way I saw it in many servers blocking weapon fires without reloading then when the timer ends the weapon can shoot normal

if (isTimer (timers[source] )) then --If the timer still running then 
--Add the func that block the fire  
end 

Link to comment
Nope, you should cancel it client sided too. Create a new function in your client with "onClientPlayerDamage" ( or something like that ) and do the same checks, if the weapon is 23 and the shooter is a cop, just cancel the event.

I did that, but If I canceled the event, the cop can't even tase wanted, and I need to cancel the fire only if the timer is still running.

Any idea?

If you only cancel the damage for the player client sided, the player can still shoot the tazer. If you do want the player to get damage when the tazer is attached to his body and destroys every little living thing inside of him. You can always set the health of the player with setElementHealth. Remember, you should cancel the onClientPlayerDamage.

Link to comment
Nope, you should cancel it client sided too. Create a new function in your client with "onClientPlayerDamage" ( or something like that ) and do the same checks, if the weapon is 23 and the shooter is a cop, just cancel the event.

I did that, but If I canceled the event, the cop can't even tase wanted, and I need to cancel the fire only if the timer is still running.

Any idea?

If you only cancel the damage for the player client sided, the player can still shoot the tazer. If you do want the player to get damage when the tazer is attached to his body and destroys every little living thing inside of him. You can always set the health of the player with setElementHealth. Remember, you should cancel the onClientPlayerDamage.

What he is trying is to stop a player from shooting the taser but still be able to shoot other weapons WITHOUT the use of cancelEvent or toggleControl. I'd honestly do it with a cancelEvent if I was making it.

Link to comment
So Anyone knows how to handle it?

The best way to do it is just use cancelEvent anyhow.

Okay, Can you help me to do it?

because I am scripting the tazer system in server side and the timer is in server side onPlayerDamage Event so how can I use cancelEvent and this event doesn't accept cancelEvent.

And if I used cancelEvent in client I need to get the timer from server side to client side to check it and cancel the event, SO what can I do in this situation?

Link to comment
Try this way maybe
local shotAlready = false 
  
addEventHandler("onClientPlayerWeaponFire", getRootElement(), function() 
   if shotAlready then 
      cancelEvent() 
   else 
      shotAlready = true 
      setTimer( function() 
         shotAlready = false 
      end, 5000, 1) 
end) 

Just use this one, timer is included so no need for that other timer.

Link to comment

You don't want to use client-side because you're using timers[player] = setTimer(function() end,time,1) ?

You can do this instead

setElementData(player,"gunBlock",true)

timers[player] = setTimer(setElementData,time,1,player,"gunBlock",false)

And like that you wont need to get the timer from server-side to client-side

I'm not sure if I can help you with codes because I don't know how your codes works exactly and what you're actually doing

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