To modify the Zombie Survival gamemode so that the round restarts instantly upon humans losing and never changes the map, you need to make adjustments to two key functionalities:
Restarting the round instantly upon humans losing.
Preventing the map from changing.
Here's how you can accomplish both:
1. Restart the round instantly upon humans losing
The function responsible for ending the round is GM:EndRound. This function is called when the round ends and determines what happens next. To restart the round immediately upon humans losing, you can override the behavior in this function by resetting the round state.
Steps:
Open the file: ./repos/zombiesurvival/gamemodes/zombiesurvival/gamemode/init.lua.
Locate the GM:EndRound function or add your own modification for it. If it doesn't exist explicitly in the code, it will be called via gamemode.Call("EndRound", ...).
Modify the function to restart the round immediately instead of proceeding to a map change or other actions.
lua
function GM:EndRound(winningteam)
if winningteam == TEAM_HUMAN then
-- If humans win, keep existing behavior (if any).
gamemode.Call("PostEndRound", winningteam)
else
-- If humans lose, restart the round instantly.
timer.Simple(0, function() -- Delay by 0 seconds to restart immediately.
self:RestartRound()
end)
end
end
function GM:RestartRound()
-- Reset all round-related variables and states here.
game.CleanUpMap() -- Resets the map to its original state.
self:SetWave(0) -- Reset wave to 0.
self:SetWaveActive(false) -- Ensure wave state resets.
self:Initialize() -- Reinitialize the gamemode.
end
The GM:RestartRound function ensures that the gamemode resets the appropriate variables and prepares the next round.
2. Prevent the map from changing
By default, the gamemode may include functionality to change the map after a round ends (e.g., using GM:LoadNextMap). To prevent this, you can override the GM:LoadNextMap function to ensure the map never changes.
Steps:
In the same file (init.lua), locate the GM:LoadNextMap function or add your own override.
Modify it to stop the map from changing by returning true (which prevents the default behavior).
lua
function GM:LoadNextMap()
-- Prevent map changing by overriding this function.
return true -- Return true to block map change.
end
With this modification, the gamemode will never attempt to load the next map.
Final Code Block
Here’s the complete code snippet to add to init.lua:
lua
function GM:EndRound(winningteam)
if winningteam == TEAM_HUMAN then
-- If humans win, keep existing behavior (if any).
gamemode.Call("PostEndRound", winningteam)
else
-- If humans lose, restart the round instantly.
timer.Simple(0, function() -- Delay by 0 seconds to restart immediately.
self:RestartRound()
end)
end
end
function GM:RestartRound()
-- Reset all round-related variables and states here.
game.CleanUpMap() -- Resets the map to its original state.
self:SetWave(0) -- Reset wave to 0.
self:SetWaveActive(false) -- Ensure wave state resets.
self:Initialize() -- Reinitialize the gamemode.
end
function GM:LoadNextMap()
-- Prevent map changing by overriding this function.
return true -- Return true to block map change.
end
Optional Enhancements
Add a notification: If you want to notify players that the round is restarting, you can use net.Broadcast or a similar function to display a message.