FtdのLuaでweaponIndexからタレットのIDを得る
4787 ワード
- この記事は「From The Depths」というゲーム(以下FtD)で使用できるLuaに関する記事です。
- Luaに関心のあるFtDプレイヤーを対象としています。
I:AimWeaponInDirection(weaponIndex, x,y,z, weaponSlot)
やI:GetWeaponBlockInfo(weaponIndex)
などでタレットを操作する際、weaponIndexが必要ですが、被弾などでタレットを喪失するとweaponIndexはズレるので、決め打ちでは使いにくい。
せっかくタレットにIDが振られているのでID指定でアクセスしたい。
そんな時がたまにあります。
というわけで、IDをキーにweaponIndexを値にもつテーブルを用意すれば後が楽になります。
コードは以下。
-- subconstIdをキーに、weaponIndexを要素にもつテーブルを返す
function get_weapon_index_map(I)
local map = {}
local subs = I:GetAllSubConstructs();
local wc = I:GetWeaponCount()
for weaponIndex = 0, wc - 1 do
local wp_info = I:GetWeaponBlockInfo(weaponIndex)
for i = 1, #subs do
local id = subs[i]
local sub_info = I:GetSubConstructInfo(id)
if sub_info.Position.x == wp_info.Position.x
and sub_info.Position.y == wp_info.Position.y
and sub_info.Position.z == wp_info.Position.z then
map[id] = weaponIndex
break
end
end
end
return map
end
使い方はこのように。
local id = 1
local map = get_weapon_index_map(I)
local blockInfo = I:GetWeaponBlockInfo(map[id])
local last_pos = blockInfo.Position
タレット直接操作することはあまりないとは思いますが。
以上。
Author And Source
この問題について(FtdのLuaでweaponIndexからタレットのIDを得る), 我々は、より多くの情報をここで見つけました https://qiita.com/tvagames/items/e786e3ffdefb9e9619fd著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .