I'm having a problem with changelevel. Everytime that I execute RunConsoleCommand( "changelevel", ReadMapToChange()). Server said: "map "X" no found on maps/" (buy when I execute the command manually "changelevel x". It works)
ReadMapToChange is returning map name correctly. And when I was testing this command on windows. It was working. (Now I'm using on linux). Anyone knows a way to fix?
We need to see what exactly ReadMapToChange() is returning.
Linux is case sensitive, while Windows is not. Maybe the map name isn't in the same case as in the script? Make the case match between the script and the map name. It's a long shot, but the case sensitivity always comes to my mind when things like this happen.
[QUOTE=vexx21322;46964125]We need to see what exactly ReadMapToChange() is returning.[/QUOTE]
A random map: deathrun_iceworld_v3, deathrun_goldfever
[CODE]
function ReadMapToChange()
local MapsTable = {}
local f = file.Open("cfg/mapcycle.cfg", "r", "GAME")
if (f) then
local str = f:Read(f:Size())
local Map = ""
for i = 0, string.len(str) do
if (str[i + 1] != "\n") && i != string.len(str) then
Map = Map .. str[i + 1]
else
table.insert(MapsTable, Map)
Map = ""
end
end
else
local files = file.Find( "maps/*.bsp", "GAME" )
MapsTable = files
end
local MapToChange
repeat
MapToChange = table.Random(MapsTable)
until (MapToChange != game.GetMap())
return MapToChange
end
[/CODE]
I'd recommend using string.lower as per my code in your other thread. Also, make sure all map-names are all lower-case. Additionally, you'll need to strip the extension from the file if you use the file.Find method as per my code in your other thread.
Here: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/map/random_nextmap_or_random_map_from_mapcycle.txt.lua.html[/url]
[QUOTE=Acecool;46965975]I'd recommend using string.lower as per my code in your other thread. Also, make sure all map-names are all lower-case. Additionally, you'll need to strip the extension from the file if you use the file.Find method as per my code in your other thread.
Here: [url]https://dl.dropboxusercontent.com/u/26074909/tutoring/map/random_nextmap_or_random_map_from_mapcycle.txt.lua.html[/url][/QUOTE]
Map is returning correctly, but is not reconizing. For example: map is returning deathrun_iceworld_v3. If I put this on change level. It will work, but if I do this on RunConsoleCommand, will not work
Try adding ""s around the name to see if there is any white-space.
Also, how are you calling RunConsoleCommand? It requires 2 arguments. RunConsoleCommand( "changelevel", mapname );
You could try using this instead I guess...?
[url]http://wiki.garrysmod.com/page/game/ConsoleCommand[/url]
Why are there two functions to do the same thing...?
They're not identical, RunConsoleCommand uses multiple args, game.consolecommand uses a single string. Both are fine.
[QUOTE=Lost Alien;46966261]They're not identical, RunConsoleCommand uses multiple args, game.consolecommand uses a single string.[/QUOTE]
Yeah, I've noticed that; it just seems strange that at the bottom line, they do the exact same thing just with slightly different input formats. RunConsoleCommand is pretty much identical to concatenating all the args with commas in between, adding \n, and running it with game.ConsoleCommand.
Which admittedly is nice to have. :P
[QUOTE=Acecool;46966125]Try adding ""s around the name to see if there is any white-space.
Also, how are you calling RunConsoleCommand? It requires 2 arguments. RunConsoleCommand( "changelevel", mapname );[/QUOTE]
I'm using RunConsoleCommand( "changelevel", ReadMapToChange()). I think i'll add "" to see if there's any white-space
Don't try putting it between "" because you'll change the function to string.
Also, try
[CODE]local maptochangeto = ReadMapToChange()
RunConsoleCommand("changelevel", maptochangeto)[/CODE]
EDIT:
I mean, it'll make the ReadMapToChange() string
-snip-
~snip
[QUOTE=geferon;46967715]Don't try putting it between "" because you'll change the function to string.
Also, try
[CODE]local maptochangeto = ReadMapToChange()
RunConsoleCommand("changelevel", maptochangeto)[/CODE]
EDIT:
I mean, it'll make the ReadMapToChange() string[/QUOTE]
it will already be a string... You literally did the same thing as the code you tried to change.
... We have to try it at least. And I meant that if you put the function between "" the string will be "ReadMapToChange()", it won't call the function.
He meant to add the "" to the debug print to check if there's any whitespace around it. Like this
[lua]print('"'..ReadMapToChange()..'"')[/lua]
This will print like
" deathrun_iceworld_v3 "
if there's whitespace.
It's just a debugging thing to help try find the problem and is not a fix.
Bo98 is right; I should've been more clear, sorry.
When you output the data, if you see whitespace then you'll know you'll need to use string.Trim( new_map ); If you see .bsp then you'll need to use the string.sub to strip the extension. Etc...
Either way, it wouldn't be a bad idea to send a notification such as: "The map is now being changed to <mapname>" because it would only happen once per changelevel, its useful for debugging, players can see it and decide if they want to stay or go or prepare themselves if they need to download it.
Sorry, you need to Log In to post a reply to this thread.