Swatrat Posted March 22, 2014 Share Posted March 22, 2014 (edited) Hello, I'm still newbie in LUA scripting and I was searching how to disable shooting for 10 seconds in the beginning. The problem is that you can shoot when you're freezed for the start and I don't know how to disable it. I was searching everywhere but badly, I didn't find anything so if anyone can help me with disabling it in the first 10 seconds of the map I will be very thankful! Script: local shootingAllowed = true function playerSpawn() shootingAllowed = true end addEventHandler("onClientPlayerSpawn", getLocalPlayer(), playerSpawn) function doShoot() if shootingAllowed == true then if not isPlayerDead(getLocalPlayer()) then shootingAllowed = false local theVehicle = getPedOccupiedVehicle(getLocalPlayer()) local x,y,z = getElementPosition(theVehicle) local rX,rY,rZ = getElementRotation(theVehicle) local x = x+4*math.cos(math.rad(rZ+90)) local y = y+4*math.sin(math.rad(rZ+90)) createProjectile(theVehicle, 19, x, y, z, 1.0, nil) setTimer(allowShooting, 3000, 1) end end end function allowShooting() shootingAllowed = true end for keyName, state in pairs(getBoundKeys("fire")) do bindKey(keyName, "down", doShoot) end Edited March 22, 2014 by Guest Link to comment
Saml1er Posted March 22, 2014 Share Posted March 22, 2014 Replace this with line 18. setTimer(allowShooting, 10000, 1) 1000 milliseconds = 1 seconds 3000 milliseconds = 3 seconds 10000 milliseconds = 10 seconds Link to comment
Swatrat Posted March 22, 2014 Author Share Posted March 22, 2014 Replace this with line 18. setTimer(allowShooting, 10000, 1) 1000 milliseconds = 1 seconds 3000 milliseconds = 3 seconds 10000 milliseconds = 10 seconds That's for rocket timing. It means that I can shoot one rocket in 10 seconds. I want to disable the shooting for the first 10 seconds not to make it 10 secs = 1 rocket Link to comment
pa3ck Posted March 22, 2014 Share Posted March 22, 2014 Just create a timer for 10 seconds as soon as you spawn and check if the timer is still going ( isTimer ) and don't allow the player to shoot if the timer is still on. Link to comment
cheez3d Posted March 22, 2014 Share Posted March 22, 2014 local shootingAllowed = false function playerSpawn() setTimer(function() shootingAllowed = true end,10000,1) end addEventHandler("onClientPlayerSpawn", getLocalPlayer(), playerSpawn) function doShoot() if shootingAllowed == true then if not isPlayerDead(getLocalPlayer()) then shootingAllowed = false local theVehicle = getPedOccupiedVehicle(getLocalPlayer()) local x,y,z = getElementPosition(theVehicle) local rX,rY,rZ = getElementRotation(theVehicle) local x = x+4*math.cos(math.rad(rZ+90)) local y = y+4*math.sin(math.rad(rZ+90)) createProjectile(theVehicle, 19, x, y, z, 1.0, nil) setTimer(allowShooting, 3000, 1) end end end function allowShooting() shootingAllowed = true end for keyName, state in pairs(getBoundKeys("fire")) do bindKey(keyName, "down", doShoot) end Link to comment
Swatrat Posted March 22, 2014 Author Share Posted March 22, 2014 local shootingAllowed = false function playerSpawn() setTimer(function() shootingAllowed = true end,10000,1) end addEventHandler("onClientPlayerSpawn", getLocalPlayer(), playerSpawn) function doShoot() if shootingAllowed == true then if not isPlayerDead(getLocalPlayer()) then shootingAllowed = false local theVehicle = getPedOccupiedVehicle(getLocalPlayer()) local x,y,z = getElementPosition(theVehicle) local rX,rY,rZ = getElementRotation(theVehicle) local x = x+4*math.cos(math.rad(rZ+90)) local y = y+4*math.sin(math.rad(rZ+90)) createProjectile(theVehicle, 19, x, y, z, 1.0, nil) setTimer(allowShooting, 3000, 1) end end end function allowShooting() shootingAllowed = true end for keyName, state in pairs(getBoundKeys("fire")) do bindKey(keyName, "down", doShoot) end Thank you bro! Thats working perfectly! 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