RU/createColTube: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
 
(2 intermediate revisions by the same user not shown)
Line 19: Line 19:
==Пример==
==Пример==


<section name="Сервер" class="server" show="true"> Этот пример выводит сообщение в чат, когда игрок входит в колшейп, и позволяет создать колшейп с помощью консольной команды ''set_zone''. <syntaxhighlight lang="lua"> local theZone
<section name="Сервер" class="server" show="true"> Этот пример выводит сообщение в чат, когда игрок входит в колшейп, и позволяет создать колшейп с помощью консольной команды ''set_zone''. <syntaxhighlight lang="lua">
local theZone
function shapeHit(thePlayer)
function shapeHit(thePlayer)
outputChatBox(getPlayerName(thePlayer).." вошёл в зону!")
  outputChatBox(getPlayerName(thePlayer).." вошёл в зону!")
end
end


function setZone(playerSource, commandName, fX, fY, fZ, fRadius, fHeight)
function setZone(playerSource, commandName, fX, fY, fZ, fRadius, fHeight)
local fX, fY, fZ, fRadius, fHeight = tonumber(fX), tonumber(fY), tonumber(fZ), tonumber(fRadius), tonumber(fHeight)
  local fX, fY, fZ, fRadius, fHeight = tonumber(fX), tonumber(fY), tonumber(fZ), tonumber(fRadius), tonumber(fHeight)
if (not fX) or (not fY) or (not fZ) or (not fRadius) or (not fHeight) then
  if (not fX) or (not fY) or (not fZ) or (not fRadius) or (not fHeight) then
outputChatBox("Синтаксис: /"..commandName.." [X] [Y] [Z] [Радиус] [Высота]", playerSource)
      outputChatBox("Синтаксис: /"..commandName.." [X] [Y] [Z] [Радиус] [Высота]", playerSource)
else
  else
if (theZone ~= nil) then
      if (theZone ~= nil) then
destroyElement(theZone)
        destroyElement(theZone)
end
      end
local tempCol = createColTube(fX, fY, fZ, fRaduis, fHeight)
      local tempCol = createColTube(fX, fY, fZ, fRaduis, fHeight)
addEventHandler("onColShapeHit", tempCol, shapeHit)
      addEventHandler("onColShapeHit", tempCol, shapeHit)
outputChatBox("Зона "..(theZone ~= nil and "перемещена" or "создана").."!", playerSource)
      outputChatBox("Зона "..(theZone ~= nil and "перемещена" or "создана").."!", playerSource)
theZone = tempCol
      theZone = tempCol
end
  end
end
end
addCommandHandler("set_zone", setZone, false, false)
addCommandHandler("set_zone", setZone, false, false)
Line 42: Line 43:


</section>
</section>
==Смотрите также==
==Смотрите также==
{{Функции формы столкновения}}
{{Collision shape functions}}


[[hu:createColTube]]
[[hu:createColTube]]
[[en:createColTube]]
[[en:createColTube]]

Latest revision as of 19:27, 6 August 2026

Эта функция создаёт трубку столкновений. Это форма, которая имеет позицию, двумерный (по X/Y) радиус и высоту. См. цилиндр для определения трубки. Трубка похожа на colcircle, но имеет ограниченную высоту, что позволяет ограничивать расстояние над позицией, заданной (fX, fY, fZ), на котором обнаруживается столкновение.

[[{{{image}}}|link=|]] Tip: To visualize a colshape when writing scripts, use the client console command showcol

Синтаксис

colshape createColTube ( float fX, float fY, float fZ, float fRadius, float fHeight )

OOP Syntax Help! I don't understand this!

Method: ColShape.Tube(...)


Обязательные аргументы

  • fX: Позиция центра основания трубки по оси X.
  • fY: Позиция центра основания трубки по оси Y.
  • fZ: Позиция центра основания трубки по оси Z.
  • fRadius: Радиус трубки столкновений.
  • fHeight: Высота трубки столкновений.

Возвращаемое значение

Возвращает элемент colshape в случае успеха, false в случае передачи неверных аргументов.

Пример

Click to collapse [-]
Сервер
Этот пример выводит сообщение в чат, когда игрок входит в колшейп, и позволяет создать колшейп с помощью консольной команды set_zone.
local theZone
function shapeHit(thePlayer)
   outputChatBox(getPlayerName(thePlayer).." вошёл в зону!")
end

function setZone(playerSource, commandName, fX, fY, fZ, fRadius, fHeight)
   local fX, fY, fZ, fRadius, fHeight = tonumber(fX), tonumber(fY), tonumber(fZ), tonumber(fRadius), tonumber(fHeight)
   if (not fX) or (not fY) or (not fZ) or (not fRadius) or (not fHeight) then
      outputChatBox("Синтаксис: /"..commandName.." [X] [Y] [Z] [Радиус] [Высота]", playerSource)
   else
      if (theZone ~= nil) then
         destroyElement(theZone)
      end
      local tempCol = createColTube(fX, fY, fZ, fRaduis, fHeight)
      addEventHandler("onColShapeHit", tempCol, shapeHit)
      outputChatBox("Зона "..(theZone ~= nil and "перемещена" or "создана").."!", playerSource)
      theZone = tempCol
   end
end
addCommandHandler("set_zone", setZone, false, false)

Смотрите также