複数起動したクライアントにそれぞれロードされた同一アドオンをIPC(プロセス間通信)で制御する機能がWindowerには実装されています。
Windowerが提供している制御方法は簡単で、あるクライアントのアドオンから他のクライアントの同一アドオンに対してメッセージ(文字列)を送信、受信できます。
Functions · Windower/Lua Wiki · GitHub
Events · Windower/Lua Wiki · GitHub
-- メッセージを送信 windower.send_ipc_message('hoge') -- メッセージを送信した以外のクラアントで受信 windower.register_event('ipc message', function(message) -- messageにsend_ipc_messageで送信した'hoge'が受信される end)
何か作ってみる
前回のディスカウントキャンペーンに1つアカウントを増やして、現在3アカウントで遊んでいます。
アカウントが1つ増えたことで、今までやっていたキャラクターの"/follow"が思ったように動かなくなったので、改善したいと思います。
現状
下記のようなコマンドをキーに割り当てて"/follow"を行っています。
//bind f10 send @others /follow <p1>;
2アカウントではどちらのキャラクターで実行してもうまく"/follow"しますが、
3アカウントではパーティのメンバーリストの順序によって、お互いを"/follow"してしまってうまく動作しないキャラクターが出てしまいます。
またパーティを組んでいないと"/follow"できないのも不便でした。
解決方法の1つとしては、プラグイン"AutoExec"を使ってログイン時にキャラクター毎にキーに割り当てるコマンドを変更することでうまく出来そうです。
//bind f10 send @others /follow (ログインしたキャラクター名);
しかし、今回はIPC Messageを使ったアドオンを作って改善したいと思います。
followme
以下のようなコマンドでフォローとアンフォローを行うコマンドを実装します。
・フォロー開始(自身以外のキャラクターを自身にフォローさせる) //followme(//fm) start ・フォロー解除(フォローしているキャラクターのフォローを解除する) //followme(//fm) stop
実装
フォローには、windower.ffxi.followを使ってみました。
FFXI Functions · Windower/Lua Wiki · GitHub
windower.ffxi.follow()のようにindexを指定しない場合、停止するようなのですが、
この停止は一時停止のような感じで再度オートランをするとフォローが再開されるような挙動になっていました。
完全にフォローを解除してほしいので、今回は今まで使っていた"setkey"でのフォローの解除方法を採用しました。
_addon.version = '0.0.1' _addon.name = 'followme' _addon.author = 'yyoshisaur' _addon.commands = {'followme','fm'} require('strings') -- //fm start -- //fm stop function fm_command(...) local args = {...} if args[1] == 'start' then local id = windower.ffxi.get_player().id windower.send_ipc_message('follow start '..id) elseif args[1] == 'stop' then windower.send_ipc_message('follow stop') end end function fm_ipc_msg(message) local msg = message:split(' ') if msg[1] == 'follow' then if msg[2] == 'start' then local id = msg[3] local mob = windower.ffxi.get_mob_by_id(id) if mob then local index = mob.index windower.ffxi.follow(index) end elseif msg[2] == 'stop' then -- windower.ffxi.follow() windower.send_command('setkey numpad7 down;wait .5;setkey numpad7 up;') end end end windower.register_event('addon command', fm_command) windower.register_event('ipc message', fm_ipc_msg)