• Simple Change map code?
    7 replies, posted
I have this script that creates a timer and then once the timer reaches 0, restarts the server. I was wondering if I could replace this with a block of code that tells the server to change to a different map provided. Anyone know the code I would have to replace this restart block with? I assume I would need to change the "game.ConsoleCommand". // Restarts the server if the timer reaches SPECIFIC TIME timer.Create("OfficialCountDownTimer",1,0, function() if tonumber(file.Read("TDM/Timer/Timer.txt","DATA")) == 1 then umsg.Start("TDMGETIFTIMER") umsg.Short(tonumber(file.Read("TDM/Timer/Timer.txt","DATA"))) umsg.Short(tonumber(file.Read("TDM/Timer/TimerLimit.txt","DATA"))) umsg.End() if tonumber(file.Read("TDM/Timer/TimerLimit.txt","DATA") - math.Round(CurTime())) <= 0 then game.ConsoleCommand("changelevel "..game.GetMap( ).."\n") end else umsg.Start("TDMGETIFTIMER") umsg.Short(tonumber(file.Read("TDM/Timer/Timer.txt","DATA"))) umsg.Short(tonumber(file.Read("TDM/Timer/TimerLimit.txt","DATA"))) umsg.End() end
-snip- missed a part
any help?
Instead of using game.ConsoleCommand("changelevel "..game.GetMap( ).."\n") the " .. game.GetMap( ) .. " part should be changed to " .. selectedMap .. ", and selectedMap variable should be set to some map name.. You could do local selectedMap = args[ 1 ] || game.GetMap( ) --- If you use a concommand to start the timer, this would be one way so it'd either use the first argument or the current map.
This is the most worst timer I have ever seen, I suggest you re-write it.
[QUOTE=AnonTakesOver;45346915]This is the most worst timer I have ever seen, I suggest you re-write it.[/QUOTE] Your post adds nothing to this thread, you should ask yourself why you posted.
[QUOTE=Effektiv;45346931]Your post adds nothing to this thread, you should ask yourself why you posted.[/QUOTE] I suggested he should re-write it and not use that system. I know it isn't that helpful, but it still adds something to the thread, he should re-write it differently, this method is inefficient and just silly.
I agree. Fileio is expensive, you're doing 3 to 4 file reads every second.... You could improve it by storing the values in a variable and reduce it to 2, or rewrite it into something like this: Countdown example: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/vgui/sh_hud_countdown.lua.html[/url] The countdown is the standard way of doing it. It gives time elapsed, time remaining, percent, etc. You could do it uses 1 timer and just using timer.TimeLeft to accomplish the exact same goal, but this shows how it is typically done. When the timer reaches the end ( notices the timer was started on server and clients so that they execute at the same time ), the shared hook fires. Basic concept of a round-system: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/_systems/round_system/basic_concept_of_round_systems.lua.html[/url] Tracking players: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/tracking_players/player_connect_and_disconnect_with_list_example.lua.html[/url]
Sorry, you need to Log In to post a reply to this thread.