add events
This commit is contained in:
parent
ef4c43161d
commit
ea01c4db77
@ -107,3 +107,20 @@ rawset(_G, "lb_mapnum_from_extended", function(map)
|
||||
|
||||
return mapnum
|
||||
end)
|
||||
|
||||
local eventHandler = {}
|
||||
|
||||
rawset(_G, "lb_hook", function(event, callback)
|
||||
local handle = eventHandler[event] or {}
|
||||
table.insert(handle, callback)
|
||||
eventHandler[event] = handle
|
||||
end)
|
||||
|
||||
rawset(_G, "lb_fire_event", function(event, ...)
|
||||
local handle = eventHandler[event]
|
||||
if not handle then return end
|
||||
|
||||
for _, callback in ipairs(handle) do
|
||||
pcall(callback, ...)
|
||||
end
|
||||
end)
|
||||
|
@ -10,6 +10,7 @@ local lbComp = lb_comp
|
||||
local mapChecksum = lb_map_checksum
|
||||
local score_t = lb_score_t
|
||||
local mapnumFromExtended = lb_mapnum_from_extended
|
||||
local fireEvent = lb_fire_event
|
||||
|
||||
-- browser.lua
|
||||
local InitBrowser = InitBrowser
|
||||
@ -107,6 +108,9 @@ local scroll_to
|
||||
|
||||
local allowJoin
|
||||
|
||||
-- Events
|
||||
local EVENT_FINISH = "Finish"
|
||||
|
||||
|
||||
-- cvars
|
||||
local cv_teamchange
|
||||
@ -1157,6 +1161,9 @@ local function saveTime(player)
|
||||
if checkFlags(player) != Flags then
|
||||
print("Game mode change detected! Time has been disqualified.")
|
||||
S_StartSound(nil, 110)
|
||||
fireEvent(EVENT_FINISH, {
|
||||
disqualified = true,
|
||||
})
|
||||
return
|
||||
end
|
||||
|
||||
@ -1185,6 +1192,7 @@ local function saveTime(player)
|
||||
FlashRate = 3
|
||||
FlashVFlags = RedFlash
|
||||
scroll_to(player)
|
||||
fireEvent(EVENT_FINISH, {score = newscore})
|
||||
return
|
||||
end
|
||||
end
|
||||
@ -1206,6 +1214,12 @@ local function saveTime(player)
|
||||
-- Set the updated ScoreTable
|
||||
ScoreTable = MapRecords[Flags]
|
||||
|
||||
for i, score in ipairs(ScoreTable) do
|
||||
if score.name != player.name then continue end
|
||||
fireEvent(EVENT_FINISH, {position = i, score = newscore})
|
||||
break
|
||||
end
|
||||
|
||||
-- Scroll the gui to the player entry
|
||||
scroll_to(player)
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user