PDA

View Full Version : [TLBB] Script NPC Nhận Thưởng



thanhluan12a14
15-08-13, 04:04 PM
Script NPC Nhận Thưởng

Qua bài viết này mình sẽ hướng dẫn các bạn làm một NPC có chức năng đổi phần thưởng. Điều khác biệt của NPC này là có hình của Item mình muốn đổi
cũng như xem thông tin của nó như NPC Lương Sư Thành đổi bộ trang bị ngụ tứ. Hoặc dùng đễ hiễn thị vật phẩm khi trả Quest.
Nhưng mình thấy script của NPC phức tạp quá nên mình đã chỉnh sửa để cho nó đơn giản một chút.
Những NPC loại này thì trên Server có đầy các bạn có thể tham khảo thêm.

Mình sẽ làm một demo đơn giản. còn việc phát triển nó như thế nào thì tùy thuộc vào sự sáng tạo của các bạn.

1. Chuẩn bị: Add thêm NPC và Script mới cho NPC đó. Hoặc có thể sử dụng NPC có sẳn. (cái này trên diễn đàn chắc cũng nói nhiều rồi. )
trong Demo này mình đã tạo ra một NPC mới ở Đại Lý và Script gắn với nó có ID là 002100

2. Bắt đầu Script:



--=================================
-- 002100
--=================================
x002100_g_ScriptId = 002100
x002100_g_RadioItemBonus={{id=30103040 ,num=2345},{id=30103039,num=2345},{id=30103038,num =2345}}

--===========================================
-- On Default Event
--===========================================
function x002100_OnDefaultEvent( sceneId, selfId, targetId )
BeginEvent(sceneId)
AddText(sceneId," Các hÕ mu¯n có mµt dßþc ph¦m quý hiªm phäi không, · ch± ta có mµt ít ðây. ")
AddNumText( sceneId, x002100_g_ScriptId, "бi dßþc ph¦m th¥n kÏ", 6, 1 )
AddNumText( sceneId, x002100_g_ScriptId, "R¶i ði..", 0, 0 )

EndEvent(sceneId)
DispatchEventList(sceneId,selfId,targetId)

end

function x002100_OnEventRequest( sceneId, selfId, targetId, eventId )
local nNumText = GetNumText()

if nNumText == 0 then
BeginUICommand(sceneId)
EndUICommand(sceneId)
DispatchUICommand(sceneId,selfId, 1000)
return
end

if nNumText == 1 then
BeginEvent(sceneId)
AddText(sceneId, " Dßþc ph¦m này không th¬ cho không ðßþc.")
local szStr = " Mu¯n nh§n ðßþc dßþc ph¦m này, ngß½i c¥n phäi ðßa mang cho ta.";
AddText(sceneId, szStr)

for i, item in x002100_g_RadioItemBonus do
if item.num == 2345 then
AddRadioItemBonus( sceneId, item.id, 4 )
end
end
EndEvent(sceneId)
DispatchMissionContinueInfo(sceneId,selfId,targetI d, x002100_g_ScriptId, 0)
end
end

function x002100_OnMissionSubmit( sceneId, selfId, targetId, missionScriptId, selectRadioId )

--Kiem tra item can thiet co du so luong hay khong va xuat ra thong bao
if selectRadioId == 30103040 then
if GetItemCount(sceneId, selfId, 30001004) >= 50 and GetItemCount(sceneId, selfId, 30002004) >= 50 then
-- du item, bat dau xoa thu
if LuaFnDelAvailableItem(sceneId,selfId, 30001004, 50) == 1 and LuaFnDelAvailableItem(sceneId,selfId, 30002004, 50) == 1 then
-- them item
TryRecieveItem( sceneId, selfId, 30103040, 1 );
LuaFnSendSpecificImpactToUnit(sceneId,selfId,selfI d,selfId,18,0)
else
x002100_MsgBox( sceneId, selfId, targetId, "#{JPZB_0610_12}" )
return
end
else
x002100_MsgBox( sceneId, selfId, targetId, "#WC¥n #R50 #WPh¥n #YThái Thß½ng Hoàn #Wvà #R50 #WPh¥n #YLµc Nhung Ðan" )
return
end
end

