スクリプト3

引用元:http://steamcommunity.com/sharedfiles/filedetails/?id=724540431
はじめに:
・GUIDについてぐらいは知っておこう>-[[GUID]]
・ページ制作者が知ってる範囲の解説だよ
 
 
Tables
テーブルはTTSゲームの大部分を占めるから重要だよ!

ここにテーブルのスクリプトがある↓
mytable = {}
普通のスクリプトだったら下の項目設定がいるんじゃないかって?
key/index value

 

いりません。 しかし、あえて、下のように入力すると・・・

mytable.thisisakey = 'value'
or
mytable['thisisakey'] = 'value'
テーブルは次のようになります
key/index value
thisisakey 'value'
テーブルには、どのような値でもどんなキーでも格納できます。 キーは一意ですが、値は異なります。 次のコードの後に、テーブルの外観を把握してみてください。
mytable.thisisakey2 = 'value' mytable.thisisakey = 1 mytable.thisisalsoakey = 1
key/index value
thisisakey 1
thisisakey2 'value'
thisisalsoakey 1
ただし、キーの代わりにインデックスを使用できます。 次の2つのスニペットで同じテーブルが作成されます。
mytable = {'data', 'moredata'}
mytable = {} mytable[1] = 'data' mytable[2] = 'moredata'
key/index value
1 'data'
2 'moredata'
テーブルから情報を取得する方法はいくつかあります。 キーと値のペアを持つテーブルがある場合は、このようにすることができます。 kはキーであり、vはテーブル内のそのキーの値です。
for k,v in pairs(mytable) do print(k,v) end
キーの代わりにインデックスを持つテーブルがある場合は、この方法でも実行できます。 #mytableはテーブルの長さです。 これは、索引を持つ表に対してのみ機能します。
for i=1,#mytable do print(mytable[i]) end
最後の注意として、テーブルにテーブルを入れることもできます 
mytable = {} mytable.table = {} mytable.something = 'data' mytable.table.table = {} mytable.table.table.table = {'hello'}
こんな風になります。
key/index value
table
key/index value
table
key/index value
table
key/index value
1 'hello'
something 'data'
ときには、このようなことをしている人がいることがあります
mytable = {['something'] = 'value', ['somethingelse'] = 'value2'}
↓これと同じことです。
mytable = {something = 'value', somethingelse = 'value2'}
唯一の違いは、入力する余分なテキストがあることです。括弧を使用しない場合は、キーに数字を使用することはできません
mytable = {['123key'] = 1} -- ok mytable = {123key = 1} -- not ok
 
 
Keywords
重要なキーワードはグローバル(global)と自己(self)の2つです。 グローバルはメインスクリプト内のすべてのものを参照し、selfはスクリプトが置かれているオブジェクトを参照します。
 
-- on a deckprint(self.name)Global.call('myFunction') -- in global scriptprint(deck.name)myFunction()
 
 
Callbacks/Functions in Parameters

場合によっては、一部の関数でコールバックパラメータが表示されることがあります。 コールバックは、現在の関数が完了したときに呼び出される関数です。

コールバック関数に影響を与える他の2つのパラメータがあります。

params.callback = 'theFunctionName' params.callback_owner = Global -- this is where function theFunctionName() is located params.params = {1,2,3}
あなたはこれを想像することができます
-- some function that utilizes the callback parameter i.e. spawnObject or takeObject theFunctionName({1,2,3}) -- this will only run once spawnObject or takeObject has completed


場合によっては、コールバック関数やパラメータテーブルに関数があり、

自動的に何が自動的に渡されるのか疑問に思っているときは、単にプリント(表示機能)を送信してみてください。

button.click_function = 'print'
それを考慮して
print(parameter,parameter,parameter...)
また、カンマ付きのprintステートメントでは、文字列を連結して(それらをまとめて)、chatログのように表示されます
Custom_Object (LuaGameScriptObject)White -- or something like that
それを分けて、あなたは2つのことがあります:
1.オブジェクト
2.ボタンを押した人の色
これは、ボタンの機能に渡される2つのパラメータ、それがオンになっているオブジェクト、それを押したプレイヤーの色があることを意味します。
 
 
 
 
 
