Jump to content

Why the fricken frack is my script spawning 2 elements?


kewizzle

Recommended Posts

local spawnPoints = {
{ 416, 2066.1, 1396, 10.9, 0, 0, 127 },
{ 416, -678.5, 977.4, 12.1, 0, 0, 127 }
}

function createDrops()
	local random2 = math.random(1, #spawnPoints)
	supplyveh1 = createVehicle ( spawnPoints[random2][1], spawnPoints[random2][2], spawnPoints[random2][3], spawnPoints[random2][4], spawnPoints[random2][5], spawnPoints[random2][6], spawnPoints[random2][7])
	suppliez = createBlipAttachedTo( supplyveh1, 0 )
	outputChatBox("Supply Drop Spawned! Go capture it and return it to the safezone.", server, 0, 255, 0)
end

addEventHandler("onResourceStart", root, function()
	createDrops()
end)

addEventHandler("onVehicleEnter", root, function(thePlayer)
		if getPedOccupiedVehicle ( thePlayer ) == supplyveh1 then
			outputChatBox("You have collected the supplies! Get to the safezone!", root, 0, 255, 0)
			safeZone = createMarker ( -687.2, 956.5, 12.1, "corona", 4, 255, 0, 255, 255, thePlayer )
			addEventHandler("onMarkerHit", safeZone, function()
			destroyElement(safeZone)
			destroyElement(supplyveh1)
			destroyElement(suppliez)
			outputChatBox("Supplies have been delivered. New supplies spawn in 5 minutes.", server, 0, 255, 0)
			setTimer(createDrops, 300000, 1)
		end)
	end
end)

addEventHandler("onVehicleStartExit", root, function(thePlayer)
		if getPedOccupiedVehicle ( thePlayer ) == supplyveh1 then
		outputChatBox("Woah :O you need dem supplies! Get da :O back in da car hoe.", root, 0, 255, 0)
		destroyElement(safeZone)
	end
end)

SO YEAH WHAT THE FRICKEN FRACK AM I DOING WRONG HOMITO???? ahhhh essay? I KNOW HAAAH!!! its spawning two supplyveh1 after i deliver it to the drop off point safeZone and waiting 5 mins for the next to spawn.

Link to comment
  • Moderators

The 'onResourceStart' call when any resource started.

Delete this event and simply call the function, without event.

 

local spawnPoints = {
{ 416, 2066.1, 1396, 10.9, 0, 0, 127 },
{ 416, -678.5, 977.4, 12.1, 0, 0, 127 }
}

function createDrops()
	local random2 = math.random(1, #spawnPoints)
	supplyveh1 = createVehicle ( spawnPoints[random2][1], spawnPoints[random2][2], spawnPoints[random2][3], spawnPoints[random2][4], spawnPoints[random2][5], spawnPoints[random2][6], spawnPoints[random2][7])
	suppliez = createBlipAttachedTo( supplyveh1, 0 )
	outputChatBox("Supply Drop Spawned! Go capture it and return it to the safezone.", server, 0, 255, 0)
end
createDrops()

addEventHandler("onVehicleEnter", root, function(thePlayer)
		if getPedOccupiedVehicle ( thePlayer ) == supplyveh1 then
			outputChatBox("You have collected the supplies! Get to the safezone!", root, 0, 255, 0)
			safeZone = createMarker ( -687.2, 956.5, 12.1, "corona", 4, 255, 0, 255, 255, thePlayer )
			addEventHandler("onMarkerHit", safeZone, function()
			destroyElement(safeZone)
			destroyElement(supplyveh1)
			destroyElement(suppliez)
			outputChatBox("Supplies have been delivered. New supplies spawn in 5 minutes.", server, 0, 255, 0)
			setTimer(createDrops, 300000, 1)
		end)
	end
end)

addEventHandler("onVehicleStartExit", root, function(thePlayer)
		if getPedOccupiedVehicle ( thePlayer ) == supplyveh1 then
		outputChatBox("Woah :O you need dem supplies! Get da :O back in da car hoe.", root, 0, 255, 0)
		destroyElement(safeZone)
	end
end)

 

Link to comment
14 hours ago, Patrick2562 said:

The 'onResourceStart' call when any resource started.

Delete this event and simply call the function, without event.

 


local spawnPoints = {
{ 416, 2066.1, 1396, 10.9, 0, 0, 127 },
{ 416, -678.5, 977.4, 12.1, 0, 0, 127 }
}

function createDrops()
	local random2 = math.random(1, #spawnPoints)
	supplyveh1 = createVehicle ( spawnPoints[random2][1], spawnPoints[random2][2], spawnPoints[random2][3], spawnPoints[random2][4], spawnPoints[random2][5], spawnPoints[random2][6], spawnPoints[random2][7])
	suppliez = createBlipAttachedTo( supplyveh1, 0 )
	outputChatBox("Supply Drop Spawned! Go capture it and return it to the safezone.", server, 0, 255, 0)
end
createDrops()

addEventHandler("onVehicleEnter", root, function(thePlayer)
		if getPedOccupiedVehicle ( thePlayer ) == supplyveh1 then
			outputChatBox("You have collected the supplies! Get to the safezone!", root, 0, 255, 0)
			safeZone = createMarker ( -687.2, 956.5, 12.1, "corona", 4, 255, 0, 255, 255, thePlayer )
			addEventHandler("onMarkerHit", safeZone, function()
			destroyElement(safeZone)
			destroyElement(supplyveh1)
			destroyElement(suppliez)
			outputChatBox("Supplies have been delivered. New supplies spawn in 5 minutes.", server, 0, 255, 0)
			setTimer(createDrops, 300000, 1)
		end)
	end
end)

addEventHandler("onVehicleStartExit", root, function(thePlayer)
		if getPedOccupiedVehicle ( thePlayer ) == supplyveh1 then
		outputChatBox("Woah :O you need dem supplies! Get da :O back in da car hoe.", root, 0, 255, 0)
		destroyElement(safeZone)
	end
end)

 

Didn't solve my problem. Same exact thing happens, when i deliver the vehicle to the marker three things happen I want to fix.

outputChatBox("Supplies have been delivered. New supplies spawn in 5 minutes.", server, 0, 255, 0) appears twice

outputChatBox("Supply Drop Spawned! Go capture it and return it to the safezone.", server, 0, 255, 0) appears twice 

and then two supply vehicles appear.

Link to comment
  • Moderators

Try that:

 

local spawnPoints = {
	{416, 2066.1, 1396, 10.9, 0, 0, 127},
	{416, -678.5, 977.4, 12.1, 0, 0, 127},
}

local supplyVehicle = false
local supplyVehicle_blip = false
local supplyCollecter = false
local safeZone = false


function enterToSupplyVehicle(player, seat)
	if seat == 0 then
		outputChatBox("You have collected the supplies! Get to the safezone!", player, 0, 255, 0)
		supplyCollecter = player
		
		safeZone = createMarker(-687.2, 956.5, 12.1, "corona", 4, 255, 0, 255, 255, player)
		addEventHandler("onMarkerHit", safeZone, hitSafeZoneMarker)
		addEventHandler("onVehicleStartExit", supplyVehicle, exitFromSupplyVehicle)
	end
end

function exitFromSupplyVehicle(player)
	outputChatBox("Woah :O you need dem supplies! Get da :O back in da car hoe.", player, 0, 255, 0)
	
	resetAll()
end

function hitSafeZoneMarker(player)
	outputChatBox("Supplies have been delivered. New supplies spawn in 5 minutes.", root, 0, 255, 0)
	
	resetAll()
	setTimer(createDrops, 300000, 1)
end

function resetAll()
	removeEventHandler("onVehicleEnter", supplyVehicle, enterToSupplyVehicle)
	removeEventHandler("onVehicleStartExit", supplyVehicle, exitFromSupplyVehicle)
	removeEventHandler("onMarkerHit", safeZone, hitSafeZoneMarker)
	
	destroyElement(safeZone)
	destroyElement(supplyVehicle_blip)
	destroyElement(supplyVehicle)
	supplyCollecter = false
end

function createDrops()
	if not isElement(supplyVehicle) then
		local randomPoint = math.random(1, #spawnPoints)
		
		supplyVehicle = createVehicle(spawnPoints[randomPoint][1], spawnPoints[randomPoint][2], spawnPoints[randomPoint][3], spawnPoints[randomPoint][4], spawnPoints[randomPoint][5], spawnPoints[randomPoint][6], spawnPoints[randomPoint][7])
		supplyVehicle_blip = createBlipAttachedTo(supplyVehicle, 0)
		
		outputChatBox("Supply Drop Spawned! Go capture it and return it to the safezone.", root, 0, 255, 0)
		addEventHandler("onVehicleEnter", supplyVehicle, enterToSupplyVehicle)
	end
end
createDrops()

 

Edited by Patrick2562
  • Thanks 1
Link to comment
24 minutes ago, Patrick2562 said:

Try that:

 


local spawnPoints = {
	{416, 2066.1, 1396, 10.9, 0, 0, 127},
	{416, -678.5, 977.4, 12.1, 0, 0, 127},
}

local supplyVehicle = false
local supplyVehicle_blip = false
local supplyCollecter = false
local safeZone = false


function enterToSupplyVehicle(player, seat)
	if seat == 0 then
		outputChatBox("You have collected the supplies! Get to the safezone!", player, 0, 255, 0)
		supplyCollecter = player
		
		safeZone = createMarker(-687.2, 956.5, 12.1, "corona", 4, 255, 0, 255, 255, player)
		addEventHandler("onMarkerHit", safeZone, hitSafeZoneMarker)
		addEventHandler("onVehicleStartExit", supplyVehicle, exitFromSupplyVehicle)
	end
end

function exitFromSupplyVehicle(player)
	outputChatBox("Woah :O you need dem supplies! Get da :O back in da car hoe.", player, 0, 255, 0)
	
	resetAll()
end

function hitSafeZoneMarker(player)
	outputChatBox("Supplies have been delivered. New supplies spawn in 5 minutes.", root, 0, 255, 0)
	
	resetAll()
	setTimer(createDrops, 300000, 1)
end

function resetAll()
	removeEventHandler("onVehicleEnter", supplyVehicle, enterToSupplyVehicle)
	removeEventHandler("onVehicleStartExit", supplyVehicle, exitFromSupplyVehicle)
	removeEventHandler("onMarkerHit", safeZone, hitSafeZoneMarker)
	
	destroyElement(safeZone)
	destroyElement(supplyVehicle_blip)
	destroyElement(supplyVehicle)
	supplyCollecter = false
end

function createDrops()
	if not isElement(supplyVehicle) then
		local randomPoint = math.random(1, #spawnPoints)
		
		supplyVehicle = createVehicle(spawnPoints[randomPoint][1], spawnPoints[randomPoint][2], spawnPoints[randomPoint][3], spawnPoints[randomPoint][4], spawnPoints[randomPoint][5], spawnPoints[randomPoint][6], spawnPoints[randomPoint][7])
		supplyVehicle_blip = createBlipAttachedTo(supplyVehicle, 0)
		
		outputChatBox("Supply Drop Spawned! Go capture it and return it to the safezone.", root, 0, 255, 0)
		addEventHandler("onVehicleEnter", supplyVehicle, enterToSupplyVehicle)
	end
end
createDrops()


 

thanks ill use your example to learn from. works.

i see what you did here ;) neat

function createDrops()
	if not isElement(supplyVehicle) then
		local randomPoint = math.random(1, #spawnPoints)
		
		supplyVehicle = createVehicle(spawnPoints[randomPoint][1], spawnPoints[randomPoint][2], spawnPoints[randomPoint][3], spawnPoints[randomPoint][4], spawnPoints[randomPoint][5], spawnPoints[randomPoint][6], spawnPoints[randomPoint][7])
		supplyVehicle_blip = createBlipAttachedTo(supplyVehicle, 0)
		
		outputChatBox("Supply Drop Spawned! Go capture it and return it to the safezone.", root, 0, 255, 0)
		addEventHandler("onVehicleEnter", supplyVehicle, enterToSupplyVehicle)
	end
end
createDrops()

 

Link to comment
  • Moderators
8 minutes ago, kewizzle said:

thanks ill use your example to learn from. works.

i see what you did here ;) neat


function createDrops()
	if not isElement(supplyVehicle) then
		local randomPoint = math.random(1, #spawnPoints)
		
		supplyVehicle = createVehicle(spawnPoints[randomPoint][1], spawnPoints[randomPoint][2], spawnPoints[randomPoint][3], spawnPoints[randomPoint][4], spawnPoints[randomPoint][5], spawnPoints[randomPoint][6], spawnPoints[randomPoint][7])
		supplyVehicle_blip = createBlipAttachedTo(supplyVehicle, 0)
		
		outputChatBox("Supply Drop Spawned! Go capture it and return it to the safezone.", root, 0, 255, 0)
		addEventHandler("onVehicleEnter", supplyVehicle, enterToSupplyVehicle)
	end
end
createDrops()

 

 

You are wellcome! :D

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