콘텐츠로 건너뛰기
라이엇 비트

라이엇 비트

  • 집
  • 소식
  • 가이드
  • 비디오 가이드
  • 패치 노트
  • 남용 신고
  • 검색 양식 전환
Tabletop Simulator

Tabletop Simulator – Trigger Game Action by Placing a Piece on a Tile

에 게시됨 04/10/202204/10/2022 에 의해 CareyMcDuff 코멘트 없음 ~에 Tabletop Simulator – Trigger Game Action by Placing a Piece on a Tile
  • 제목: Tabletop Simulator
  • 출시일:
  • 개발자:
  • 발행자:
Information about Tabletop Simulator is still incomplete. 이것을 사용하여 게임의 세부 정보를 입력할 수 있도록 도와주세요. 문의 양식.

Instead of using a button to trigger a script action, simulate the board game environment by triggering a script action by placing a game piece on a tile.

This intermediate guide assumes basic knowledge of lua scripting.

대개, a mod will use a button to trigger a script action. This works well, but is not in keeping with TTS as a simulation of a board game.

Another approach is to use a custom tile or token. The player can trigger a script action by placing a specific game piece on the tile.

Basic Approach

This approach uses the onCollisionEnter() 기능. If this function is included in the object script attached to the tile, it will be called every time a game piece makes contact with the tile.

The onCollisionEnter() function must be in the object script for the tile. It will not work if it is in the global script.

A simple function looks like this:

function  onCollisionEnter(collision_info)
  -- collision_info table:
  -- collision_object    Object
  -- contact_points      Table     {벡터, ...}
  -- relative_velocity   Vector
  local piece = 'guidaa' -- the guid of the piece that triggers the action
  local guid = collision_info.collision_object.getGUID()
  if guid == piece then
    return Global:부르다('desiredAction') -- string name of the function to be called
  end
end


Note that the function is called any time that any object makes contact with the tile, so the first step of the function must be to check if the object making contact is the one that should trigger the action.

Instead of using the guid to identify the object making contact, you could use the object’s name, description or gmnotes using getName(), getDescription() or getGMNotes() in place of getGUID().

Different Pieces Trigger Different Actions

To take this approach a step further, you could set up different game pieces that trigger different actions when they are placed on the tile.

Use a function like this:

function  onCollisionEnter(collision_info)
  local piece = {['guidaa'] = 1, ['guidbb'] = 2, ['guidcc'] = 3}
  -- guids as keys in the table are easier to check
  local guid = collision_info.collision_object.getGUID()
  local somedata
  -- somedata to pass to the Global script,
  -- 예를 들어. the action to trigger
  -- include somedata as values in piece{}
 if piece[guid] then
    somedata = piece[guid]
    -- pass somedata to the Global script
    return Global:부르다('desiredAction', {somedata})
  end
end

Trigger Different Actions by Location Placed

Going further, you could also set up the tile so that the player can trigger different actions by placing a game piece on different places on the game tile.

예를 들어, you could design the image for the tile to be divided into four quadrants.

This function triggers different actions depending on which quadrant of the tile is contacted.

function  onCollisionEnter(collision_info)
  local piece = 'guidaa'
  -- shorthand reference to the contacting obj
  local obj = collision_info.collision_object
  local guid = obj.getGUID()
  local somedata
  if guid == piece then
    -- find the midpoint between contact points
    local hit1 = self.positionToLocal(obj.contact_points[1] or obj.contact_points[3])
    local hit3 = self.positionToLocal(obj.contact_points[3] or obj.contact_points[1])
    -- use 'or' in case the piece is not entirely on the tile
    local hitx = (hit1.x+hit3.x)/2
    local hitz = (hit1.z+hit3.z)/2
    -- typically, you could divide the tile into quarters using the x and z coordinates
    if hitz < 0 then if hitx > 0 then
        somedata = 1
      else
        somedata = 2
      end
    else
      if hitx > 0 then
        somedata = 3
      else
        somedata = 4
      end
    end
    -- pass somedata to the Global script
    return Global:부르다('desiredAction', {guid, somedata})
  end
end


This last step can be tricky, because it is not always intuitive how the x,와이,z coordinates in TTS are determined. 예를 들어, it can depend on how the tile is rotated or flipped. You may need to experiment a bit. You could add the line log(hitx..” “..hitz) to the function to output the values to the console as you experiment.

변화

The purpose of the approach described here is to trigger a game action when a player places a relevant piece on the tile. That is why this approach uses the onCollisionEnter() 기능.

If instead you want the function to activate only when it is called in the script, you could use a slightly different approach. 예를 들어, you may want the script to check an option that a player has chosen. The guide linked below describes that approach.

문제 해결

그만큼 onCollisionEnter() function may be triggered multiple times if a piece jostles against the tile. A fix for this is to avoid triggering the function if not enough time has passed since the tile was last contacted. 이를 수행하려면, include this code at the beginning of the function.

if Time.time - (seconds or 0) < 1 then
  return
else
  seconds = Time.time
end

Note that the variable for seconds has to be a global variable. 그렇지 않은 경우, it may be reset every time the function is called. Watch out for conflicts with other global variables.

이것이 오늘 우리가 공유하는 모든 것입니다. Tabletop Simulator 가이드. 이 가이드는 원래 작성자가 작성하고 작성했습니다. CareyMcDuff. 이 가이드를 업데이트하지 못한 경우, 다음을 수행하여 최신 업데이트를 찾을 수 있습니다. 링크.

이 사이트의 콘텐츠가 귀하의 권리를 침해한다고 생각하는 경우, 귀하의 지적 재산권을 포함하여, 문의 양식을 사용하여 즉시 문의하십시오..
가이드 태그:Tabletop Simulator

탐색 후

이전 게시물: 레고 스타 워즈 스카이 워커 사가 – Easy Stud Farming Guide
다음 게시물: Tabletop Simulator – Use Description to Show Objects Beneath an Object

답장을 남겨주세요 답장 취소

귀하의 이메일 주소는 공개되지 않습니다. 필수 입력란이 표시되어 있습니다 *

  • 제목: Tabletop Simulator
  • 출시일:
  • 개발자:
  • 발행자:
Information about Tabletop Simulator is still incomplete. 이것을 사용하여 게임의 세부 정보를 입력할 수 있도록 도와주세요. 문의 양식.

부인 성명

인용된 모든 콘텐츠는 해당 소스에서 파생됩니다.. 귀하의 콘텐츠를 허가 없이 사용했다고 생각되는 경우, 우리에게 연락하면 진지하게 받아 들일 것입니다..
  • 회사 소개
  • 문의하기
  • 개인 정보 정책
  • 서비스 약관

저작권 © 2025 라이엇 비트.

에 의해 구동 프레스북 뉴스 WordPress 테마