這篇主要是分享利用 ShowWindowTalked 完成多個窗口對話,實作一層一層的對話窗口
先看看ShowWindowTalked 參數說明
ShowWindowTalked( ToIndex, WindowType, ButtonType, SeqNo, Data, [WinTalkIndex]);
函數功能:
對在某一指定地圖內的所有玩家說話。
參數說明:
ToIndex:[數值型] 發送對話框的目標 對像索引 。
WindowType:[數值型] 窗口類型 。
ButtonType:[數值型] 按鈕類型 。
SeqNo:[數值型] 自定義數值,用於識別不同的對話框事件響應,可參考 WindowTalkedCallBack 。
Data:[字串型] 對話框的內容,有時候會根據不同的 窗口類型 而有不同的格式,可以參考 窗口類型 。
WinTalkIndex:[數值型] 默認值-1,發出此對話框的對像索引。
如果設置了,玩家就必須在此NPC附近才能接收到此函數所發出去的對話框,
而且當玩家離開這個NPC一定範圍外,對話框將消失。
返回值:
返回0表示成功,其他表示失敗,調用 GetErrorStr 獲取具體錯誤信息。
SeqNo用來定義你這個對話窗口的編號
舉個例子來講第21行
NLG.ShowWindowTalked( _PlayerIndex, 2, 0, 0, token, _MeIndex); --對客戶端發送窗口的封包
此窗口的編號為0,因此要判斷這個窗口上所做的動作時,參考第30,37,42行,這邊的_Data 即是你在這個窗口上點的選項位置
if _Seqno == 0 and _Data == "1" then -- 介紹 -- 假如選擇窗口編號0,的第1個選項
if _Seqno == 0 and _Data == "3" then -- 離開 -- 假如選擇窗口編號0,的第3個選項
if _Seqno == 0 and _Data == "2" then -- 選要衝的裝備 -- 假如選擇窗口編號0,的第2個選項
再舉一個例子
如果我們選擇了 窗口編號"0"的選項"2"(選要衝的裝備) 就會跳出第71行的窗口 窗口編號為 1
NLG.ShowWindowTalked( _PlayerIndex, 2, 0, 1, TM_Buff, _MeIndex);
接著看到第75行,如果在窗口編號1 選擇了第9個選項(下一頁),則執行換頁選道具的程式碼
if _Seqno == 1 and _Data == "9" then --換頁選道具
function EquipPlus_Talked( _MeIndex, _PlayerIndex, _Msg, _Color, _Channel) --對話事件
--這裡檢查玩家是否站在NPC面前
if(NLG.CheckInFront(_PlayerIndex, _MeIndex, 1) == false) then
return ;
end
local i; --以下讓NPC面對你
i = Char.GetData(_PlayerIndex, %對像_方向%);
if i >= 4 then
i = i - 4;
else
i = i + 4;
end
-- Char.SetData(_MeIndex, %對像_方向%,i);
Char.SetData(_MeIndex, %對像_方向%,i);
NLG.UpChar( _MeIndex);
local token = "3\n 「 裝備強化系統 」\n你好,今天想做什麼呢?\n"..
"\n 『了解強化裝備』".."\n 『強 化 裝 備』".."\n 『暫時無此需求』";
NLG.ShowWindowTalked( _PlayerIndex, 2, 0, 0, token, _MeIndex); --對客戶端發送窗口的封包
return;
end
function EquipPlus_WindowTalked( _MeIndex, _PlayerIndex, _Seqno, _Select, _Data) --窗口事件
if _Seqno == 0 and _Data == "1" then -- 離開
local token2 = " 「 裝備強化系統 」\n 此強化系統可強化-盾牌、腰帶、手套、鞋子\n 需透過磷石來進行強化,每件裝備最多能強化9階,從第6階開始有機率會爆裝,將原本階層回到0階\n 另外如果有工匠之石可以提高6階以後sucess的機率,若要使用工匠之石,請將工匠之石放於道具欄左上方第一格";
button = 1;
NLG.ShowWindowTalked( _PlayerIndex, 0, button, 5, token2, _MeIndex); --對客戶端發送窗口的封包
return;
end
if _Seqno == 0 and _Data == "3" then -- 離開
NLG.TalkToCli(_PlayerIndex,"有需要可以來找我哦~" ,%紅色% );
return;
end
if _Seqno == 0 and _Data == "2" then -- 選要衝的裝備
-- 工匠之石
EquipPlus_lucky = {22750,22751};
--判斷玩家身上是不是有工匠之石,如果有工匠之石且位置不再第一格則文字提醒
if(Char.FindItemId( _PlayerIndex,EquipPlus_lucky[1])>0 or Char.FindItemId( _PlayerIndex,EquipPlus_lucky[2])>0) then
if(Char.GetItemId( _PlayerIndex,9)==EquipPlus_lucky[1] or Char.GetItemId( _PlayerIndex,9)==EquipPlus_lucky[2]) then
else
NLG.TalkToCli(_PlayerIndex,"您身上帶有工匠之石,若有需要使用,請將工匠之石手動放置道具欄最左上方第一格位置。",%黃色%);
end
end
local pos = 9;
local TM_Buff = "1\n請選擇『要衝的裝備』:";
local itemindex;
local itempos = {"道具欄1","道具欄2","道具欄3","道具欄4","道具欄5","道具欄6","道具欄7","道具欄8"};
while(pos <= 17)do
itemindex = Char.GetItemIndex( _PlayerIndex, pos);
if (pos == 17) then
TM_Buff = TM_Buff .. "\n" .. " 下一頁";
else
if( itemindex > 0)then
TM_Buff = TM_Buff.."\n".. itempos[pos - 8] .. ": " .. Item.GetData( itemindex, %道具_名%);
else
TM_Buff = TM_Buff .. "\n" .. itempos[pos - 8] .. ": 無道具";
end
end
pos = pos + 1;
end
NLG.ShowWindowTalked( _PlayerIndex, 2, 0, 1, TM_Buff, _MeIndex);
return;
end
if _Seqno == 1 and _Data == "9" then --換頁選道具
local pos = 17;
local TM_Buff = "0\n";
local itemindex;
local itempos = {"道具欄9","道具欄10","道具欄11","道具欄12","道具欄13","道具欄14","道具欄15"};
while(pos <= 24)do
itemindex = Char.GetItemIndex( _PlayerIndex, pos);
if (pos == 24) then
TM_Buff = TM_Buff .. "\n" .. " 取 消";
else
if( itemindex > 0)then
-- TM_Buff = TM_Buff.."\n".. itempos[pos - 16] .. ": " .. Item.GetData( itemindex, %道具_名%);
TM_Buff = TM_Buff.."\n".. itempos[pos - 16] .. ": " .. Item.GetData( itemindex, %道具_名%);
else
TM_Buff = TM_Buff .. "\n" .. itempos[pos - 16] .. ": 無道具";
end
end
pos = pos + 1;
end
NLG.ShowWindowTalked( _PlayerIndex, 2, 0, 2, TM_Buff, _MeIndex);
end
<<程式碼省略...>>
最後這邊附上一個用loop寫成的多視窗NPC (目前是傳送師功能)
點我下載 pw:http://dsa.welovesa.com/
