Sói Đẹp Trai
29-09-17, 12:29 AM
Mình có đoạn code sau về phụ bản bạn chịu khó đọc dịch và hiểu nhé. Còn add vào thì nó như các pb thường thôi. Bạn tham khảo các pb của bọn tàu nó làm ấy chỉ cần bước đó là đủ.
Code tổng quát của pb có dạng như sau
--Powered by TLBB-LuaEditor
--Script: YOUR SCRIPT DESCRIPTION
--Author: YOUR NAME
--Date: CURRENT DATE
--************************--
x000000_g_ScriptId = 000000 --ID of this script. Remember replace all 000000 text by your script index with exactly 6 digits
--************************--
x000000_g_CopySceneType = --This constant is the index of this CopyScene. Find it at ScriptGlobal and register it at scene.lua. (Eg: FUBEN_TEST)
x000000_g_CopySceneLifeTime = --The lifetime of this CopyScene (milis)
x000000_g_CopySceneMissionData = --The MD of this CopyScene (Ex: MD_FUBEN_TEST)
x000000_g_LoadMonster = "_monster.ini" --Set loading monster file for this CopyScene (Ex: "test_monster.ini")
x000000_g_LoadScene = ".nav" --Set loading scene file for this CopyScene (Ex: "test.nav")
x000000_g_LoadArea = "_area.ini" --Set loading area file for this CopyScene (Ex: "test_area.ini")
x000000_g_NoUserTime = 5000 --The time of closing CopyScene while no player is inside (milis)
x000000_g_Relive_PosX = --The relive position X of player at the CopyScene
x000000_g_Relive_PosY = --The relive position Y of player at the CopyScene
x000000_g_Limit_Member = --The minimum number of player that able to attend this CopyScene
x000000_g_TurnPerDay = --The maximum number of attending time of player at this CopyScene
x000000_g_Need_Level = --The minimum level of player that able to attend this CopyScene
--These values belows should be default
x000000_g_CopySceneTimer = 9 --Variable index 10 stores the time of CopyScene to generate MilisTime
x000000_g_CopySceneTimeLeft = 10 --Variable index 10 stores the time left of CopyScene
x000000_g_CopySceneStep = 11 --Controller step of CopyScene
-- TODO init some variables index below with value range [12..36]
--************************--
--================================================== =======--
-- [DEFAULT]
-- This function is called to add the selection of this event to a NPC
-- sceneId: ID of current scene
-- playerId: ID of player
-- targetId: ID of NPC
--================================================== =======--
function x000000_OnEnumerate(sceneId,playerId,targetId)
--************************--
AddNumText(sceneId,x000000_g_ScriptId,"Create copy scene",3,0)
AddNumText(sceneId,x000000_g_ScriptId,"Leave",3,1)
--************************--
-- TODO your code below.
--************************--
end
--================================================== =======--
-- [DEFAULT]
-- This function is called to catch the selection event of this event
-- sceneId: ID of current scene
-- playerId: ID of player
-- targetId: ID of NPC
--================================================== =======--
function x000000_OnDefaultEvent(sceneId,playerId,targetId)
--************************--
if GetNumText()==0 then
local result,nTip=x000000_OnCheckCondition(sceneId,playe rId)
if result==0 then
BeginEvent(sceneId)
AddText(sceneId,nTip)
EndEvent(sceneId)
DispatchEventList(sceneId,playerId,targetId)
return
end
x000000_MakeCopyScene(sceneId,playerId)
end
--************************--
if GetNumText()==1 then
BeginUICommand(sceneId)
EndUICommand(sceneId)
DispatchUICommand(sceneId,playerId,1000)
end
--************************--
-- TODO your code below.
--************************--
end
--================================================== =======--
-- [ADDITION]
-- This function is called to check some conditions of player before entering
-- sceneId: ID of current scene
-- playerId: ID of player
--================================================== =======--
function x000000_OnCheckCondition(sceneId,playerId)
--************************--
if LuaFnHasTeam(sceneId,playerId)~=1 then
return 0,"You need to join in a team!"
end
--************************--
if GetTeamLeader(sceneId,playerId)~=playerId then
return 0,"You are not team leader!"
end
--************************--
if GetTeamSize(sceneId,playerId)<x000000_g_Limit_Member then
return 0,"Your team needs to have at least #G"..x000000_g_Limit_Member.."#W member!"
end
--************************--
local NearTeamSize = GetNearTeamCount(sceneId,playerId)
if GetTeamSize(sceneId,playerId)~=NearTeamSize then
return 0,"Your teammates need to stay near by me!"
end
--************************--
local Humanlist={}
local nHumanNum=0
for i=0,NearTeamSize-1 do
local teammateId=GetNearTeamMember(sceneId,playerId,i)
if GetLevel(sceneId,teammateId)<x000000_g_Need_Level then
Humanlist[nHumanNum]=GetName(sceneId,teammateId)
nHumanNum = nHumanNum+1
end
end
if nHumanNum > 0 then
local msg="Your team has "
for i=0,nHumanNum-2 do
msg=msg..Humanlist[i]..", "
end
msg=msg..Humanlist[nHumanNum-1].." whose level is not enough #G"..x000000_g_Need_Level..", can`t join in this event!"
return 0,msg
end
--************************--
local Humanlist={}
local nHumanNum=0
local CurDayTime = GetDayTime()
for i=0,NearTeamSize-1 do
local teammateId=GetNearTeamMember(sceneId,playerId,i)
local lastTime = GetMissionData(sceneId,teammateId,x000000_g_CopySc eneMissionData)
local lastDayTime = floor(lastTime/100)
local lastDayCount = mod(lastTime,100)
if CurDayTime > lastDayTime then
lastDayTime = CurDayTime
lastDayCount = 0
end
if lastDayCount >= x000000_g_TurnPerDay then
Humanlist[nHumanNum]=GetName(sceneId,teammateId)
nHumanNum = nHumanNum+1
end
end
if nHumanNum > 0 then
local msg="Your team has "
for i=0,nHumanNum-2 do
msg=msg..Humanlist[i]..", "
end
msg=msg..Humanlist[nHumanNum-1].." who attent that event enough times today!"
return 0,msg
end
--************************--
end
--================================================== =======--
-- [ADDITION]
-- This function is called to create the copy scene
-- sceneId: ID of current scene
-- playerId: ID of player
--================================================== =======--
function x000000_MakeCopyScene(sceneId,playerId)
--************************--
local x,y=GetWorldPos(sceneId,playerId)
LuaFnSetSceneLoad_Map(sceneId,x000000_g_LoadScene)
LuaFnSetCopySceneData_TeamLeader(sceneId,LuaFnObjI d2Guid(sceneId,playerId))
LuaFnSetCopySceneData_NoUserCloseTime(sceneId,x000 000_g_NoUserTime)
LuaFnSetCopySceneData_Timer(sceneId,1)
LuaFnSetCopySceneData_Param(sceneId,0,x000000_g_Co pySceneType)
LuaFnSetCopySceneData_Param(sceneId,1,x000000_g_Sc riptId)
LuaFnSetCopySceneData_Param(sceneId,2,0)
LuaFnSetCopySceneData_Param(sceneId,3,sceneId)
LuaFnSetCopySceneData_Param(sceneId,4,x)
LuaFnSetCopySceneData_Param(sceneId,5,y)
LuaFnSetCopySceneData_Param(sceneId,6,GetTeamId(sc eneId,playerId))
LuaFnSetCopySceneData_Param(sceneId,7,0)
--************************--
for i=8,31 do
LuaFnSetCopySceneData_Param(sceneId,i,0)
end
--************************--
LuaFnSetSceneLoad_Area(sceneId,x000000_g_LoadArea)
LuaFnSetSceneLoad_Monster(sceneId,x000000_g_LoadMo nster)
local bRetSceneID=LuaFnCreateCopyScene(sceneId)
BeginEvent(sceneId)
if bRetSceneID>0 then
AddText(sceneId,"Transfer succeeded!")
else
AddText(sceneId,"Over number of copyscene. Please try again later!")
end
EndEvent(sceneId)
DispatchMissionTips(sceneId,playerId)
--************************--
end
--================================================== =======--
-- [DEFAULT]
-- This function is called to take players to the copy scene. This function should be kept default
-- sceneId: ID of current scene
-- destsceneId: ID of target scene
--================================================== =======--
function x000000_OnCopySceneReady(sceneId,destsceneId)
--************************--
LuaFnSetCopySceneData_Param(destsceneId,3,sceneId)
leaderguid=LuaFnGetCopySceneData_TeamLeader(destsc eneId)
leaderObjId=LuaFnGuid2ObjId(sceneId,leaderguid)
local nearteammembercount=GetNearTeamCount(sceneId,leade rObjId)
local mems={}
for i=0,nearteammembercount-1 do
mems[i]=GetNearTeamMember(sceneId,leaderObjId,i)
NewWorld(sceneId,mems[i],destsceneId,x000000_g_Relive_PosX,x000000_g_Reliv e_PosY)
end
--************************--
end
--================================================== =======--
-- [DEFAULT]
-- This function is called every short tick lifetimer of this copy scene
-- sceneId: ID of current scene
-- nowTime: Current system time
--================================================== =======--
function x000000_OnCopySceneTimer(sceneId,nowTime)
--************************--
local nTick = x000000_UpdateTimerMilis(sceneId,nowTime) --This is the milis time, use it base on your goal
x000000_ShowCopySceneTimer(sceneId,nTick)
--************************--
local nStep = LuaFnGetCopySceneData_Param(sceneId,x000000_g_Copy SceneStep)
--************************--
if nStep==0 then
x000000_InitCopySceneData(sceneId)
LuaFnSetCopySceneData_Param(sceneId,x000000_g_Copy SceneStep,1)
end
--************************--
-- TODO your code below. with `nStep` start with value = 1
--************************--
end
--================================================== =======--
-- [DEFAULT]
-- This function is called to do something when players enter copy scene (includes disconnect then reconnect)
-- sceneId: ID of current scene
-- playerId: ID of player
--================================================== =======--
function x000000_OnPlayerEnter(sceneId,playerId)
--************************--
local lastTime = GetMissionData(sceneId,playerId,x000000_g_CopyScen eMissionData)
local lastDayTime = floor(lastTime/100)
local lastDayCount = mod(lastTime,100)
local CurDayTime = GetDayTime()
if CurDayTime > lastDayTime then
lastDayTime = CurDayTime
lastDayCount = 0
end
lastDayCount = lastDayCount+1
lastTime = lastDayTime*100+lastDayCount
--************************--
SetMissionData(sceneId,playerId,x000000_g_CopyScen eMissionData,lastTime)
--************************--
SetPlayerDefaultReliveInfo(sceneId,playerId,"%10",-1,"0",sceneId,x000000_g_Relive_PosX,x000000_g_Relive_Po sY)
--************************--
-- TODO your code below.
--************************--
end
--================================================== =======--
-- [ADDITION]
-- This function is called to update the timeleft of copy scene
-- sceneId: ID of current scene
-- nowTime: Current system time
--================================================== =======--
function x000000_UpdateTimerMilis(sceneId,nowTime)
--************************--
if LuaFnGetCopySceneData_Param(sceneId,x000000_g_Copy SceneTimeLeft)==0 then
LuaFnSetCopySceneData_Param(sceneId,x000000_g_Copy SceneTimeLeft,x000000_g_CopySceneLifeTime)
end
--************************--
local nTick = nowTime-LuaFnGetCopySceneData_Param(sceneId,x000000_g_Copy SceneTimeLeft)
LuaFnSetCopySceneData_Param(sceneId,x000000_g_Copy SceneTimeLeft,nowTime)
return nTick
--************************--
end
--================================================== =======--
-- [ADDITION]
-- This function is called to show the copyscene timeleft to player
-- sceneId: ID of current scene
-- nTick: The milis timer between previous call and current call
--================================================== =======--
function x000000_ShowCopySceneTimer(sceneId,nTick)
--************************--
local timeLeft = LuaFnGetCopySceneData_Param(sceneId,x000000_g_Copy SceneTimeLeft)-nTick
LuaFnSetCopySceneData_Param(sceneId,x000000_g_Copy SceneTimeLeft,timeLeft)
--************************--
-- TODO your code below.
--************************--
end
--================================================== =======--
-- [ADDITION]
-- This function is called to initialize some paramaters of copyscene
-- sceneId: ID of current scene
--================================================== =======--
function x000000_InitCopySceneData(sceneId)
--************************--
-- TODO your code below.
--************************--
end
--================================================== =======--
-- [ADDITION]
-- This function is called to kick out all players from this copy scene
-- You need to call it when you want to do this action
-- sceneId: ID of current scene
--================================================== =======--
function x000000_KickOutAllPlayer(sceneId)
--************************--
local nHumanNum=LuaFnGetCopyScene_HumanCount(sceneId)
local Scene=LuaFnGetCopySceneData_Param(sceneId,3)
local x=LuaFnGetCopySceneData_Param(sceneId,4)
local y=LuaFnGetCopySceneData_Param(sceneId,5)
for i=0,nHumanNum-1 do
local teamMateId=LuaFnGetCopyScene_HumanObjId(sceneId,i)
if LuaFnIsObjValid(sceneId,teamMateId)==1 and LuaFnIsCanDoScriptLogic(sceneId,teamMateId)==1 then
CallScriptFunction((400900),"TransferFunc",sceneId,teamMateId,Scene,x,y)
end
end
--************************--
end
--================================================== =======--
-- [ADDITION]
-- This function is called to show notification tip to all players inside this copy scene
-- You need to call it when you want to do this action
-- sceneId: ID of current scene
--================================================== =======--
function x000000_TipAllHuman(sceneId,nTip)
--************************--
local nHumanNum=LuaFnGetCopyScene_HumanCount(sceneId)
for i=0,nHumanNum-1 do
local teamMateId=LuaFnGetCopyScene_HumanObjId(sceneId,i)
if LuaFnIsObjValid(sceneId,teamMateId)==1 and LuaFnIsCanDoScriptLogic(sceneId,teamMateId)==1 then
BeginEvent(sceneId)
AddText(sceneId,nTip)
EndEvent(sceneId)
DispatchMissionTips(sceneId,teamMateId)
end
end
--************************--
end
Được gọi qua 1 NPC như này.
--Powered by TLBB-LuaEditor
--Script: YOUR SCRIPT DESCRIPTION
--Author: YOUR NAME
--Date: CURRENT DATE
--************************--
x000000_g_ScriptId = 000000 --ID of this script. Remember replace all 000000 text by your script index with exactly 6 digits
--************************--
x000000_g_Event_ScriptId = 000001 --Script event. Remember replace 000001 by the script index of your target event
--************************--
--================================================== =======--
-- [DEFAULT]
-- This function is called firstly when a player clicks on NPC
-- sceneId: ID of current scene
-- playerId: ID of player
-- targetId: ID of NPC
--================================================== =======--
function x000000_OnDefaultEvent(sceneId,playerId,targetId)
--************************--
BeginEvent(sceneId)
AddText(sceneId,"SOME TEXT")
CallScriptFunction(x000000_g_Event_ScriptId,"OnEnumerate",sceneId,playerId,targetId)
EndEvent(senceId)
DispatchEventList(sceneId,playerId,x000000_g_Scrip tId)
--************************--
end
--================================================== =======--
-- [DEFAULT]
-- This function is called when a selection is detected
-- sceneId: ID of current scene
-- playerId: ID of player
-- targetId: ID of NPC
-- eventId: ID of selection event (Don`t need to pay attention to it)
--================================================== =======--
function x000000_OnEventRequest(sceneId,playerId,targetId,e ventId)
--************************--
if eventId==x000000_g_Event_ScriptId then
CallScriptFunction(eventId,"OnDefaultEvent",sceneId,playerId,targetId)
return
end
--************************--
end
Powered by vBulletin® Version 4.2.0 Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.