スクリプト2

引用元:http://steamcommunity.com/sharedfiles/filedetails/?id=752690530
必要そうなところだけ抜粋↓ 機能別のスクリプト解説

  Function: この機能が何をするかの説明。必要な入力/入力のタイプをとります。
  Returns:生成された出力/出力のタイプ。
  Example Input:関数に与えることができるフィールドの型の例
  Example Output:関数が結果として返す例
(各例文の最初にある説明項目)


   スクリプトでデッキゾーンからデッキの名前を抽出して、チャット欄に表示させるには、
function onload()
   local deckInZone = findDeckInZone(getObjectFromGUID("######"))
   print(deckInZone.getName())
end
   と、書きます。


ゾーン内のシングルデッキ/置物/トークン/その他を探す
機能:スクリプトゾーンで特定の種類の項目を検索します。
受け取る:ゾーンentity
戻り値:item entityまたはnil
入力例:getObjectFromGUID("######")
出力例:(オブジェクトへの参照)

function findDecksInZone(zone)
   local objectsInZone = zone.getObjects()
   local decksFound = {}
   for i, object in ipairs(objectsInZone) do
       if object.tag == "Deck" then
           table.insert(decksFound, object)
       end
   end
   if #decksFound > 0 then
       return decksFound
   else
       return nil
   end
end

この例では、タグ「Deck」を持つオブジェクトを探していました。 あなたはそれを "置物(figure)"または必要なものすべてに変更することができます。 これは、そのオブジェクト型のすべてをテーブルに返します。見つからなければnilを返します。

位置の半径内のオブジェクトを見つける
機能:特定の半径内にある特定のタイプのアイテムを見つけて配置します。
取る:オブジェクト型文字列、位置テーブル、半径番号
戻り値:オブジェクトエンティティまたはnil
入力例: "Deck"、{0,0,0}、5
出力例:(オブジェクトエンティティ)

function printCards(tagName, targetPosition, rad)
   local allObjects = getAllObjects()
   local tpX = targetPosition.x
   local tpZ = targetPosition.z
   for i, v in pairs(allObjects) do
       if v.tag == tagName then
           local vPos = v.getPosition()
           local vPosX = vPos.x
           local vPosZ = vPos.z
           local dX = tpX - vPosX
           local dZ = tpZ - vPosZ
           if dX<rad and dX>-rad and dZ<rad and dZ>-rad then
               return v
           end
       end
   end
   return nil
end

tagNameここでは、object.tagはそのタイプのアイテムのものです。 「デッキ」や「チップ」のように。 targetPositionは、そのタイプのオブジェクトを見つけるための半径内で見たい位置です。 radは半径であり、アイテムがオブジェクトポイントからどれだけ離れていても、それがどれくらい離れているかを示します。
注意:位置/オブジェクトに最も近いオブジェクトを見つけたいだけで、正確な数は必要ない場合は、math.sqrt操作をスキップすることができます。


機能:コンテナから取得したオブジェクトを返します。何も取得されなかった場合はnilを返します。
Takes:オブジェクト参照、テーブル(takeObjectパラメータ)
戻り値:オブジェクト参照
入力例:{container object}, {guid = 'ffffff', position = {0,0,0}} 
出力例:なし

    • perform takeObject only if the object exists in the container
function takeObjectSafe(container, params)
   if params.guid ~= nil then
       for _, item in pairs(container.getObjects()) do
           if item.guid == params.guid then
               return container.takeObject(params)
           end
       end
   else
       return container.takeObject(params)
   end
   --printToAll("Warning: Object " .. params.guid .. " not found in container. It may have already been removed.", {1,0,0})
end


バッグに存在しないguidでtakeObjectを使用すると、スクリプトがクラッシュします。 オブジェクトを安全に取り出そうとする場合は、この関数を使用します。 必要に応じて、エラーメッセージのコメントを解除してプレーヤーに通知します。 結果がnilであるかどうかを確認してください。その場合、コールバック関数は決して呼び出されません。
すべてにメッセージを出力するが、ターゲットプレーヤーにのみブロードキャストする

機能:すべてのプレイヤーにメッセージを出力しますが、ターゲットにのみブロードキャストします。
Takes:文字列、テーブル、文字列
戻り値:void
入力例: "Hello world!", {1,1,1}, "White"
出力例:void

function allGameMessage(msg, rgb, target_color)
   for _, player in ipairs(Player.getPlayers()) do
       if player.color == target_color then
           player.broadcast(msg, rgb)
       else
           player.print(msg, rgb)
       end
   end
end


rgbの括弧で囲まれた16進数の色を取得する
機能:文字列に色を追加するために使用できる、色の括弧内の16進数のカラーコードを返します。 stringColorToRGBをラップして、プレーヤーの色やその他のカスタム色で使用することができます(RGB形式に適合している場合)。
Takes:テーブル(rgbフォーマット)
戻り値:文字列
入力例:stringColorToRGB('White')
出力例:Output: "[ffffff]"