if selectRadioId == 30103039 then
if GetItemCount(sceneId, selfId, 30002003) >= 50 then
-- du item, bat dau xoa thu
if LuaFnDelAvailableItem(sceneId,selfId, 30002003, 50) == 1 then
-- them item
TryRecieveItem( sceneId, selfId, 30103039, 4 );
LuaFnSendSpecificImpactToUnit(sceneId,selfId,selfI d,selfId,18,0)
else
x002100_MsgBox( sceneId, selfId, targetId, "#{JPZB_0610_12}" )
return
end
else
x002100_MsgBox( sceneId, selfId, targetId, "#WC¥n #R50 #WPh¥n #YQuy Linh Hoàn" )
return
end
end

if selectRadioId == 30103038 then
if GetItemCount(sceneId, selfId, 30001003) >= 50 then
-- du item, bat dau xoa thu
if LuaFnDelAvailableItem(sceneId,selfId, 30001003, 50) == 1 then
-- them item
TryRecieveItem( sceneId, selfId, 30103038, 4 );
LuaFnSendSpecificImpactToUnit(sceneId,selfId,selfI d,selfId,18,0)
else
x002100_MsgBox( sceneId, selfId, targetId, "#{JPZB_0610_12}" )
return
end
else
x002100_MsgBox( sceneId, selfId, targetId, "#WC¥n #R50 #WPh¥n #YKim Sáng Dßþc" )
return
end
end
end

--===========================================
-- Show A Message Box
--===========================================
function x002100_MsgBox( sceneId, selfId, targetId, Tip )
BeginEvent( sceneId )
AddText( sceneId, Tip )
EndEvent( sceneId )
DispatchEventList( sceneId, selfId, targetId )
end



Các bạn xem còn phần nào chưa hiểu thì đặt câu hỏi bên dưới, mình sẽ cố gắng trả lời.
chú Hà Hoàng có lẽ thích cái này. :D

tanhn
15-08-13, 05:41 PM
Script NPC Nhận Thưởng

Qua bài viết này mình sẽ hướng dẫn các bạn làm một NPC có chức năng đổi phần thưởng. Điều khác biệt của NPC này là có hình của Item mình muốn đổi
cũng như xem thông tin của nó như NPC Lương Sư Thành đổi bộ trang bị ngụ tứ. Hoặc dùng đễ hiễn thị vật phẩm khi trả Quest.
Nhưng mình thấy script của NPC phức tạp quá nên mình đã chỉnh sửa để cho nó đơn giản một chút.
Những NPC loại này thì trên Server có đầy các bạn có thể tham khảo thêm.

Mình sẽ làm một demo đơn giản. còn việc phát triển nó như thế nào thì tùy thuộc vào sự sáng tạo của các bạn.

1. Chuẩn bị: Add thêm NPC và Script mới cho NPC đó. Hoặc có thể sử dụng NPC có sẳn. (cái này trên diễn đàn chắc cũng nói nhiều rồi. )
trong Demo này mình đã tạo ra một NPC mới ở Đại Lý và Script gắn với nó có ID là 002100

2. Bắt đầu Script:



--=================================
-- 002100
--=================================
x002100_g_ScriptId = 002100
x002100_g_RadioItemBonus={{id=30103040 ,num=2345},{id=30103039,num=2345},{id=30103038,num =2345}}

--===========================================
-- On Default Event
--===========================================
function x002100_OnDefaultEvent( sceneId, selfId, targetId )
BeginEvent(sceneId)
AddText(sceneId," Các hÕ mu¯n có mµt dßþc ph¦m quý hiªm phäi không, · ch± ta có mµt ít ðây. ")
AddNumText( sceneId, x002100_g_ScriptId, "бi dßþc ph¦m th¥n kÏ", 6, 1 )
AddNumText( sceneId, x002100_g_ScriptId, "R¶i ði..", 0, 0 )

EndEvent(sceneId)
DispatchEventList(sceneId,selfId,targetId)

end

function x002100_OnEventRequest( sceneId, selfId, targetId, eventId )
local nNumText = GetNumText()

if nNumText == 0 then
BeginUICommand(sceneId)
EndUICommand(sceneId)
DispatchUICommand(sceneId,selfId, 1000)
return
end

