function SecondsToClock(ElapsedTime)
if (ElapsedTime == nil or ElapsedTime == "") then
ElapsedTime = 99999999
end
local ms = tonumber(ElapsedTime)
local floor = math.floor
local seconds = floor(ms)
local minutes = floor(seconds / 60); seconds = floor(seconds % 60)
local hours = floor(minutes / 60); minutes = floor(minutes % 60)
if minutes < 10 then
minutes = "0"..minutes
end
if seconds < 10 then
seconds = "0"..seconds
end
if hours > 0 then
return hours..":"..minutes..":"..seconds
else
return minutes..":"..seconds
end
end
function NPC_FunArenaInitiate()
-- Make sure a global variable exists;
if (get_global_variable("FunzoA_Time_1") == "") or (get_global_variable("FunzoA_Name_1") == "") then
for i = 0, 22, 1
do
set_global_variable("FunzoA_Time_"..tostring(i), "999999999999")
set_global_variable("FunzoA_Name_"..tostring(i), "#NONE#")
end
end
dlg_text("Gamearena Funzo")
dlg_text("Oi! Greetings, fellow warrior. I'll be just standing here, looking at your pretty little butt, until Fyben gets more time to finish the work.")
dlg_menu("[ Gamemode #1 ]", "SelectFunzoArena_A()")
if tonumber(gv("permission")) == 100 then
dlg_menu("[ Remove #1 records ]", "RemoveFunzoRecordsA()")
dlg_menu("[ Reset layers ]", "ResetLayers()")
dlg_menu("[ Display usable layer ]", "cprint(tostring(SelectFreeLayer()))")
end
dlg_show()
end
function SelectFunzoArena_A()
dlg_text("Gamearena Funzo")
dlg_text("Gamemode #1 is all about killing as many bosses as possible in the shortest time.")
dlg_menu("[ BEGIN ]", "TeleToFunzo_A()")
dlg_menu("[ Current records ]", "DisplayFunzoArenaCurrentRecs_A()")
dlg_show()
end
function DisplayFunzoArenaCurrentRecs_A()
cprint("####################################################")
for i = 1, 21, 1
do
cprint("Level "..tostring(i).." record holder: "..get_global_variable("FunzoA_Name_"..tostring(i))..", time "..SecondsToClock(get_global_variable("FunzoA_Time_"..tostring(i)))..".")
end
cprint("####################################################")
end
function RemoveFunzoRecordsA()
for i = 1, 19, 1
do
del_global_variable("FunzoA_Time_"..tostring(i))
del_global_variable("FunzoA_Name_"..tostring(i))
end
cprint("All record flags have been removed.")
end
function TeleToFunzo_A()
-- Make sure all flags are deleted;
RemoveFunzoA_Flags()
-- Make sure we have unused layers;
local FreeLayer = tonumber(SelectFreeLayer())
if FreeLayer == 256 then
cprint("There are no layers available to be used right now. Please try again later.")
return
end
-- Warp to arena;
warp(72504, 88636)
-- Set flag;
set_flag("funzo_a", "1")
set_flag("funzo_a_lv", "1")
-- Give leave item;
insert_item(1504, 1, 0, 1, 2)
cprint("You have received x1 "..get_item_name_by_code(1504)..".")
cprint("<#f1c40f>Double click on "..get_item_name_by_code(1504).."<#f1c40f> to start the gamemode.")
add_state(6007, 1, 999999999)
add_state(6014, 1, 999999999)
add_state(314015, 1, 999999999)
end
function SelectFreeLayer()
for i = 1, 256, 1
do
if (get_global_variable("funzo_layer_"..tostring(i)) == "") or (get_global_variable("funzo_layer_"..tostring(i)) == nil) then
return i
else
local LayerLastUsed = tonumber(get_global_variable("funzo_layer_"..tostring(i)))
local TimeNow = tonumber(get_os_time())
if TimeNow-LayerLastUsed > 3600 then
del_global_variable("funzo_layer_"..tostring(i))
end
end
end
end
function ResetLayers()
for i = 1, 255, 1
do
del_global_variable("funzo_layer_"..tostring(i))
end
end
function StartFunzoWave()
local FreeLayer = SelectFreeLayer()
remove_state(6007, 1)
remove_state(6014, 1)
remove_state(314015, 1)
insert_item(1503, 1, 0, 1, 2)
cprint("You have received x1 "..get_item_name_by_code(1503)..".")
set_global_variable("funzo_layer_"..tostring(FreeLayer), tostring(get_os_time()))
warp(gv("x"), gv("y"), FreeLayer)
-- Give some instructions;
cprint("####################################################")
cprint("Funzo gamearena 'Gamemode #1'.")
cprint("Your objective is to survive as many bosses as possible. If you fail to kill the boss within 15 minutes it will disappear and you must leave the arena.")
cprint("####################################################")
-- Add first mob;
cprint("-")
cprint(" <#f1c40f>--- [ BOSS #1 ] ---")
cprint("-")
set_flag("funzo_a_start", tostring(get_os_time()))
add_npc(gv("x"), gv("y"), 6500, 1, 90000, FreeLayer)
end
function FunzoMobDead()
-- Check if arena flag has been set;
local mf = get_flag("funzo_a")
if mf == "" then
TeleOutOfFunzoA_Arena()
return
end
local WaveLevel = tonumber(get_flag("funzo_a_lv"))
if WaveLevel == 22 then
set_flag("funzo_a_stop", tostring(get_os_time()))
del_global_variable("funzo_layer_"..tostring(gv("layer")))
local s = tonumber(get_flag("funzo_a_start"))
local e = tonumber(get_os_time())
local totalTime = tostring(""..SecondsToClock(e-s).."")
cprint("Current time: "..totalTime)
local RecordTime = get_global_variable("FunzoA_Time_"..tostring(WaveLevel-1))
if tonumber(e-s) < tonumber(RecordTime) then
set_global_variable("FunzoA_Time_"..tostring(WaveLevel), tostring(e-s))
set_global_variable("FunzoA_Name_"..tostring(WaveLevel), gv("name"))
announce(gv("name").." has just beaten Funzos Gamearena #1 (level "..tostring(WaveLevel)..") record with the time of "..totalTime.."!")
end
EndGamearenaFunzoA()
return
else
-- Spawn next mob;
add_npc(gv("x"), gv("y"), 6500+WaveLevel, 1)
local s = tonumber(get_flag("funzo_a_start"))
local e = tonumber(get_os_time())
local totalTime = tostring(""..SecondsToClock(e-s).."")
cprint("Current time: "..totalTime)
local RecordTime = get_global_variable("FunzoA_Time_"..tostring(WaveLevel))
if tonumber(e-s) < tonumber(RecordTime) then
set_global_variable("FunzoA_Time_"..tostring(WaveLevel), tostring(e-s))
set_global_variable("FunzoA_Name_"..tostring(WaveLevel), gv("name"))
announce(gv("name").." has just beaten Funzos Gamearena #1 (level "..tostring(WaveLevel)..") record with the time of "..totalTime.."!")
end
if WaveLevel < 21 then
cprint("-")
cprint(" <#f1c40f>--- [ BOSS #"..tostring(WaveLevel+1).." ] ---")
cprint("-")
end
set_flag("funzo_a_lv", WaveLevel+1)
end
end
function EndGamearenaFunzoA()
-- Make some variables;
local WaveLevel = tonumber(get_flag("funzo_a_lv"))-1
-- Display end message;
if WaveLevel > 0 then
cprint("####################################################")
cprint("Current record holder: "..get_global_variable("FunzoA_Name_"..tostring(WaveLevel)).."")
cprint("Record time: "..SecondsToClock(get_global_variable("FunzoA_Time_"..tostring(WaveLevel))).."")
cprint("####################################################")
end
if WaveLevel == 22 then
whisper(gv("name"), "Congratulations! You have killed all of the bosses within "..totalTime..".")
elseif WaveLevel == 0 then
whisper(gv("name"), "You have quit the gamemode without killing a single boss.")
TeleOutOfFunzoA_Arena()
return
else
whisper(gv("name"), "You have killed bosses up to level "..tostring(WaveLevel)..".")
end
-- Tele out of arena;
TeleOutOfFunzoA_Arena()
end
function TeleOutOfFunzoA_Arena()
delete_item(get_item_handle(1503), 1)
delete_item(get_item_handle(1504), 1)
RemoveFunzoA_Flags()
warp(153551,77228, 0)
cprint("You have been teleported out of Funzo arena.")
set_global_variable("funzo_layer_"..tostring(gv("layer")), tonumber(get_os_time()-2700))
end
function RemoveFunzoA_Flags()
del_flag("funzo_a")
del_flag("funzo_a_lv")
del_flag("funzo_a_start")
del_flag("funzo_a_stop")
del_flag("funzo_a_end")
del_flag("funzo_a_exit")
end