Jump to content

[HELP] Modifying car shooting script


Recommended Posts

Hello everyone, I am new here, and also new to MTA scripting, so I was hoping that maybe some experienced scripters can help me with a small problem that I have.

I have a shoot.Lua script, that is used for [SHOOTER] gamemode/minigame, the script allows the cars to shoot rockets, and it is working ok, but I want to modify it a little, so that the rockets go faster and travel less distance, and also if it is possible to make the rockets go through objects (walls, ground...), and only hit and make damage to the cars (other players)?

I am including a video, so that you can see what I am trying to achieve, the first part of the video is from a SAMP server (faster rockets, less distance), and the second part is from MTA shoot.Lua script. The link to the video is: https://drive.google.com/file/d/1fhX6LXNca_ArJwfzhv9gwRL9N6jWDSma/view

 

And the code from shoot.Lua:

cLP = getLocalPlayer()
screenWidth, screenHeight = guiGetScreenSize()

function cRStest()
	setTimer(resourcesCheck, 10000, 1)
end
addEventHandler("onClientResourceStart", getRootElement(), cRStest)

function resourcesCheck()
	if check=="done" then return
	else
		setTimer(cbinds, 1000, 1)
		textToggle=0
		check="done"
	end
end

function cRS()
	if check=="done" then return
	else
		setTimer(cbinds, 3333, 1)
		textToggle=0
		check="done"
	end
end
addEventHandler("onClientPlayerSpawn", getLocalPlayer(), cRS)

function markers(player)
	if isPedInVehicle(player) then
		local vehicle = getPedOccupiedVehicle(player)
		fixVehicle(vehicle)
	end
end
addEventHandler("onClientMarkerHit", getResourceRootElement(getThisResource()), markers)

function cbinds()
	local keys1 = getBoundKeys("vehicle_fire")
	local keys2 = getBoundKeys("vehicle_secondary_fire")
	if keys1 then
		for keyName, state in pairs(keys1) do
			bindKey(keyName, "down", cdoshoot)
		end
		bindKey("F", "down", cdoshoot)
		cbindsText = "- Press F or the button you use to fire to shoot rockets!\n- You can shoot once every 3 seconds.\n- good luck and have fun!."
	end
	if keys2 then
		for keyName, state in pairs(keys2) do
			bindKey(keyName, "down", cdoshoot)
		end
	end
	if (not keys1) and (not keys2) then
		bindKey("F", "down", cdoshoot)
		bindKey("lctrl", "down", cdoshoot)
		bindKey("rctrl", "down", cdoshoot)
		cbindsText = "- Press F or CTRL to shoot rockets!\n- You can shoot once every 3 seconds."
	end
	theVehicle = getPedOccupiedVehicle(cLP)
	allowShoots()
	bindKey("K", "down", toggleText)
	outputChatBox("#FF3366Press K to show/hide instructions", 255, 255, 255, true)
end

function toggleText()
	if textToggle==0 then
		addEventHandler("onClientRender", getRootElement(), bindsText)
		textToggle=1
	elseif textToggle==1 then
		removeEventHandler("onClientRender", getRootElement(), bindsText)
		textToggle=0
	end
end

function allowShoots()
	bindTrigger = 1
end

function cdoshoot()
	if bindTrigger == 1 then
		if not isPedDead(cLP) then
			bindTrigger = 0
			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(allowShoots, 3000, 1)
		end
	end
end

function bindsText()
	dxDrawText(cbindsText, screenWidth/15, screenHeight/2.5, screenWidth, screenHeight, tocolor(0, 149, 254, 255), 0.75, "bankgothic")
end

 

Thanks in advance to everyone!

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