Jump to content

Vehicle Missile (Infernus)


Bryton

Recommended Posts

Below is a simple code that allows all vehicles to fire missiles. How can we adjust this to make only 1 vehicle (Infernus: id 411) fire missiles.


local shootTimer = nil 
function shoot() 
        local vehicle = getPedOccupiedVehicle(localPlayer) 
            if not isElement(vehicle) then return end 
            if(not isTimer(shootTimer))then 
        local posX, posY, posZ = getElementPosition(vehicle) 
        shootTimer = setTimer(function()end, 5000, 1) 
        createProjectile(vehicle, 19, posX, posY, posZ, 1.0) 
    end 
end 
bindKey("vehicle_fire", "down", shoot) 
bindKey("vehicle_secondary_fire", "down", shoot) 

Link to comment

Welcome to the Forums!

To do that you will need to use getElementModel function to get vehicle's model ID.

Like this:

local shootTimer = nil 
function shoot() 
	local vehicle = getPedOccupiedVehicle(localPlayer)

	-- stop if "vehicle" is not an element or if its not infernus (411)
	if not isElement(vehicle) or getElementModel(vehicle) ~= 411 then
		return
	end
	
	if(not isTimer(shootTimer))then
		local posX, posY, posZ = getElementPosition(vehicle)
		shootTimer = setTimer(function()end, 5000, 1)
		createProjectile(vehicle, 19, posX, posY, posZ, 1.0)
	end
end
bindKey("vehicle_fire", "down", shoot)
bindKey("vehicle_secondary_fire", "down", shoot)

 

Edited by SpecT
  • Like 1
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...