复制内容到剪贴板
代码:
--宠物技能学习——Pet_AddSkillNpc_id13——Lua脚本
--道具参数格式:techid,cost
--cost可选,不填写,则表示免费,如果填写-1则表示使用tech.txt中定义的价格
function Pet_AddSkillNpc_id13_Talked(_npc,_player)
local _str = MyFun.ShowSelectPetstr(_player,"学习技能");
NLG.ShowWindowTalked(_player,_npc,%WINDOW_MESSAGETYPE_SELECT%,%BUTTON_CANCEL%,LuaSetup.MySeqno+1,_str);
return;
end
function Pet_AddSkillNpc_id13_WTalked(_npc,_player,_seqno,_select,_data)
local _seqno = _seqno - LuaSetup.MySeqno;
--验证缓存的道具
local _item = MyFun.CheckItemBuffer(_player,"LUA_usePetAddSkill");
if _item == nil then
return;
end;
local _arg = Item.GetData(_item,%ITEM_ARGUMENT%);
local _argstl = MyFun.Split(_arg,",");
local _techid = tonumber(_argstl[1]);
local _needgold = 0;
local _techindex = Data.GetIndex(%FILE_TECH%,_techid);
if _techindex == nil then
MyFun.EndWindow(_player,"\\n\\n\\n\\n@c技能ID错误,请截图联系GM");
return;
end
local _techname = Data.GetChar(%FILE_TECH%,_techindex,%TECH_NAME%);
if #_argstl == 2 then
if tonumber(_argstl[2]) ~= -1 then
_needgold = tonumber(_argstl[2]);
else
local _techcost = Data.GetInt(%FILE_TECH%,_techindex,%TECH_COST%);
if _techcost ~= "" then
_needgold = tonumber(_techcost);
end
end
end
--选择宠物后确认
if (tonumber(_seqno)==1 and _data~=nil) then
if tonumber(_select) == %BUTTON_CANCEL% then
return;
end
--容错
if MyFun.CheckSelectWindowData(_player,_data,5) == false then
return;
end
local _petpos = tonumber(_data) - 1;
local _pet = Char.GetPet(_player,_petpos);
if _pet == nil then
MyFun.EndWindow(_player,"\\n\\n\\n\\n@c您选择的位置没有宠物,请重新选择!");
return;
end
--这里加一个验证,禁止部分宠物学习指定技能
if (Char.GetData(_pet,%PET_PetId%) >= 20921) and (Char.GetData(_pet,%PET_PetId%) <= 20924) and (_techid == 8900) then
MyFun.EndWindow(_player,"\\n\\n\\n\\n@c很抱歉,出生系列牛头怪禁止学习宠物邮件");
return;
end
local _itemname = Item.GetData(_item,%ITEM_TRUENAME%);
local _petname = Char.GetData(_pet,%CHAR_Name%);
local _petlv = Char.GetData(_pet,%CHAR_Lv%);
Char.SetData(_player,LuaSetup.TMP_PetSelect,_petpos);
local _str = "\\n\\n 已选宠物:".._petname.."\\n 当前等级:".._petlv.." 级\\n\\n 您确定要让这只宠物学习新技能——\\n “".._techname.."”吗?";
if _needgold > 0 then
_str = _str.."\\n 这将需要花费".._needgold.."G";
end
NLG.ShowWindowTalked(_player,
_npc,
%WINDOW_MESSAGETYPE_MESSAGE%,
%BUTTON_YES_NO%,
LuaSetup.MySeqno+2,
_str);
return;
end
--进行学习技能操作
if (tonumber(_seqno)==2) then
if tonumber(_select) == %BUTTON_NO% then
--将缓存释放
Char.SetData(_player,LuaSetup.TMP_ItemSelect,0);
Char.SetData(_player,LuaSetup.TMP_PetSelect,0);
return;
end
local _pet = MyFun.CheckPetBuffer(_player);
if _pet == nil then
return;
end
local _petname = Char.GetData(_pet,%CHAR_Name%);
local _petlv = Char.GetData(_pet,%CHAR_Lv%);
local _itemid = Item.GetData(_item,%ITEM_ID%);
if Char.ItemNum(_player,_itemid) > 0 then
--先判断金币是否充足
if Char.GetData(_player,%PLAYER_Gold%) < _needgold then
MyFun.EndWindow(_player,"\\n\\n\\n\\n@c您的魔币不足以支付该技能学习费用!");
return;
end
--尝试学习技能
local _ret = Pet.AddSkill(_pet,_techid);
if _ret == nil then
MyFun.EndWindow(_player,"\\n\\n\\n\\n@c学习失败,可能宠物的技能已满了!");
return;
end
Char.DelItem(_player,_itemid,1);--删除道具
if _needgold > 0 then
Char.AddGold(_player,-_needgold);
end
NLG.UpChar(_pet);
NLG.SystemMessage(_player,"[系统提示] 您的宠物“".._petname.."”已成功习得新技能“".._techname.."”");
--将缓存释放
Char.SetData(_player,LuaSetup.TMP_ItemSelect,0);
Char.SetData(_player,LuaSetup.TMP_PetSelect,0);
return;
end
end
return;
end
function Pet_AddSkillNpc_id13_LoopEvent(_npc)
return;
end
复制内容到剪贴板
代码:
--组合宠物选择框
function MyFun.ShowSelectPetstr(_player,_keystr)
local _keystrnew = "操作";
if _keystr ~= nil then
_keystrnew = _keystr;
end
local _str = "3|\\n\\n 请选择您要".._keystrnew.."的宠物!\\n\\n";
local _str2 = "";
local _str3 = "";
for i=0,4 do
local _pet = Char.GetPet(_player,i);
if (_pet == nil) then
_str = _str .. " *空*\\n";
else
_str2 = Char.GetData(_pet,%CHAR_Name%);
_str2 = " "..string.format("%-20s",_str2);
_str3 = "LV"..Char.GetData(_pet,%CHAR_Lv%);
_str2 = string.format("%20s",_str2);
_str = _str.._str2.._str3.."\\n";
end
end
return _str;
end
复制内容到剪贴板
代码:
--验证缓存的所选择宠物
function MyFun.CheckPetBuffer(_player)
local _slot = Char.GetData(_player,LuaSetup.TMP_PetSelect);
if _slot < 0 or _slot > 4 then
MyFun.EndWindow(_player,"\\n\\n\\n\\n@c宠物栏异常,请截图联系GM");
return;
end
local _pet = Char.GetPet(_player,_slot)
if _pet == nil then
MyFun.EndWindow(_player,"\\n\\n\\n\\n@c您所选择的宠物异常,请截图联系GM");
return;
else
return _pet;
end
end
复制内容到剪贴板
代码:
--分割字符串
function MyFun.Split(szFullString, szSeparator)
local nFindStartIndex = 1;
local nSplitIndex = 1;
local nSplitArray = {};
while true do
local nFindLastIndex = string.find(szFullString, szSeparator, nFindStartIndex);
if not nFindLastIndex then
nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, string.len(szFullString));
break;
end
nSplitArray[nSplitIndex] = string.sub(szFullString, nFindStartIndex, nFindLastIndex - 1);
nFindStartIndex = nFindLastIndex + string.len(szSeparator);
nSplitIndex = nSplitIndex + 1;
end
return nSplitArray;
end
--结束窗口
function MyFun.EndWindow(_player,_str)
local _fd = Char.GetData(_player,%PLAYERWORK_Fd%);
local _objindex = Char.GetData(_player,%CHARWORK_ObjIndex%);
Protocol.WN_Send(_fd,%WINDOW_MESSAGETYPE_MESSAGE%,%BUTTON_OK%,LuaSetup.EndWindowSeqno,_objindex,_str);
return;
end
--判断选择窗口异常
function MyFun.CheckSelectWindowData(_player,_data,_max)
if (_data == "") or (_data == nil) or (tonumber(_data) == nil) then
MyFun.EndWindow(_player,"@c\\n\\n\\n\\n异常选项处理失败,请截图联系客服!");
return false;
end
if (tonumber(_data) > _max or tonumber(_data) < 1) then
MyFun.EndWindow(_player,"@c\\n\\n\\n\\n异常选项处理失败,请截图联系客服!");
return false;
end
return true;
end