----API----
API[berserk-games.com]
 
 
Collisions 衝突
function onCollisionEnter(collision_info) print('The object that hit me\'s name is' .. collision_info.collision_object.getName()) for i=1,#collision_info.contact_points do print('Collision point:') for k,v in pairs(collision_info.contact_points[i]) do print(k .. '=' .. v) end end print('Relative velocity values') print('x=' .. collision_info.relative_velocity.x) print('y=' .. collision_info.relative_velocity.y) print('z=' .. collision_info.relative_velocity.z) end
 
function onCollisionExit(collision_info) print('The object that left me\'s name is' .. collision_info.collision_object.getName()) for i=1,#collision_info.contact_points do print('Collision point:') for k,v in pairs(collision_info.contact_points[i]) do print(k .. '=' .. v) end end print('Relative velocity values') print('x=' .. collision_info.relative_velocity.x) print('y=' .. collision_info.relative_velocity.y) print('z=' .. collision_info.relative_velocity.z) end
 
function onCollisionStay(collision_info) print('The object is hitting me\'s name is' .. collision_info.collision_object.getName()) for i=1,#collision_info.contact_points do print('Collision point:') for k,v in pairs(collision_info.contact_points[i]) do print(k .. '=' .. v) end end print('Relative velocity values') print('x=' .. collision_info.relative_velocity.x) print('y=' .. collision_info.relative_velocity.y) print('z=' .. collision_info.relative_velocity.z) end
 
 
Picked Up/Dropped 拾い上げ、落とし
function onDropped(player_color) print(player_color .. ' dropped ' .. self.getName()) end
 
function onPickedUp(player_color) print(player_color .. ' dropped ' .. self.getName()) end
 
function onObjectPickedUp(player_color, object) print(player_color .. ' dropped ' .. object.getName()) end
 
function onObjectDropped(player_color, object) print(player_color .. ' dropped ' .. object.getName()) end
 
 
Save/Load セーブ ロード
function onSave() return JSON.encode({savedSomething=true}) end function onLoad(save_state) print('Everythings loaded!') if JSON.decode(save_state).savedSomething then print('Something was saved from before') end end

コメント:onSave()は文字列を返す必要があります。 JSON.encode()はテーブルを文字列に変換します。 JSON.decode()はそれらの文字列をテーブルに戻します。
 
 
Destroy 破壊
function onDestroy() print('I\'m dying!! (' .. self.getName() .. ')') end
 
function onObjectDestroyed(dying_object) print(dying_object.getName() .. 'is dying!!') end
 
destroyObject(obj)
 
 
Scripting Zones
function onObjectEnterScriptingZone(zone, enter_object) print(enter_object.getName() .. ' has entered zone ' .. zone.getGUID()) end
 
function onObjectLeaveScriptingZone(zone, exit_object) print(leave_object.getName() .. ' has left zone ' .. zone.getGUID()) end
 
 
Player Color Change プレイヤーの色を変える
onPlayerChangedColor(player_color) print('Someone moved to ' .. player_color) end
 
 
Player Turns プレイヤーのターン
onPlayerTurnEnd(player_color_end, player_color_next) print(player_color_end .. ' just ended his turn. Now it is ' .. player_color_next .. '\'s turn.') end
 
onPlayerTurnStart(player_color_start, player_color_previous) print(player_color_previous .. ' just ended his turn. Now it is ' .. player_color_start .. '\'s turn.') end
 
 
Notebook Tabs メモ帳
local params = {} params.title = 'myNewNotebookTab' params.body = 'myNewNotebookTabContents\nHere's a new line' params.color = 'White' addNotebookTab(params) params.title = 'myNewNotebookTab2' addNotebookTab(params)
 
local params = {} params.index = 1 params.title = 'myNewTitle' params.body = 'myNewBody\nAnd Other' params.color = 'Red' editNotebookTab(params)
 
local tabs = getNotebookTabs() for i=1,#tabs do print(tabs[i].index) print(tabs[i].title) print(tabs[i].body) print(tabs[i].color) end
 
removeNotebookTab(1)
 
 
Copy, Paste, and Spawn コピー&ペースト 生成
local objects = {} objects[1] = obj1 objects[2] = obj2 copy(objects) paste({position={0, 0, 0}, snap_to_grid=false})
 
