Skip to content

Instantly share code, notes, and snippets.

@pohka
Last active April 27, 2020 13:23
Show Gist options
  • Save pohka/76e0db4962c16b97af6e373e16e6a2ce to your computer and use it in GitHub Desktop.
Save pohka/76e0db4962c16b97af6e373e16e6a2ce to your computer and use it in GitHub Desktop.
custom time for dota custom games
if CAddonTemplateGameMode == nil then
CAddonTemplateGameMode = class({})
end
--global time value
_G.time = 0
-- Create the game mode when we activate
function Activate()
GameRules.AddonTemplate = CAddonTemplateGameMode()
GameRules.AddonTemplate:InitGameMode()
end
function CAddonTemplateGameMode:InitGameMode()
GameRules:SetPreGameTime(0)
GameRules:GetGameModeEntity():SetThink( "OnThink", self, "GlobalThink", 1 )
end
-- Evaluate the state of the game
function CAddonTemplateGameMode:OnThink()
--only update time in state GAME_IN_PROGRESS and when game is not paused
if GameRules:State_Get() == DOTA_GAMERULES_STATE_GAME_IN_PROGRESS then
if GameRules:IsGamePaused() == false then
_G.time = _G.time + 1
print("time:" .. time)
end
elseif GameRules:State_Get() >= DOTA_GAMERULES_STATE_POST_GAME then
return nil
end
return 1 -- call this function once per second
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment