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)

 

76561198387870432.png

ZI ZOMBIE INFECTION: mtasa://5.196.7.163:22003

560x95_FFFFFF_FF9900_000000_000000.png

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

6C73yFv.png

Did I help you?

Mmpe7Jm.gif


NeXuS™#0001

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

76561198387870432.png

ZI ZOMBIE INFECTION: mtasa://5.196.7.163:22003

560x95_FFFFFF_FF9900_000000_000000.png

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

6C73yFv.png

Did I help you?

Mmpe7Jm.gif


NeXuS™#0001

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?

76561198387870432.png

ZI ZOMBIE INFECTION: mtasa://5.196.7.163:22003

560x95_FFFFFF_FF9900_000000_000000.png

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

6C73yFv.png

Did I help you?

Mmpe7Jm.gif


NeXuS™#0001

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