function RGBToBracketedHex(rgb)
   if rgb ~= nil then
       return "[" .. string.format("%02x%02x%02x", rgb.r*255,rgb.g*255,rgb.b*255) .. "]"
   else
       return ""
   end
end


テーブルの要素を注文する
機能:値に基づいて注文テーブルエントリ。
取る:テーブル
戻り値:表
入力例: { {color="Red", points=5}, {color="Blue", points=10} }
出力例: { {color="Blue", points=10}, {color="Red", points=5} }

function orderTable(t)
   local sort_func = function( a,b ) return a.points > b.points end
   table.sort( t, sort_func )
   return t
end

これは、スコアに基づいてプレイヤーを注文するのに適しています。 この例では、他のテーブルでいっぱいになったテーブルを関数に渡します。
各サブテーブルには、スコアの対象となるプレーヤーの色とスコアが表示されます。 この例では、最も高い順に並べられます。
>を<に変更すると、最低から最高の順に並べ替えられます。


表の要素をシャッフルする
機能:テーブル内の要素の順序をランダム化し、それらをシャッフルします。
取る:テーブル
戻り値:表
入力例: {"first", "second", "third"}
出力例: {"second", "first", "third"}

function shuffleTable(t)
   for i = #t, 2, -1 do
       local n = math.random(i)
       t[i], t[n] = t[n], t[i]
   end
   return t
end

テーブルに要素が含まれているかどうかをチェックします。
機能:テーブルに要素が含まれている場合はtrueを返し、そうでない場合はfalseを返します。
引き継ぐ:テーブル、変数
戻り値:bool
入力例:{1、2、3、4、5}、3
出力例:true

function table.contains(table, element)
   if type(element) ~= 'table' then
       for _, value in ipairs(table) do
           if value == element then
               return true
           end
       end
   end
   return false
end


Activate an Asset Bundle Trigger Effect by Name
Function: Activates a trigger effect on an asset bundle.
Takes: object, string
Returns: 無し
Example Input: (object entity of assetbundle), "Some Name
Example Output: -

function activateTrigger(obj, triggerName)
   local effectList = local obj.AssetBundle.getTriggerEffects()
   if #effectList == 0 then
       print("Error: No trigger effects on this object.")
   else
       for i, effect in pairs(effectList) do
           if effect.name == triggerName then
               obj.AssetBundle.playTriggerEffect(effect.index)
               return
           end
       end
       print("Error: No trigger found with that exact name.")
       return
   end
end


コルーチンをx秒間一時停止する 停止時間を発生させる?
機能:任意の秒数のコルーチンを生成する
取る:フロート
戻り値:void
入力例:0.25
出力例:void

function wait(time)
 local start = os.time()
 repeat coroutine.yield(0) until os.time() > start + time
end

オブジェクトと位置の間の距離を求める
機能:オブジェクトと位置の間の距離を求めます。
引き取る:ポジションテーブル、オブジェクトエンティティ
戻り値:距離番号
入力例:{x = 5、y = 2、z = 12}、(オブジェクト実体)
出力例:3.526

function findProximity(targetPos, object)
   local objectPos = object.getPosition()
   local xDistance = math.abs(targetPos.x - objectPos.x)
   local zDistance = math.abs(targetPos.z - objectPos.z)
   local distance = xDistance^2 + zDistance^2
   return math.sqrt(distance)
end

This function handles positions directly from getPosition() without any reformatting. It does not take Y into account (height off table). The number it returns matches those readings you would get from the line tool, except more exact. Special thanks to my good friend Math for help on this one. I find this function particularly useful to locate an object without a scripting zone. For example, if I were trying to find a deck near a certain position, I would use getAllObjects(), check if object.tag == "Deck", then check how far that deck was from the certain position to see if it was the correct deck.
この関数は、再フォーマットを行わずにgetPosition()から直接位置を処理します。 それはYを考慮に入れません(テーブルからの高さ)。 返される数値は、より正確な場合を除いて、ラインツールから取得した数値と一致します。 私の親友であるこの数学の助けを借りて数学に感謝します。 私は、この機能がスクリプトゾーンなしでオブジェクトを見つけるのに特に有用であることを発見しました。 たとえば、特定の位置の近くでデッキを見つけようとすると、getAllObjects()を使用してobject.tag == "Deck"かどうかを確認し、そのデッキが特定の位置からどれだけ離れていたかを確認して、 正しいデッキ。


注意:位置/オブジェクトに最も近いオブジェクトを見つけようとしていて、正確な数は必要ない場合は、math.sqrt操作をスキップすることができます。これは非常に数学的な処理であり、 理由。
もっと是非
私はここに機能を追加しつづけるつもりです。 私はちょうど始まって、あなたからすべての贈り物のためのアイデアを得たいと思っていました。 また、私はこのプロジェクト全体に関心を持ちたいと思っていました。

タグ:

+ タグ編集
  • タグ:
最終更新:2017年07月05日 16:19