if nNumText == 1 then
BeginEvent(sceneId)
AddText(sceneId, " Dßþc ph¦m này không th¬ cho không ðßþc.")
local szStr = " Mu¯n nh§n ðßþc dßþc ph¦m này, ngß½i c¥n phäi ðßa mang cho ta.";
AddText(sceneId, szStr)

for i, item in x002100_g_RadioItemBonus do
if item.num == 2345 then
AddRadioItemBonus( sceneId, item.id, 4 )
end
end
EndEvent(sceneId)
DispatchMissionContinueInfo(sceneId,selfId,targetI d, x002100_g_ScriptId, 0)
end
end

function x002100_OnMissionSubmit( sceneId, selfId, targetId, missionScriptId, selectRadioId )

--Kiem tra item can thiet co du so luong hay khong va xuat ra thong bao
if selectRadioId == 30103040 then
if GetItemCount(sceneId, selfId, 30001004) >= 50 and GetItemCount(sceneId, selfId, 30002004) >= 50 then
-- du item, bat dau xoa thu
if LuaFnDelAvailableItem(sceneId,selfId, 30001004, 50) == 1 and LuaFnDelAvailableItem(sceneId,selfId, 30002004, 50) == 1 then
-- them item
TryRecieveItem( sceneId, selfId, 30103040, 1 );
LuaFnSendSpecificImpactToUnit(sceneId,selfId,selfI d,selfId,18,0)
else
x002100_MsgBox( sceneId, selfId, targetId, "#{JPZB_0610_12}" )
return
end
else
x002100_MsgBox( sceneId, selfId, targetId, "#WC¥n #R50 #WPh¥n #YThái Thß½ng Hoàn #Wvà #R50 #WPh¥n #YLµc Nhung Ðan" )
return
end
end

if selectRadioId == 30103039 then
if GetItemCount(sceneId, selfId, 30002003) >= 50 then
-- du item, bat dau xoa thu
if LuaFnDelAvailableItem(sceneId,selfId, 30002003, 50) == 1 then
-- them item
TryRecieveItem( sceneId, selfId, 30103039, 4 );
LuaFnSendSpecificImpactToUnit(sceneId,selfId,selfI d,selfId,18,0)
else
x002100_MsgBox( sceneId, selfId, targetId, "#{JPZB_0610_12}" )
return
end
else
x002100_MsgBox( sceneId, selfId, targetId, "#WC¥n #R50 #WPh¥n #YQuy Linh Hoàn" )
return
end
end

if selectRadioId == 30103038 then
if GetItemCount(sceneId, selfId, 30001003) >= 50 then
-- du item, bat dau xoa thu
if LuaFnDelAvailableItem(sceneId,selfId, 30001003, 50) == 1 then
-- them item
TryRecieveItem( sceneId, selfId, 30103038, 4 );
LuaFnSendSpecificImpactToUnit(sceneId,selfId,selfI d,selfId,18,0)
else
x002100_MsgBox( sceneId, selfId, targetId, "#{JPZB_0610_12}" )
return
end
else
x002100_MsgBox( sceneId, selfId, targetId, "#WC¥n #R50 #WPh¥n #YKim Sáng Dßþc" )
return
end
end
end

--===========================================
-- Show A Message Box
--===========================================
function x002100_MsgBox( sceneId, selfId, targetId, Tip )
BeginEvent( sceneId )
AddText( sceneId, Tip )
EndEvent( sceneId )
DispatchEventList( sceneId, selfId, targetId )
end



Các bạn xem còn phần nào chưa hiểu thì đặt câu hỏi bên dưới, mình sẽ cố gắng trả lời.
chú Hà Hoàng có lẽ thích cái này. :D

=)) Sói chắc chắn là thích rồi
Thanks Thành Luân vì cống hiến mới nhaaaaaaaaaaaaaaaaaaaaaaaaaaa!
Chúc cậu ngày càng phát triển~!~

Sói Đẹp Trai
15-08-13, 05:53 PM
Thích quá ấy chư. Kết nhất cái vụ RadioItemBonus :)). Nhưng mà đang rối đầu, phải ngồi tu tâm dưỡng tính mới đọc code đc :)). Cái này đang đánh nhau với bài C++ vừa mới giải xong :))