📄 npcsdk.lua
字号:
--发送列表信息
PRINT( "SendMissionList: send list notice" )
if count < 1 then
PRINT( "SendMissionList: does not have previous page or next page notice!" )
return SystemNotice( character, "SendMissionList: does not have previous page or next page notice!" )
end
previd = previd - 1
nextid = nextid - 1
PRINT( "SendMissionList:previd = %d, nextid = %d, count = %d", previd, nextid, count )
PRINT( "SendMissionList:sendpacket" )
--发送报文信息
local packet = GetPacket()
WriteCmd( packet, CMD_MC_MISSION )
local npcid = GetCharID( npc )
WriteDword( packet, npcid )
WriteByte( packet, listtype )
WriteByte( packet, previd )
WriteByte( packet, nextid )
PRINT( "SendMissionList: fill page notice!, previd, nextid ", previd, nextid )
--设置页
if previd == 0 then
PRINT( "SendMissionList: fill page notice!prev = end" )
WriteByte( packet, MIS_PREV_END )
else
PRINT( "SendMissionList: add page notice!prev = prev" )
WriteByte( packet, MIS_PREV )
end
local endid = num - 1
if nextid == endid then
PRINT( "SendMissionList: fill page notice! next = end" )
WriteByte( packet, MIS_NEXT_END )
else
PRINT( "SendMissionList: fill page notice! next = next" )
WriteByte( packet, MIS_NEXT )
end
WriteByte( packet, count - 1 )
for i = 1, count - 1, 1 do
PRINT( item[i] )
WriteString( packet, item[i] )
end
PRINT( "SendMissionPage" )
SendPacket( character, packet )
SetMissionPage( character, npcid, previd, nextid, listtype )
return LUA_TRUE
end
--执行页跳转命令
function JumpPage( character, npc, page, param )
if page == nil or param == nil or page[param] == nil then
return SystemNotice( character, "JumpPage:Function parameter error!" )
end
if page[param][1] == nil then
return SystemNotice( character, "JumpPage: page notice cannot be as null!" )
end
--提取对话信息
local talk = ""
if page[param][1] ~= nil and page[param][1].talk ~= nil then
talk = page[param][1].talk
end
--提取选择项信息
local FuncItem = {}
local count = 0
PRINT( "JumpPage:page item count = ", page[param].count )
local funcnum = 8
if page[param].count ~= nil then
funcnum = page[param].count
end
for i = 1, funcnum, 1 do
if page[param][i] == nil then
break
end
if page[param][i].talk == nil then
count = count + 1
FuncItem[count] = page[param][i].text
PRINT( "JumpPage:", FuncItem[count] )
end
end
PRINT( "JumpPage, ismission = ", page[param].ismission )
if page[param].ismission == nil or GetNpcHasMission( npc ) ~= LUA_TRUE then
PRINT( "JumpPage3:SendMissioniPage, pageid, talk, funcitem, count, misitem, misnum", param, talk, FuncItem, count, nil, 0 )
return SendMissionPage( character, npc, param, talk, FuncItem, count, nil, 0 )
end
--提取任务列表信息
local misnum = 0
local MisItem = {}
local ret, NpcInfoID = GetScriptID( npc )
PRINT( "JumpPage:GetScriptID: ret = , NpcInfoID = ", ret, NpcInfoID )
if ret ~= LUA_TRUE or NpcInfoList[NpcInfoID] == nil or NpcInfoList[NpcInfoID].missionlist == nil then
PRINT( "JumpPage1:SendMissioniPage, pageid, talk, funcitem, count, misitem, misnum", param, talk, FuncItem, count, MisItem, misnum )
return SendMissionPage( character, npc, param, talk, FuncItem, count, MisItem, misnum )
end
local missionlist = NpcInfoList[NpcInfoID].missionlist
local npcid = GetCharID( npc )
ret, misnum = GetNumMission( character, npcid )
--获取任务列表
PRINT( "JumpPage:misnum = ", misnum )
for n = 1, misnum, 1 do
local ret, id, state = GetMissionInfo( character, npcid, n - 1 )
PRINT( "JumpPage:missionid = %d, state = %d", id, state )
if missionlist[id] == nil or missionlist[id].name == nil then
MisItem[n] = {}
MisItem[n].name = "Error: quest index or name does not exist!"
MisItem[n].state = state
PRINT( "JumpPage:mission name = , state = ", missionlist[id].name, state )
else
MisItem[n] = {}
MisItem[n].name = missionlist[id].name
MisItem[n].state = state
PRINT( "JumpPage:mission name = , state = ", missionlist[id].name, state )
end
end
PRINT( "JumpPage2:SendMissioniPage, pageid, talk, funcitem, count, misitem, misnum", param, talk, FuncItem, count, MisItem, misnum )
return SendMissionPage( character, npc, param, talk, FuncItem, count, MisItem, misnum )
end
--发送功能页信息
function FuncPage( character, npc, page, param )
if page == nil or param == nil or page[param] == nil or page[param][1] == nil then
return SystemNotice( character, "FuncPage: function parameter error!" )
end
local FuncItem = {}
local count = 0
for i = 1, ROLE_MAXNUM_PAGEITEM, 1 do
if page[param][i] == nil then
break
end
if page[param][i].talk == nil then
count = count + 1
FuncItem[count] = page[param][i].text
end
end
if count == 0 then
return SystemNotice( character, "FuncPage: does not have function item notice!" )
else
return SendFuncPage( character, npc, param, FuncItem, count )
end
end
--关闭本次对话
function CloseTalk( character, npc )
return SendClosePage( character, npc )
end
--移动到制定地图坐标
function GoTo( character, xpos, ypos, mapname )
if xpos == nil or ypos == nil or mapname == nil then
return SystemNotice( character, " GoTo:xpos or ypos or mapname level parameter cannot be as null!" )
end
return MoveTo( character, xpos, ypos, mapname )
end
--随机跳转地图
function RandToMap( character, npc, maplist, count )
SendClosePage( character, npc )
if maplist == nil or count == nil then
return SystemNotice( character, "RandToMap:maplist or count level parameter cannot be as null!" )
end
local id = Rand( count )
id = id + 1
if maplist[id] == nil or maplist[id].xpos == nil or maplist[id].ypos == nil or maplist[id].mapname == nil then
return SystemNotice( character, "RandToMap: certain parameter in maplist cannot be as null!" )
end
GoTo( character, maplist[id].xpos, maplist[id].ypos, maplist[id].mapname )
end
--随机检测是否已到达地图
function IsRandInMap( character, npc, rate, mapname, x, y, w, h )
if rate == nil or mapname == nil or x == nil or y == nil then
PRINT( "IsRandInMap: parameter error!" )
SystemNotice( character, "IsRandInMap:Function parameter error!rate, mapname, x, y", rate, mapname, x, y )
return LUA_ERROR
end
if rate > Rand( 100 ) then
return LUA_FALSE
end
return IsInMap( character, mapname, x, y, w, h )
end
function PopupWindow( character, npc, page, trigger, p2 )
if trigger == nil or p2 == nil then
return SystemNotice( character, "PopupWindow:参数不能为空!" )
end
trigger( character, npc, p2 )
end
--多个触发器功能执行
function MultiTrigger( character, npc, page, trigger, count )
PRINT( "MultiTrigger" )
if trigger == nil or count == nil then
return SystemNotice( character, "MultiTrigger:funclist or count parameter cannot be as null!" )
end
for n = 1, count, 1 do
if trigger[n] == nil then
break
end
PRINT( "MultiTrigger:ConditionsTest, n = "..n )
local ret = ConditionsTest( character, trigger[n].conditions, nil, nil, npc )
if ret == LUA_TRUE then
PRINT( "MultiTrigger:success, ActionsProc, n = "..n )
if trigger[n].actions ~= nil and trigger[n].actions.count ~= 0 then
return ActionsProc( character, trigger[n].actions, npc, page )
end
else
PRINT( "MultiTrigger:failure, ActionsProc, n = "..n )
if trigger[n].failures ~= nil and trigger[n].failures.count ~= 0 then
return ActionsProc( character, trigger[n].failures, npc, page )
end
end
end
end
--新触发器0
function MultiTrigger_0( character, npc, page, trigger, count )
MultiTrigger( character, npc, page, trigger, count )
Eleven_Log_0( character )
end
--新触发器1
function MultiTrigger_1( character, npc, page, trigger, count )
MultiTrigger( character, npc, page, trigger, count )
Eleven_Log( character,1 )
end
--新触发器2
function MultiTrigger_2( character, npc, page, trigger, count )
MultiTrigger( character, npc, page, trigger, count )
Eleven_Log( character,2 )
end
--新触发器3
function MultiTrigger_3( character, npc, page, trigger, count )
MultiTrigger( character, npc, page, trigger, count )
Eleven_Log( character,3 )
end
--多个条件判断
function MultiConditions( character, npc, funclist, count )
if funclist == nil or count == nil then
return SystemNotice( character, "MultiConditions:funclist or count parameter cannot be as null!" )
end
return ConditionsTest( character, funclist )
end
--多个函数功能
function MultiFunc( character, npc, page, funclist, count )
if funclist == nil or count == nil then
return SystemNotice( character, "MultiFunc:funclist or count parameter cannot be as null!" )
end
for id = 1, count, 1 do
PRINT( "MultiFunc n = "..id )
if funclist[id].func == AddMoney then
AddMoney( character, funclist[id].p1 )
elseif funclist[id].func == AddExp then
AddExp( character, funclist[id].p1, funclist[id].p2 )
elseif funclist[id].func == GiveItem then
Giveitem( character, funclist[id].p1, funclist[id].p2, funclist[id].p3 )
elseif funclist[id].func == TakeItem then
TakeItem( character, funclist[id].p1, funclist[id].p2 )
elseif funclist[id].func == TakeMoney then
TakeMoney( character, funclist[id].p1, funclist[id].p2 )
elseif funclist[id].func == JumpPage then
JumpPage( character, npc, page, funclist[id].p1 )
elseif funclist[id].func == RandToMap then
RandToMap( character, npc, funclist[id].p1, funclist[id].p2 )
elseif funclist[id].func == GoTo then
GoTo( character, funclist[id].p1, funclist[id].p2, funclist[id].p3 )
elseif funclist[id].func == SetRecord then
SetRecord( character, funclist[id].p1 )
elseif funclist[id].func == SetFlag then
SetFlag( character, funclist[id].p1, funclist[id].p2 )
elseif funclist[id].func == CloseTalk then
CloseTalk( character, npc )
elseif funclist[id].func == RefreshMissionState then
RefreshMissionState( character, npc )
elseif funclist[id].func == OpenBank then
OpenBank( character, npc )
elseif funclist[id].func == OpenHair then
OpenHair( character, npc )
elseif funclist[id].func == OpenChaSel then
OpenHair( character, npc )
elseif funclist[id].func == OpenTiger then
OpenTiger( character, npc )
elseif funclist[id].func == CreditExchange then
CreditExchange( character, npc, funclist[id].p1 )
else
return SystemNotice( character, "MultiFunc:unknown functionerror!" )
end
end
end
--随机功能
function RandFunction( character, npc, page, funclist, count )
if funclist == nil or count == nil then
return SystemNotice( character, "RandFunction:funclist or count parameter cannot be as null!" )
end
local id = Rand( count )
id = id + 1
if funclist[id] == nil or funclist[id].func == nil then
return SystemNotice( character, "RandFunction:funclist certain parameter cannot be as null!" )
end
if funclist[id].func == JumpPage then
return JumpPage( character, npc, page, funclist[id].p1 )
elseif funclist[id].func == RandToMap then
return RandToMap( character, npc, funclist[id].p1, funclist[id].p2 )
elseif funclist[id].func == GoTo then
SendClosePage( character, npc )
return GoTo( character, funclist[id].p1, funclist[id].p2, funclist[id].p3 )
elseif funclist[id].func == GiveItem then
PRINT( "RandFunction:GiveItem, p1, p2, p3", funclist[id].p1, funclist[id].p2, funclist[id].p3 )
return GiveItem( character, npc, funclist[id].p1, funclist[id].p2, funclist[id].p3 )
elseif funclist[id].func == MultiFunc then
PRINT( "RandFunction:MultiFunc, p1, p2 ", funclist[id].p1, funclist[id].p2 )
return MultiFunc( character, npc, page, funclist[id].p1, funclist[id].p2 )
else
return SystemNotice( character, "RandFunction: unknown function error!" )
end
end
--交易
function SendTradePage( character, npc, cmd, trade, tradetype, p1 )
if cmd == nil or trade == nil or tradetype == nil then
return SystemNotic( character, "TradePage:Function parameter error!" )
end
PRINT( "SendTradePage: send start. tradetype = ", tradetype )
local packet = GetPacket()
WriteCmd( packet, cmd )
local npcid = GetCharID( npc )
WriteDword( packet, npcid )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -