Jump to content

Vehicle spawner


Recommended Posts

Yes it is server side, I want to prevent a ambulance (416) to spawn inside the marker if a other player or vehicle is inside the marker.
How could I prevent this?

Spoiler

medicVehicleSpanwer = createMarker (1179.71, -1338.31, 13.00, "cylinder", 2, 255, 255, 255, 120)

local vehicleTable = {}

function giveAmbulance(hitElement, matchingDimension)
	if (getElementType (hitElement) == "player" and getTeamName(getPlayerTeam(hitElement)) == "Paramedic") then
		local theVehicle = getPedOccupiedVehicle (hitElement)
		if not theVehicle then
			local jobVehicle = vehicleTable[hitElement]
			if jobVehicle then
				if isElement(jobVehicle) then
					destroyElement(jobVehicle)
				end
				vehicleTable[hitElement] = nil
			end
			jobVehicle = createVehicle (416, 1179.71, -1338.31, 14.00, 0, 0, 270)
			setElementData (jobVehicle, "fuel", 100)
			warpPedIntoVehicle (hitElement, jobVehicle)
			vehicleTable[hitElement] = jobVehicle
		end
	end
end
addEventHandler ("onMarkerHit", medicVehicleSpanwer, giveAmbulance)

addEventHandler("onPlayerQuit", root,
function ()
    local jobVehicle = vehicleTable[source]
    if jobVehicle then
        if isElement(jobVehicle) then
            destroyElement(jobVehicle)
        end
        vehicleTable[source]= nil
    end
end)

 

 

Link to comment
  • Moderators
13 minutes ago, Potato_Tomato420 said:

How could I prevent this?

 

1. You can get the colshape of a marker.

https://wiki.multitheftauto.com/wiki/GetElementColShape

 

2. Get the elements of a specific type and check if there are none.

https://wiki.multitheftauto.com/wiki/GetElementsWithinColShape

 

 

local colshape = getElementColShape ( marker )

local players = getElementsWithinColShape ( colshape, "player" )
local vehicles = getElementsWithinColShape ( colshape, "vehicle" )
if #vehicles == 0 and #players == 0 then
  
end

 

Note: you might also need to check if the elements are not in the same dimension + interior, if you make use of those.

Edited by IIYAMA
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...