trứng
x559731_g_ScriptId = 559731
x559731_g_BoxItem = 30002031
x559731_g_TableItem = {}
x559731_g_TableItem[1] = {30504190,20310020,30700230,20501002,20502002} -- 10 l¥n
x559731_g_TableItem[2] = {30000265,20501002,20502002,20501003,20502003,30509014,30504190,30700230,20501002,20502002} -- 50 l¥n
x559731_g_TableItem[3] = {30505816,30505804,30000265,20501002,20502002,20501003,20502003,20501002,20502002,20501003,20502003,30509014,20501002,20502002,30504190,30700230,20501002,20502002} -- 100 l¥n
x559731_g_TableItem[4] = {30008030,30900015,30505816,30505804,30000265,20501002,20502002,20501003,20502003,20501002,20502002,20501003,20502003,30509014,20501002,20502002,30008029,30505107,30504190,30700230,20501002,20502002} -- 200 l¥n
x559731_g_TableItem[5] = {30000012,30000266,20501004,20502004,30505107,10410151,10141693,30505107,30505816,30505804,30000265,20501002,30505107,20502002,20501003,20502003,30505107,20501002,20502002,20501003,20502003,30509014,30008105,30900048,30700308,30504190,30700230,20501002,20502002} -- 500 l¥n
x559731_g_TableItem[6] = {30505816,30505804,30505107,30000265,20501002,20502002,20501003,30505107,20502003,20501002,20502002,20501003,30505107,20502003,30509014,20501002,20502002,30505107,30504190,30700230,20501002,20502002,50413104,10141690,10410153,30000135,30000012,30000266,20501004,20502004,20310113,30505816,10125500,20501002,20502002,20501003,20502003,30509014,30504190,30700230,20501002,20502002,30505816,30000265,20501002,20502002,20501003,20502003,20501002,20502002,20501003,20502003,30509014,20501002,20502002,20501002,20502002} -- 1000 l¥n
x559731_g_TableItem[7] = {30504190,20310020,30700230,30505107,20501002,20502002,20109101,30000265,20501002,30505107,20502002,20501003,20502003,30509014,30505107,30504190,20501002,20502002,30505107,20501003,20502003,30509014,30504190,20501002,20502002,20501003,20502003,30509014,30504190,30000265,20501002,20502002,30402058,20501003,20502003,30509014} -- 10 l¥n
x559731_g_TableItem[8] = {30505816,30505804,30505107,30900015,30000265,20501002,20502002,20501003,30505107,20502003,20501002,20502002,20501003,30505107,20502003,30509014,20501002,20502002,30505107,30504190,30700230,20501002,20502002,50413104,10141690,10410153,30000135,30000012,30000266,20501004,20502004,10410151,30402046,30402036,30008030,10141693,30505816,10125500,20501002,20502002,20501003,20502003,30509014,30700230,20501002,20502002,20501002,20502002,20501003,20502003,20501002,20502002,20501003,20502003,30509014,20501002,20502002,30700230,20501002,20502002} -- 1000 l¥n
x559731_g_TableItem[9] = {30505816,30505804,30505107,10125500,30000265,20501002,20502002,20501003,30505107,20502003,20501002,20502002,20501003,30505107,20502003,30509014,20501002,30308043,30505107,20502002,30504190,30700230,20501002,20502002,30008053,50413104,10141690,10410153,30000135,30000012,30000266,20501004,20502004,10410151,10141693,30505816,10125500,30000265,20501002,20502002,20501003,20502003,30509014,30700230,20501002,20502002,20501002,20502002,20501003,20502003,20501002,20502002,20501003,20502003,30509014,20501002,20502002,30700230,20501002,20502002} -- 1000 l¥n
-- s¯ l¥n c¥n thiªt cho t×ng list
x559731_g_RequiredCounts = {10, 50, 100, 200, 500, 1000, 2000, 5000, 10000}
--**********************************
function x559731_OnDefaultEvent(sceneId, selfId, bagIndex)
end
function x559731_IsSkillLikeScript(sceneId, selfId)
return 1
end
function x559731_CancelImpacts(sceneId, selfId)
return 0
end
function x559731_OnConditionCheck(sceneId, selfId)
local PropertySpace = LuaFnGetPropertyBagSpace(sceneId, selfId)
local MaterialSpace = LuaFnGetMaterialBagSpace(sceneId, selfId)
if PropertySpace < 2 or MaterialSpace < 2 then
x559731_ShowNotice(sceneId, selfId, "Túi ðÕo cø và nguyên li®u c¥n ít nh¤t 2 ô tr¯ng!")
return 0
end
local totalSpace = PropertySpace + MaterialSpace
if totalSpace <= 4 then
x559731_ShowNotice(sceneId, selfId, "Túi ðÕo cø và nguyên li®u c¥n ít nh¤t 2 ô tr¯ng!")
end
return 1
end
function x559731_OnDeplete(sceneId, selfId)
if LuaFnDepletingUsedItem(sceneId, selfId) > 0 then
return 1
end
return 0
end
function x559731_OnActivateOnce(sceneId, selfId)
local PropertySpace = LuaFnGetPropertyBagSpace(sceneId, selfId)
local MaterialSpace = LuaFnGetMaterialBagSpace(sceneId, selfId)
if PropertySpace < 1 and MaterialSpace < 1 then
x559731_ShowNotice(sceneId, selfId, "Túi ðÕo cø và nguyên li®u c¥n ít nh¤t 2 ô tr¯ng!")
Msg2Player(sceneId, selfId, "Túi ðÕo cø và nguyên li®u c¥n ít nh¤t 2 ô tr¯ng")
BeginUICommand(sceneId)
UICommand_AddInt(sceneId, 1)
EndUICommand(sceneId)
DispatchUICommand(sceneId, selfId, 1000)
return 0
end
if PropertySpace < 2 then
Msg2Player(sceneId, selfId, "Túi ðÕo cø và nguyên li®u c¥n ít nh¤t 2 ô tr¯ng!")
elseif MaterialSpace < 2 then
Msg2Player(sceneId, selfId, "Túi ðÕo cø và nguyên li®u c¥n ít nh¤t 2 ô tr¯ng!")
end
local playerName = GetName(sceneId, selfId)
local playerGuid = 0
if LuaFnObjId2Guid then
playerGuid = LuaFnObjId2Guid(sceneId, selfId) or 0
end
local countFile = "Var/BoxOpen/" .. playerGuid .. ".txt"
local currentCount = x559731_GetTXTNumContain(countFile) or 0
currentCount = currentCount + 1
x559731_SetTXTNumContain(countFile, currentCount)
local unlockedLists = {}
local totalUnlockedItems = 0
for listIndex = 1, getn(x559731_g_TableItem) do
local requiredCount = x559731_g_RequiredCounts[listIndex]
if currentCount >= requiredCount then
local listItems = x559731_g_TableItem[listIndex]
for i = 1, getn(listItems) do
totalUnlockedItems = totalUnlockedItems + 1
unlockedLists[totalUnlockedItems] = {
itemId = listItems[i],
listIndex = listIndex
}
end
end
end
if totalUnlockedItems == 0 then
local listItems = x559731_g_TableItem[1]
for i = 1, getn(listItems) do
totalUnlockedItems = totalUnlockedItems + 1
unlockedLists[totalUnlockedItems] = {
itemId = listItems[i],
listIndex = 1
}
end
end
local randomIndex = random(1, totalUnlockedItems)
local selectedData = unlockedLists[randomIndex]
local selectedItem = selectedData.itemId
local fromListIndex = selectedData.listIndex
local ret = -1
local addSuccess = 0
-- check túi ð° và add item
if PropertySpace > 1 and MaterialSpace > 1 then
-- thØ add item vào túi
ret = TryRecieveItem(sceneId, selfId, selectedItem, 1)
if ret >= 0 then
addSuccess = 1
-- Msg2Player(sceneId, selfId, "[SUCCESS] Da add item vao tui do!")
end
end
-- if addSuccess == 0 and MaterialSpace > 1 then
-- -- add vào túi nl
-- ret = LuaFnTryRecieveItem(sceneId, selfId, selectedItem, 1)
-- if ret >= 0 then
-- addSuccess = 1
-- -- Msg2Player(sceneId, selfId, "[SUCCESS] Da add item vao tui nguyen lieu!")
-- end
-- end
-- -- nªu ko add dc item thì thØ cách khác
-- if addSuccess == 0 then
-- -- add trñc tiªp
-- ret = AddItem(sceneId, selfId, selectedItem, 1)
-- if ret >= 0 then
-- addSuccess = 1
-- -- Msg2Player(sceneId, selfId, "[SUCCESS] Da add item bang AddItem!")
-- end
-- end
-- if addSuccess == 0 then
-- -- Cách 4: BeginAddItem/EndAddItem
-- BeginAddItem(sceneId)
-- AddItem(sceneId, selectedItem, 1)
-- ret = EndAddItem(sceneId, selfId)
-- if ret >= 0 then
-- addSuccess = 1
-- -- Msg2Player(sceneId, selfId, "[SUCCESS] Da add item bang BeginAddItem!")
-- end
-- end
if addSuccess == 0 then
x559731_ShowNotice(sceneId, selfId, "Vui lòng ki¬m tra lÕi túi ð°!")
return 0
end
local ItemName = "Item " .. selectedItem
local dropDetails = ItemName .. " (List " .. fromListIndex .. ")"
LuaFnSendSpecificImpactToUnit(sceneId, selfId, selfId, selfId, 18, 0)
x559731_WriteLuaDropLog(sceneId, selfId, playerName, playerGuid, selectedItem, ItemName, fromListIndex, currentCount)
-- thông báo nªu item hiªm
-- if fromListIndex >= 9 then
-- x559731_ShowSystemNotice(sceneId, selfId, ItemName, fromListIndex, currentCount)
-- end
return 1
end
function x559731_OnActivateEachTick(sceneId, selfId)
return 1
end
function x559731_WriteLuaDropLog(sceneId, playerObjId, playerName, playerGuid, itemId, itemName, listIndex, openCount)
local ItemName = GetItemName(sceneId, itemId)
local timeStr = date('%Y-%m-%d %H:%M:%S')
local logLine = format('[%s] l¥n %d: %s nh§n ðßþc %s(%s) - List %d\n',
timeStr,
openCount,
playerName,
itemId,
ItemName or "Unknown",
listIndex)
local playerLogPaths = {
'Var/BoxOpen/Player_'..playerGuid..'.log',
'Var/BoxOpen/Player_'..playerName..'.log',
'Player_'..playerGuid..'.log'
}
for i = 1, getn(playerLogPaths) do
local playerLog = openfile(playerLogPaths[i], 'a+')
if playerLog then
write(playerLog, logLine)
closefile(playerLog)
break
end
end
end
function x559731_ShowSystemNotice(sceneId, selfId, itemName, listIndex, count)
local playerName = GetName(sceneId, selfId)
local playerInfoName = "#{_INFOUSR" .. playerName .. "}"
local sysStr = playerInfoName .. " ðã m· " .. count .. " l¥n và nh§n ðßþc " .. itemName
BroadMsgByChatPipe(sceneId, selfId, sysStr, 4)
end
function x559731_ShowNotice(sceneId, selfId, strNotice)
BeginEvent(sceneId)
AddText(sceneId, strNotice)
EndEvent(sceneId)
DispatchMissionTips(sceneId, selfId)
end
function x559731_GetTXTNumContain(filename)
local num = 0
local file = openfile(filename, "r")
if file then
local content = read(file, "*n")
if content then
num = content
end
closefile(file)
end
return num
end
function x559731_SetTXTNumContain(filename, num)
local file = openfile(filename, "w")
if file then
write(file, tostring(num))
closefile(file)
return 1
end
return 0
end