📄 scriptsdk.lua
字号:
Trade.tp = TRADE_GOODS
Trade.berth = berth
--武器
Trade[1] = {}
Trade[1].itemtype = WEAPON
Trade[1].count = 0;
Trade[1].item = {}
Trade[1].price = {}
--防具
Trade[2] = {}
Trade[2].itemtype = DEFENCE
Trade[2].count = 0;
Trade[2].item = {}
Trade[2].price = {}
--杂项
Trade[3] = {}
Trade[3].itemtype = OTHER
Trade[3].count = 0;
Trade[3].item = {}
Trade[3].price = {}
--合成
Trade[4] = {}
Trade[4].itemtype = SYNTHESIS
Trade[4].count = 0;
Trade[4].item = {}
Trade[4].price = {}
end
--初始化npc任务列表信息
function InitNpcMission()
NpcMissionList = {}
NpcMissionList.count = 0
--for n = 1, 32, 1 do
--NpcMissionList[n] = {}
--end
end
--npc对话信息函数
function ResetNpcInfo( npc, name )
InitPage()
InitTrade()
InitNpcMission()
NpcPointer = npc
local str = "Initialization NPC ["..name.."] script notice successful!"
PRINT( str )
LG( "npcinit", str )
end
--获取npc对话信息和交易信息ID
function GetNpcInfo( npc, name )
NpcInfoList.count = NpcInfoList.count + 1
NpcInfoList[NpcInfoList.count] = {}
NpcInfoList[NpcInfoList.count].page = Page
NpcInfoList[NpcInfoList.count].trade = Trade
NpcInfoList[NpcInfoList.count].eXchange = ExchangeX
NpcInfoList[NpcInfoList.count].missionlist = NpcMissionList
SetNpcScriptID( npc, NpcInfoList.count )
if NpcMissionList.count > 0 then
LG( "mission", "Set NPC bring quest label!" )
SetNpcHasMission( npc, 1 )
end
NpcPointer = LUA_NULL
local str = "Obtain NPC ["..name.."] script data notice, ID = "..NpcInfoList.count
PRINT( str )
LG( "npcinit", str )
end
--动态修改npc脚本信息
function ModifyNpcInfo( npc, name, id )
PRINT( "ModifyNpcInfo:npc = , name = , id = ", npc, name, id )
NpcInfoList[id] = {}
NpcInfoList[id].page = Page
NpcInfoList[id].trade = Trade
NpcInfoList[id].eXchange = ExchangeX
NpcInfoList[id].missionlist = NpcMissionList
PRINT( "set npcscript notice ID = ", id )
--SetNpcScriptID( npc, id )
if NpcMissionList.count > 0 then
PRINT( "mission", "Set NPC bring quest label!" )
SetNpcHasMission( npc, 1 )
else
PRINT( "mission", "set NPC does not carry quest label !" )
SetNpcHasMission( npc, 0 )
end
NpcPointer = LUA_NULL
local str = "修改NPC《"..name.."] script data notice, ID = "..id
PRINT( str )
LG( "npcinit", str )
end
-- npc消息处理函数
function NpcProc( character, npc, rpk, id )
PRINT( "NpcProc:character, npc, rpk, id", character, npc, rpk, id )
if NpcInfoList[id] == nil then
PRINT( "unable to obtain NPC script notice!ID = ", id )
local npcname = GetCharName( npc )
local str = npcname..": Hi! You are looking for me? I am quite busy right now._......."
SendPage( character, npc, 0, str, nil, 0 )
return
end
MsgProc( character, npc, rpk, NpcInfoList[id].page, NpcInfoList[id].trade, NpcInfoList[id].missionlist )
end
--npc任务状态处理函数
function NpcState( character, npcid, id )
PRINT( "NpcState:character, npcid, NpcMissionList", character, npcid, id )
if NpcInfoList[id] == nil or NpcInfoList[id].missionlist == nil then
PRINT( "unable to obtain NPC script notice!ID = ", id )
LG( "npc_error", "unable to obtain NPC script notice!ID = ", id )
return LUA_FALSE
end
return MissionState( character, npcid, NpcInfoList[id].missionlist )
end
--重新装载npc处理信息
function NpcInfoReload( name, func )
PRINT( "NpcInfoReload: name, findnpc ", name, FindNpc )
local ret, npc, id = FindNpc( name )
if ret == LUA_FALSE or npc == nil or id == nil then
print( "unfound ["..name.."] NPC!" )
return
end
PRINT( "got npc notice, pointer =, id = ", npc, id )
print( GetCharName( npc ) )
ResetNpcInfo( npc, name )
PRINT( "ResetNpcInfo, npc = , name = ", npc, name )
func()
PRINT( "Func = ", func )
ModifyNpcInfo( npc, name, id )
PRINT( "ModifyNpcInfo, name = , id = ", name, id )
print( "Edit NPC ["..name.."] script notice successful!" )
end
--对话描述信息注册
function Talk( pageid, talk )
Page[pageid].count = Page[pageid].count + 1
Page[pageid][Page[pageid].count].talk = talk
LG( "npcinit", "Talk:pageid, count, talk", pageid, Page[pageid].count, Page[pageid][Page[pageid].count].talk )
end
--对话选项信息注册
function Text( pageid, text, func, p1, p2, p3, p4 )
Page[pageid].count = Page[pageid].count + 1
Page[pageid][Page[pageid].count].text = text
Page[pageid][Page[pageid].count].func = func
Page[pageid][Page[pageid].count].p1 = p1
Page[pageid][Page[pageid].count].p2 = p2
Page[pageid][Page[pageid].count].p3 = p3
Page[pageid][Page[pageid].count].p4 = p4
LG( "npcinit", "Text:pageid, count, text, func, p1, p2, p3, p4 ", pageid, Page[pageid].count, text, func, p1, p2, p3, p4 )
end
--设置对话页包含任务信息
function MisListPage( pageid )
Page[pageid].ismission = 1
LG( "npcinit", "MisListPage:"..pageid )
end
--交易信息注册
function Weapon( id )
--武器
Trade[1].count = Trade[1].count + 1;
Trade[1].item[Trade[1].count] = id
LG( "npcinit", "Weapon:count, id", Trade[1].count, id )
end
function Defence( id )
--防具
Trade[2].count = Trade[2].count + 1;
Trade[2].item[Trade[2].count] = id
LG( "npcinit", "Defence:count, id", Trade[2].count, id )
end
function Other( id )
--杂项
Trade[3].count = Trade[3].count + 1;
Trade[3].item[Trade[3].count] = id
LG( "npcinit", "Other:count, id", Trade[3].count, id )
end
function OtherX( trade, id )
trade[3].count = trade[3].count + 1;
trade[3].item[trade[3].count] = id
end
function Synthesis( id )
--合成
Trade[4].count = Trade[4].count + 1;
Trade[4].item[Trade[4].count] = id
LG( "npcinit", "Synthesis:count, id", Trade[4].count, id )
end
--交易货物买卖收购信息
function SaleGoodsData( level, id, num, price, pricerange )
if level == nil or id == nil or num == nil or price == nil or pricerange == nil then
LG( "npcinit_error", "SaleGoodsData:Function parameter error!level, id, num, price, pricerange", level, id, num, price, pricerange )
return
end
Trade[1].count = Trade[1].count + 1
--记录货物数据
Trade[1].item[Trade[1].count] = {}
Trade[1].item[Trade[1].count].level = level
Trade[1].item[Trade[1].count].id = id
Trade[1].item[Trade[1].count].count = num
Trade[1].item[Trade[1].count].num = num
--物品价格信息
Trade[1].price[Trade[1].count] = {}
Trade[1].price[Trade[1].count].price = price
Trade[1].price[Trade[1].count].range = pricerange
Trade[1].price[Trade[1].count].curprice = price + Rand( pricerange )
LG( "npcinit_trade", "SaleGoodsData, count, level, id, num, price, range, curprice", Trade[1].count, level, id, num, price, pricerange, Trade[1].price[Trade[1].count].curprice )
end
--初始化黑市兑换信息
function InitExchange()
Exchange = {}
Exchange.count = 0
Exchange.srcid = {}
Exchange.srcnum = {}
Exchange.tarid = {}
Exchange.tarnum = {}
Exchange.timenum = {}
end
function InitExchangeX()
ExchangeX = {}
ExchangeX.count = 0
ExchangeX.srcid = {}
ExchangeX.srcnum = {}
ExchangeX.tarid = {}
ExchangeX.tarnum = {}
end
--黑市商人兑换
function ExchangeData( srcID, srcNum, tarID, tarNum, timeNum )
if srcID == nil or srcNum == nil or tarID == nil or tarNum == nil or timeNum == nil then
LG( "npcinit_error", "ExchangeData:函数参数错误!srcID, srcNum, tarID, tarNum, timeNum", srcID, srcNum, tarID, tarNum, timeNum )
return
end
Exchange.count = Exchange.count + 1
--兑换数据
Exchange.srcid[Exchange.count] = srcID
Exchange.srcnum[Exchange.count] = srcNum
Exchange.tarid[Exchange.count] = tarID
Exchange.tarnum[Exchange.count] = tarNum
Exchange.timenum[Exchange.count] = timeNum
end
function ExchangeDataX( srcID, srcNum, tarID, tarNum )
if srcID == nil or srcNum == nil or tarID == nil or tarNum == nil then
LG( "npcinit_error", "ExchangeDataX:函数参数错误!srcID, srcNum, tarID, tarNum", srcID, srcNum, tarID, tarNum )
return
end
ExchangeX.count = ExchangeX.count + 1
--兑换数据
ExchangeX.srcid[ExchangeX.count] = srcID
ExchangeX.srcnum[ExchangeX.count] = srcNum
ExchangeX.tarid[ExchangeX.count] = tarID
ExchangeX.tarnum[ExchangeX.count] = tarNum
end
--Leo的黑市商人加强版,全随机数
function DoExchange()
local intMoney =0
local intGoods =0
local intMoneyNum =0
local intNum=0
local intCount=0
for intCount=1 , 8 ,1 do
intNum = math.floor(math.random(1,4))
if intNum == 1 then --摩力符石2个
intMoney = 1028
intMoneyNum = 2
intGoods = MoliTable[math.floor(math.random(1,12))]
elseif intNum ==2 then --纳卡符石1个
intMoney = 3457
intMoneyNum = 1
intGoods = NakaTable[math.floor(math.random(1,22))]
elseif intNum ==3 then --精灵硬币1000个
intMoney = 855
intMoneyNum = 1000
intGoods = CoinTable1000[math.floor(math.random(1,36))]
elseif intNum ==4 then --精灵硬币600个
intMoney = 855
intMoneyNum = 600
intGoods = CoinTable600[math.floor(math.random(1,56))]
end
ExchangeData( intMoney, intMoneyNum , intGoods, 1, 1 )
end
end
function BuyGoodsData( level, id, num, price, pricerange )
if level == nil or id == nil or num == nil or price == nil or pricerange == nil then
LG( "npcinit_error", "BuyGoodsData:Function parameter error!level, id, num, price, pricerange", level, id, num, price, pricerange )
return
end
Trade[2].count = Trade[2].count + 1
--记录货物数据
Trade[2].item[Trade[2].count] = {}
Trade[2].item[Trade[2].count].level = level
Trade[2].item[Trade[2].count].id = id
Trade[2].item[Trade[2].count].count = num
Trade[2].item[Trade[2].count].num = num
--物品价格信息
Trade[2].price[Trade[2].count] = {}
Trade[2].price[Trade[2].count].price = price
Trade[2].price[Trade[2].count].range = pricerange
Trade[2].price[Trade[2].count].curprice = price + Rand( pricerange )
LG( "npcinit_trade", "BuyGoodsData, count, level, id, num, price, range, curprice", Trade[2].count, level, id, num, price, pricerange, Trade[2].price[Trade[2].count].curprice )
end
--货物交易出售物品价格数量更新
function UpdateGoodsData( tradenpc )
PRINT( "UpdateGoodsData" )
if tradenpc == nil then
PRINT( "UpdateGoodsData:Function parameter error!" )
LG( "UpdateGoodsData:Function parameter error!" )
return LUA_ERROR
end
local name = GetCharName( tradenpc )
local ret, id = GetScriptID( tradenpc )
if ret ~= LUA_TRUE then
PRINT( "UpdateGoodsData:GetScriptID, obtain npc"..name.."script notice ID failed!" )
LG( "npctrade_error", "UpdateGoodsData:GetScriptID, obtain npc"..name.."script notice ID failed!" )
return LUA_FALSE
end
if NpcInfoList == nil or NpcInfoList[id] == nil then
PRINT( "UpdateGoodsData:GetScriptID, npc"..name.."script notice does not exist! NpcInfoList, ID", NpcInfoList, id )
LG( "npctrade_error", "UpdateGoodsData:npc"..name.."script notice does not exist! NpcInfoList, ID", NpcInfoList, id )
return LUA_FALSE
end
PRINT( name..": update trade data notice" )
local trade = NpcInfoList[id].trade
for n = 1, trade[1].count, 1 do
trade[1].item[n].count = trade[1].item[n].num
trade[1].price[n].curprice = trade[1].price[n].price + Rand( trade[1].price[n].range )
PRINT( "Sell item: ID = , Count = , CurPrice = ", trade[1].item[n].id, trade[1].item[n].count, trade[1].price[n].curprice )
end
for n = 1, trade[2].count, 1 do
trade[2].item[n].count = trade[2].item[n].num
trade[2].price[n].curprice = trade[2].price[n].price + Rand( trade[2].price[n].range )
PRINT( "Purchase item: ID = , Count = , CurPrice = ", trade[2].item[n].id, trade[2].item[n].count, trade[2].price[n].curprice )
end
SendAllGoodsData( tradenpc, trade )
return LUA_TRUE
end
--定时更新出售货物种类
function UpdateGoodsKinds( tradenpc )
PRINT( "UpdateGoodsData" )
if tradenpc == nil then
PRINT( "UpdateGoodsData:函数参数错误!" )
LG( "UpdateGoodsData:函数参数错误!" )
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -