Hero192 Posted January 23, 2016 Share Posted January 23, 2016 Hey all, I want to make If the police or LAWTEAM shooted a wanted player with taser the law team need to wait 2 secs to shoot the wanted player again, I tried that but not working fine and no errors on debug. local lawTeam = {["Police"]=true, ["SWAT"]=true} function onShoot(target, posX, posY, posZ) if (getPlayerTeam(localPlayer) and lawTeam[getTeamName(getPlayerTeam(localPlayer))]) then local wanted = getPlayerWantedLevel() if (wanted > 0) then if (source == 23) then setTimer(function() --HERE i don't know how to stop him shooting only with Silenced gun (ID23) end,2000,1) end end end end addEventHandler("onClientWeaponFire", root, onShoot) Link to comment
Army@1 Posted January 23, 2016 Share Posted January 23, 2016 Try this. local lawTeam = {["Police"]=true, ["SWAT"]=true} ostimer = true function onShoot(target, posX, posY, posZ) if (getPlayerTeam(localPlayer) and lawTeam[getTeamName(getPlayerTeam(localPlayer))]) then local wanted = getPlayerWantedLevel() if (wanted > 0) then if (source == 23) and ostimer == true then -- your code.... ostimer = false setTimer(function() ostimer = true end,2000,1) end end end end addEventHandler("onClientWeaponFire", root, onShoot) Link to comment
tosfera Posted January 23, 2016 Share Posted January 23, 2016 I don't think that's going to work. The wiki states: "Note: This event is only for custom weapons that were created with createWeapon, for player held weapons use onClientPlayerWeaponFire." Therefore the entire eventHandler is wrong, second of all. If a player fires a gun and it's streamed in, no one else will be able to shoot again since ostimer is set to true. I would go for an approach like this; local lawTeam = { [ "Police" ] = true, [ "SWAT" ] = true }; local timers = {} addEventHandler ( "onClientPlayerWeaponFire", getRootElement(), function ( weapon, ammo, _, posX, posY, posZ, target ) if ( getPlayerTeam ( source ) ) then if ( lawTeam [ getTeamName ( getPlayerTeam ( source ) ) ] ) then if ( weapon == 23 ) then if ( isTimer ( timers [ source ] ) ) then outputChatBox ( "Your tazer is still on cooldown.", source ); cancelEvent(); return; end timers [ source ] = setTimer ( function ( thePlayer ) timers [ thePlayer ] = nil; end, 2000, 1, source ); -- your code to "taze" the person end end end end ); Another thing you can do is disable the aim control for the time that the tazer has been disabled. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now