Jump to content

Vehicle Zone


Recommended Posts

Posted

Hello guys, I have this script working fine, when you join with a vehicle to zone, it will be automatically respawned and you will get out of it

but when you are on zone, you can get into the vehicles, I want even when you are inside the zone and spawn a vehicle, you will can not use it

help please

Code

local myCol = createColRectangle (667.73, 1850.39, 50, 50)

function destroyTheVehicles (player)
	if getElementType (player) == "player" and isPedInVehicle (player) then
	local vehicle = getPedOccupiedVehicle(player)
		removePedFromVehicle(player)
		respawnVehicle(vehicle)
		outputChatBox ("Vehicles are not allowed here!", player, 255, 0, 0)
	end
end
addEventHandler ("onColShapeHit", myCol, destroyTheVehicles)

 

Posted
function cancelEnter(thePlayer)
	if isElementWithinColShape(thePlayer, myCol) then
		destroyElement(source)
		outputChatBox("Vehicles are not allowed here!", thePlayer, 255, 0, 0)
	end
end
addEventHandler("onVehicleStartEnter", root, cancelEnter)

Should work just fine.

  • Thanks 1
Posted (edited)
On 3/4/2018 at 18:53, TorNix~|nR said:

Hello guys, I have this script working fine, when you join with a vehicle to zone, it will be automatically respawned and you will get out of it

but when you are on zone, you can get into the vehicles, I want even when you are inside the zone and spawn a vehicle, you will can not use it

help please

Code


local myCol = createColRectangle (667.73, 1850.39, 50, 50)

function destroyTheVehicles (player)
	if getElementType (player) == "player" and isPedInVehicle (player) then
	local vehicle = getPedOccupiedVehicle(player)
		removePedFromVehicle(player)
		respawnVehicle(vehicle)
		outputChatBox ("Vehicles are not allowed here!", player, 255, 0, 0)
	end
end
addEventHandler ("onColShapeHit", myCol, destroyTheVehicles)

 

Working fine Thank you, but how can I make more cols, not just 1, I know I should use the table

but I don't know how? help please?

Edited by TorNix~|nR
Posted

Create more cols, add more event handlers with the new cols as the attached element, and in the onVehicleStartEnter event, write

isElementWithinColShape(...) or isElementWithinColShape(...) 

 

  • Thanks 1
Posted

I know I can use more event handlers, but I want to make it more easy, and not a big code

like this for example

local cols = {
{667.73, 1850.39, 50, 50}, -- First location
{1667.73, 1050.39, 100, 100}, -- Second location
}

but I don't know how to do it inside the code, help please?

Posted (edited)
local colPositions = {
	{667.73, 1850.39, 50, 50},
	{1667.73, 1050.39, 100, 100},
}

local createdCols = {}

for i, k in pairs(colPositions) do
	local tCol = createColRectangle(k[1], k[2], k[3], k[4]) -- Creating the col at the position with the fix width and height.
	addEventHandler("onColShapeHit", tCol, destroyTheVehicles) -- Adding the "onColShapeHit" event to the created col.
	table.insert(createdCols, tCol) -- Adding the created col to the "createdCols" table.
end

function cancelEnter(thePlayer)
	for i, k in pairs(createdCols) do -- Looping through the created cols.
		if isElementWithinColShape(thePlayer, k) then -- Checking if the player is inside one.
			destroyElement(source) -- If he is.
			outputChatBox("Vehicles are not allowed here!", thePlayer, 255, 0, 0)
			break
		end
	end
end
addEventHandler("onVehicleStartEnter", root, cancelEnter)

function destroyTheVehicles(player)
	if getElementType(player) == "player" and isPedInVehicle(player) then
		local vehicle = getPedOccupiedVehicle(player)
		removePedFromVehicle(player)
		respawnVehicle(vehicle)
		outputChatBox("Vehicles are not allowed here!", player, 255, 0, 0)
	end
end

Just so you understand, this is the last full code I provide you. From now-on, I'll only tell you what functions you'll need, and if you can't find the right way, I'll ONLY push you.

Edited by NeXuS™
  • Thanks 1

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