HideAndSeek/lua/gamelogic.lua

84 lines
1.6 KiB
Lua
Raw Normal View History

2024-06-01 22:02:10 +00:00
local function countPlayers()
local count = 0
for p in players.iterate
if p.spectator
continue
end
count = $ + 1
end
return count
end
local function resetState()
return {
active = false,
state = HNSDEFS.GameState.Loading,
seekstart = 0,
}
end
rawset(_G, "HNS", resetState())
addHook("MapChange", function(mapnum)
if not (gametype == GT_HIDENSEEK) return end
-- Reset vars
HNS = resetState()
end)
local loadTime = 10 * TICRATE
addHook("MapLoad", function(mapnum)
if not (gametype == GT_HIDENSEEK) return end
-- Welcome to the setup zone, enjoy your brief stay
local player_count = countPlayers()
HNS.active = true --player_count > 1
HNS.seekstart = loadTime + TICRATE * hns_hidingtime.value
if not HNS.active
-- I guess you get to look around??
return
end
local initial_seeker = P_RandomRange(1, player_count) -- Be like P_RandomRange: inclusive!
-- Init state for each player
local index = 1
for p in players.iterate
p.hns = {
seeker = index == initial_seeker
}
index = $ + 1
-- If hider, set invisible
if not p.hns.seeker
p.hyudorotimer = HNS.seekstart
end
end
HNS.state = HNSDEFS.GameState.LevelStart
end)
addHook("ThinkFrame", function()
if HNS.state == HNSDEFS.GameState.LevelStart
if leveltime > loadTime
HNS.state = HNSDEFS.GameState.Hiding
HNS.seekstart = leveltime + (hns_hidingtime.value * TICRATE)
end
elseif HNS.state == HNSDEFS.GameState.Hiding
if leveltime >= HNS.seekstart
HNS.state = HNSDEFS.GameState.Seeking
-- Play seek start sound!
--TODO
end
end
end)
addHook("NetVars", function(net)
-- Sync your shit here
HNS = net($)
end)