• Get an Lua Error in the Code
    4 replies, posted
Hey there, i am new in Coding for Gmod, the first think i tried to make is change something in an older code. The think i changed is, that the Server had to come back to the Default Map, i done it with some Vars, but now i got an error: [ERROR] lua/autorun/sh_mapchange.lua:34: 'then' expected near '='1. unknown - lua/autorun/sh_mapchange.lua:0 Here is the Code: [url]https://pastebin.com/ghg74AyK[/url] Thanks for helping me.
For those too lazy to click the link. [CODE]if SERVER then hook.Add("InitPostEntity", "Mapcycleinit", function() local maps = { "sb_battlegrounds_r2", "sb_new_worlds_2", "sb_omen_v2", "sb_gooniverse" } local standard = { "map" } local cycletime = 180 -- Cycle Time Delay local warningdelay = 60 -- Notification Delay local randommap = maps[math.random(1, #maps)] -- Random Map Selection SetGlobalInt ( "Cycletime", cycletime ) SetGlobalInt ( "Warningdelay", warningdelay ) timer.Simple( cycletime*60, function() for k, ply in pairs( player.GetAll() ) do ply:ChatPrint( "Map Will Change To ".. randommap .." in ".. warningdelay.. " seconds! Save your work!") end timer.Simple( warningdelay, function() if game.GetMap() = standard then RunConsoleCommand("changelevel",randommap) else RunConsoleCommand("changelevel",standard) end) end) end) end if CLIENT then surface.CreateFont("font", { font="Myriad Pro", size=34}) hook.Add("HUDPaint", "DrawCountDown", function() local cycletime = GetGlobalInt( "Cycletime" ) local warningdelay = GetGlobalInt( "Warningdelay" ) local seconds = cycletime*60 - CurTime() + warningdelay local hours = math.floor(seconds / 3600) local mins = math.floor((seconds - (hours*3600)) / 60) local secs = math.floor((seconds - (hours*3600) -(mins*60) )) local thetime = string.format("%02d:%02d:%02d", hours, mins, secs) if seconds >= 0 then draw.WordBox(4, ScrW()/2 - 150, 10, "Map Change In ".. thetime, "font", Color(0, 0, 0, 180), Color(255,255,255)) end end) end[/CODE]
"if game.GetMap() = standard then" -- You can't compare a string to a table like that, either use table.HasValue or change your table to something like, local table = { ["map"] = true } and do, if table[ game.GetMap() ] then end also read this: [url]http://lua-users.org/wiki/ExpressionsTutorial[/url] -- You're using '=' wrong.
Okay, thank you.
[url]https://fptje.github.io/glualint-web/[/url] use this for future reference and further help
Sorry, you need to Log In to post a reply to this thread.