Jump to content

SetTimer problem [create vehicle script]


enzopaul4

Recommended Posts

function createVehicleForPlayer(thePlayer, command, vehicleModel)
	local x,y,z = getElementPosition(thePlayer)
	x = x + 5 
	local createdVehicle = createVehicle(tonumber(vehicleModel),x,y,z)
	if (createdVehicle == false) then
		outputChatBox("SYNTAX:/createvehicle [id]",thePlayer)
	end
end
addCommandHandler("createvehicle", createVehicleForPlayer)
setTimer ( createVehicleForPlayer, 1000, 1, "You cannot create a vehicle now!!Please try later again!" )

If i write in chat /createvehicle 410 it's spawn a manana but if i write again it is spawn me again one , what is wrong with setTimer ? 

Link to comment

Im not sure if you are trying to block the function to create vehicle during a second after creating one. In case of yes, try this

local allowedToSpawnVehicle = true

function createVehicleForPlayer(thePlayer, command, vehicleModel)
	if allowedToSpawnVehicle then
		local x,y,z = getElementPosition(thePlayer)
		x = x + 5 
		local createdVehicle = createVehicle(tonumber(vehicleModel),x,y,z)
		if (createdVehicle == false) then
			outputChatBox("SYNTAX:/createvehicle [id]",thePlayer)
		end
		allowedToSpawnVehicle = false
		blockerTime = setTimer(function()
		allowedToSpawnVehicle = true
		end,1000,1)
	else
		outputChatBox("You cannot create a vehicle now!!Please try later again!",thePlayer,255,255,255,true)
	end
	
end
addCommandHandler("createvehicle", createVehicleForPlayer)

It is not tested

Regards.

Link to comment
Just now, Overkillz said:

Im not sure if you are trying to block the function to create vehicle during a second after creating one. In case of yes, try this


local allowedToSpawnVehicle = true

function createVehicleForPlayer(thePlayer, command, vehicleModel)
	if allowedToSpawnVehicle then
		local x,y,z = getElementPosition(thePlayer)
		x = x + 5 
		local createdVehicle = createVehicle(tonumber(vehicleModel),x,y,z)
		if (createdVehicle == false) then
			outputChatBox("SYNTAX:/createvehicle [id]",thePlayer)
		end
		allowedToSpawnVehicle = false
		blockerTime = setTimer(function()
		allowedToSpawnVehicle = true
		end,1000,1)
	else
		outputChatBox("You cannot create a vehicle now!!Please try later again!",thePlayer,255,255,255,true)
	end
	
end
addCommandHandler("createvehicle", createVehicleForPlayer)

It is not tested

Regards.

It isn't working

i try to block it for 1 minute

Link to comment
local allowedToSpawnVehicle = true

function createVehicleForPlayer(thePlayer, command, vehicleModel)
	if allowedToSpawnVehicle then
		local x,y,z = getElementPosition(thePlayer)
		x = x + 5 
		if not vehicleModel then outputChatBox("SYNTAX:/createvehicle [id]",thePlayer)
		return 
		end
		createVehicle(tonumber(vehicleModel),x,y,z)
		allowedToSpawnVehicle = false
		blockerTime = setTimer(function()
		allowedToSpawnVehicle = true
		end,1000,1)
	else
		outputChatBox("You cannot create a vehicle now!!Please try later again!",thePlayer,255,255,255,true)
	end
	
end
addCommandHandler("createvehicle", createVehicleForPlayer)

Remember that it 1000 miliseconds is ONE second, so, be aware of it, I have changed something on the code, try it now.

Regards.

PS: The script is serverside

Link to comment
createdVehicle = { }
aVoidSpam = { }
function createVehicleForPlayer ( thePlayer,command,vehicleModel )
	if isTimer ( aVoidSpam[thePlayer] ) then return 
	outputChatBox ('You cannot create a vehicle now!!Please try later again!',thePlayer) end
	if not vehicleModel or not tonumber ( vehicleModel ) then return 
		outputChatBox("SYNTAX:/createvehicle [id]",thePlayer)
	end
	local x,y,z = getElementPosition(thePlayer)
	local createdVehicle[thePlayer] = createVehicle ( tonumber ( vehicleModel ),x+5,y,z )
	aVoidSpam[thePlayer] = setTimer ( function( thePlayer ) aVoidSpam [thePlayer] = nil end,1000,1,thePlayer ) 
end
addCommandHandler("createvehicle", createVehicleForPlayer)

 

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