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
|
return mapnum
|
||||||
end)
|
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 mapChecksum = lb_map_checksum
|
||||||
local score_t = lb_score_t
|
local score_t = lb_score_t
|
||||||
local mapnumFromExtended = lb_mapnum_from_extended
|
local mapnumFromExtended = lb_mapnum_from_extended
|
||||||
|
local fireEvent = lb_fire_event
|
||||||
|
|
||||||
-- browser.lua
|
-- browser.lua
|
||||||
local InitBrowser = InitBrowser
|
local InitBrowser = InitBrowser
|
||||||
@ -107,6 +108,9 @@ local scroll_to
|
|||||||
|
|
||||||
local allowJoin
|
local allowJoin
|
||||||
|
|
||||||
|
-- Events
|
||||||
|
local EVENT_FINISH = "Finish"
|
||||||
|
|
||||||
|
|
||||||
-- cvars
|
-- cvars
|
||||||
local cv_teamchange
|
local cv_teamchange
|
||||||
@ -1157,6 +1161,9 @@ local function saveTime(player)
|
|||||||
if checkFlags(player) != Flags then
|
if checkFlags(player) != Flags then
|
||||||
print("Game mode change detected! Time has been disqualified.")
|
print("Game mode change detected! Time has been disqualified.")
|
||||||
S_StartSound(nil, 110)
|
S_StartSound(nil, 110)
|
||||||
|
fireEvent(EVENT_FINISH, {
|
||||||
|
disqualified = true,
|
||||||
|
})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1185,6 +1192,7 @@ local function saveTime(player)
|
|||||||
FlashRate = 3
|
FlashRate = 3
|
||||||
FlashVFlags = RedFlash
|
FlashVFlags = RedFlash
|
||||||
scroll_to(player)
|
scroll_to(player)
|
||||||
|
fireEvent(EVENT_FINISH, {score = newscore})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1206,6 +1214,12 @@ local function saveTime(player)
|
|||||||
-- Set the updated ScoreTable
|
-- Set the updated ScoreTable
|
||||||
ScoreTable = MapRecords[Flags]
|
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 the gui to the player entry
|
||||||
scroll_to(player)
|
scroll_to(player)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user