RU/setGarageOpen

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Эта функция открывает, или закрывает определенную дверь гаража в игре.

Использование

bool setGarageOpen ( int garageID, bool open )

Необходимые параметры

  • garageID: ID гаража, дверь которого нужно открыть либо закрыть.
  • isOpen: параметр, указывающий на открытие либо закрытие двери данного гаража.

Что возвращается

Возвращается true, если действие произошло, или false, если был введен неправильный id гаража.

Пример

Click to collapse [-]
Сервер

В этом примере открывается дверь гаража, когда игрок соприкасается с ней, и закрывает её, когда игрок покидает гараж.

GARAGE_ID = 25

-- create a collision shape and attach event handlers to it when the resource starts
addEventHandler("onResourceStart", getResourceRootElement(getThisResource()),
function (resource)
	local garageCube = createColCube(1337, 194, 28, 6, 10, 4)
	addEventHandler("onColShapeHit", garageCube, onGarageCubeHit)
	addEventHandler("onColShapeLeave", garageCube, onGarageCubeLeave)
end)

-- open the door when someone enters the garage's collision shape
function onGarageCubeHit(hitElement, matchingDimension)
	if (getElementType(hitElement) == "player") then
		-- check to make sure the door is closed
		if (not isGarageOpen(GARAGE_ID)) then
			-- open the door
			setGarageOpen(GARAGE_ID, true)
		end
	end
end

-- close the door when someone leaves the garage's collision shape
function onGarageCubeLeave(leaveElement, matchingDimension)
	if (getElementType(leaveElement) == "player") then
		-- check to make sure the door is open
		if (isGarageOpen(GARAGE_ID)) then
			-- close the door
			setGarageOpen(GARAGE_ID, false)
		end
	end
end

Смотри также