local params = {} params.type = 'myObjectType' params.position = {0, 0, 0} params.rotation = {0, 0, 0} params.scale = {0, 0, 0} params.callback = 'myCallbackFunction' params.callback_owner = Global params.snap_to_grid = false params.params = {'myCallbackParams1', 'myCallbackParams2'} spawnObject(params)
 
 
Notes
local notesText = getNotes() print(notesText)
 
setNotes('These are the notes')
 
 
Printing 表示
print('Only host can read this')
 
printToAll('Everyone can read this', {1, 1, 1})
 
printToColor('Only white can read this', 'White', {1, 1, 1})
 
 
Misc.
flipTable()
 
getAllObjects()
 
getObjectFromGUID('objguid')
 
local seated = getSeatedPlayers() for i=1,#seated do print(seated[i]) end
 
function update() print('frame gone by') end
 
clearPixelPaint() clearVectorPaint()
 
startLuaCoroutine(Global, 'myFunction')
 
local color_table = stringColorToRGB('White') print('White\'s R value is ' .. color_table.r) print('White\'s G value is ' .. color_table.g) print('White\'s B value is ' .. color_table.b)
 
 
----Objects----
Objects[berserk-games.com]
 
 
Clone 複製
myclonedobject = obj.clone({position={0,0,0},snap_to_grid=false}) -- is the same as copy({obj}) myclonedobject = paste({position={0,0,0},snap_to_grid=false})[1]
 
 
Buttons ボタン
Method 1:
local button_parameters = {} button_parameters.click_function = 'myFunction' button_parameters.function_owner = Global button_parameters.label = 'myTextHere' button_parameters.position = {0, 0, 0} button_parameters.rotation = {0, 0, 0} button_parameters.width = 500 button_parameters.height = 500 button_parameters.font_size = 20 object.createButton(button_parameters) button_parameters.click_function = 'myOtherFunction' object2.createButton(button_parameters)

Method 2:
local button_parameters = {click_function = 'myFunction', function_owner = Global, label = 'myTextHere', position = {0, 0, 0}, rotation = {0, 0, 0}, width = 500, height = 500, font_size = 20} object.createButton(button_parameters) button_parameters.click_function = 'myOtherFunction' object2.createButton(button_parameters)

Method 3:
object.createButton({click_function = 'myFunction', function_owner = Global, label = 'myTextHere', position = {0, 0, 0}, rotation = {0, 0, 0}, width = 500, height = 500, font_size = 20}) object2.createButton({click_function = 'myOtherFunction', function_owner = Global, label = 'myTextHere', position = {0, 0, 0}, rotation = {0, 0, 0}, width = 500, height = 500, font_size = 20})

これらのスニペットはすべて同じことをしますが、異なる方法で行います。 あなたのスクリプトに最適なものを選択してください。
 
function myFunction(object, player) print(player .. ' pressed the button on ' .. object.getName()) end
 
 
Taking out of Containers
myBag.takeObject({position={0,1,0}, rotation={0,0,180}, callback='myFunction', callback_owner = Global, params = {self,1}, flip = false, top = false}) function myFunction(paramstable) for k,v in pairs(paramstable) do print(k,v) end end
 
 
----Notable Functions/Classes----
Somewhat more indepth.
 
 
spawnObject( Table parameters )
一見すると、spawnObjectはそれほど印象的ではないと思うかもしれませんが、物理的な表のような2つの印象的なもの、テキストツール、スクリプトゾーン、そしてテーブルさえ作ることができます。 3つのことを待ってください。
私はspawnObjectを使って作業するという一般的なアイデアについて説明します。 まず、生成するオブジェクトを作成し、そのオブジェクトの名前を出力します。 今あなたはそのタイプを知っていて、あなたはそのタイプをスポーンすることができます。
 
guid = 297853 -- pretend this is the guid of a scripting zoneprint(getObjectFromGUID(guid).name)-- this will print 'ScriptingTrigger' spawnObject({type='ScriptingTrigger'}) -- this will spawn a scripting zone

これはテーブルやテキストツールでも機能します(テキストツール名は3DTextです)。しかし、テーブルのGUIDを取得できないため、onCollisionEnterを使用してテーブルオブジェクトを取得できます。
 
function onCollisionEnter(info)print(info.collision_object.name)end

テーブルでのオブジェクト生成についての最も重要な部分は、それらのサイズを決めることができることです。
--my huge table spawnObject({type='table_custom',scale={10,1,10}})


