Jump to content

Shooting script [SOLVED]


Swatrat

Recommended Posts

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 by Guest
Link to comment
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
  
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
  
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

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