あなたが生成することができるもう一つとして、隠しゾーンがあります。 しかし、隠しゾーンの名前をどうやって得るか?

オブジェクトの名前フィールドを見つける別の方法は、隠しゾーンだけを含む保存ファイルを作成し、.JSONセーブファイルに直接行き、名前フィールドを調べることです。 

"Name": "FogOfWarTrigger",
これが隠しゾーンです。
spawnObject({type='FogOfWarTrigger'})
そして今、あなたは隠れることのできるゾーンを持っています。
 
 
onDestroy()
それはonDestroy()と呼ばれますが、破壊はあなたが思っているほど単純ではありません。 オブジェクトを削除するときに呼び出されますが、オブジェクトが「消える」、つまりデッキやバッグに入ったときにも呼び出されます。 私はどのようにデッキやバッグを取得するか分からない。
 
function onDestroy() print('I've disappeared into a container') end
 
 
Timer
タイマーは、しばらくの間、関数の呼び出しを遅らせる方法です。
 
Timer.create({identifier='uniqueGUID', function_name='myFunction', function_owner=Global, delay=2}) function myFunction() print('2 seconds have passed since the Timer was created') end
 
 
----Random Snippets----
私のMODで、いくつか取り扱ってます。
 
 
Getting Player Count
#getSeatedPlayers()
 
 
String Manipulation
function split(input, split) local returnarr = {} local i = 1 for str in string.gmatch(input, '([^' .. split .. ']+)') do returnarr[i] = str i = i + 1 end return returnarr end options = split('option1=val1','=') print(options.option1) -- val 1
私は自分で作ったので、LUAのデフォルトの文字列分割関数を見つけることができませんでした。
 
 
Color Manipulation
function onetotfs(rgbtableone) rgbtableone.r = dechex(rgbtableone.r * 255) rgbtableone.g = dechex(rgbtableone.g * 255) rgbtableone.b = dechex(rgbtableone.b * 255) return '[' .. rgbtableone.r .. rgbtableone.g .. rgbtableone.b .. ']' end function dechex(number) local base=16 local hexvals='0123456789ABCDEF' local returnval = '' local remainder while number>0 do number,remainder=math.floor(number/base),number%base+1 returnval=string.sub(hexvals,remainder,remainder)..returnval end return returnval end function niceColorName(color) return onetotfs(stringColorToRGB(color[1])) .. Player[color[1]].steam_name .. '[-]' end print(dechex(255)) -- ff print(niceColorName({'White'})) -- [ffffff]reimu[-] : note bb tags will just color the text

ベースを10から16に変更します。ベースを変更することはできますが、これは特にTTSが使用するRGBテーブル(最大値1)をbbcodeタグに変更するためのものです。
 
 
Searching Containers
function getIndexOf(col,table) for i=1,#table do if table[i] == col then return i end end return -1 end table = {1,2,3} print(getIndexOf(2,table)) -- 2

それはテーブル/配列を検索するためのものです
 
function searchForIn(object, containerguid, params2) params2.guid = '000000' local deckorbag local guids = {} if type(containerguid) == 'string' then deckorbag = getObjectFromGUID(containerguid) else deckorbag = containerguid end local obj = nil for k,v in pairs(deckorbag.getObjects()) do ifstring.find(string.lower(v.name==niland v.nickname==nil and '' orv.nameor v.nickname), string.lower(object)) then table.insert(guids, v.guid) end end if #guids > 0 then params2.guid = guids[math.random(#guids)] return deckorbag.takeObject(params2) else return false end end
ちょっと複雑な関数で、名前が一致するすべてのオブジェクトをバッグで検索し、ランダムなものを取り出します。
パラメーター:
Stringオブジェクト - 検索するオブジェクトの名前
String / Object containerguid - 検索するコンテナ/デッキのGUID、または実際のコンテナ/デッキオブジェクト
Table params2 - オブジェクトを取り出すときのパラメータ
戻り値 - コンテナ/デッキにオブジェクトが見つからない場合はfalse、オブジェクトがコンテナ/デッキにある場合はオブジェクトへの参照
 
 
----Player Control----
プレイヤーを扱う公式サイトのドキュメントに記載されていないいくつかの機能。
 
 
Kick, promote
これらはスクリプト作成でできることです
 
print(Player.white.promoted) Player.white.promote() Player.white.kick()

タグ:

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