• GM:Initialize( )
    23 replies, posted
[lua] function City18() if game.GetMap() == "gm_construct" then game.ConsoleCommand( "changelevel rp_c18_v1" ) end end hook.Add( "Initialize", "City18", City18 ) [/lua] Think it would work?
[QUOTE=yahan;17245644][lua] function City18() if game.GetMap() == "gm_construct" then game.ConsoleCommand( "changelevel rp_c18_v1" ) end end hook.Add( "Initialize", "City18", City18 ) [/lua] Think it would work?[/QUOTE] Looks correct here. Why make a thread if you didn't test it first if it works or not?
Because it's not working. [lua] function GM:Initialize( ) -- Initialize the gamemode if game.GetMap() == "gm_construct" then game.ConsoleCommand( "changelevel rp_c18_v1" ) end end [/lua]
[QUOTE=yahan;17245757]Because it's not working. [lua] function GM:Initialize( ) -- Initialize the gamemode if game.GetMap() == "gm_construct" then game.ConsoleCommand( "changelevel rp_c18_v1" ) end end [/lua][/QUOTE] From the wiki: [quote]The command needs to be ended with a \n to be run, as shown in the examples. [/quote] So this should work: [lua] function GM:Initialize( ) -- Initialize the gamemode if game.GetMap() == "gm_construct" then game.ConsoleCommand( "changelevel rp_c18_v1\n" ) end end [/lua]
[QUOTE=Dlaor;17245853]From the wiki: So this should work: [lua] function GM:Initialize( ) -- Initialize the gamemode if game.GetMap() == "gm_construct" then game.ConsoleCommand( "changelevel rp_c18_v1\n" ) end end [/lua][/QUOTE] Doesn't work.
-snip-
Weird. You would think any of them would work. Can't figure out why.
What exactly is GetMap returning? Print the value it returns, as it could be returning it with the bsp extension.
Try InitPostEntity?
I'm trying to get the current map. If the map is construct then change map to rp_c18_v1.
Forgive me if I don't see a point to this, but why not just set the default map to be city18 in the command line?
[QUOTE=Teddi Orange;17247215]Forgive me if I don't see a point to this, but why not just set the default map to be city18 in the command line?[/QUOTE] This.
[QUOTE=Overv;17247780]This.[/QUOTE] This.
[QUOTE=MakeR;17247806]This.[/QUOTE] This.
[QUOTE=stylee32;17247931]This.[/QUOTE] That.
[QUOTE=victi;17245947][lua] function GM:Initialize( ) -- Initialize the gamemode local TheMap = "rp_c18_v1" if game.GetMap() == "gm_construct" then game.ConsoleCommand( "changelevel" .. TheMap .. "\n") end end [/lua] Try this[/QUOTE] This won't work because you forgot a space after changelevel. It's basically running the consolecommand, changelevelrp_c18v1.
The server provider is a dick and doesn't offer it.
game.ConsoleCommand blocks changelevel for some reason I think. Try hacking your way through it.
[lua] function City18() if game.GetMap() == "gm_construct" then RunConsoleCommand( "changelevel", "rp_c18_v1" ) end end hook.Add( "Initialize", "City18", City18 ) [/lua] ^ Should work ^
[QUOTE=gmt2001;17279236][lua] function City18() if game.GetMap() == "gm_construct" then RunConsoleCommand( "changelevel", "rp_c18_v1" ) end end hook.Add( "Initialize", "City18", City18 ) [/lua] ^ Should work ^[/QUOTE] No that will not work... this will: [lua] function City18() if game.GetMap() == "gm_construct" then RunConsoleCommand( "changelevel ", "rp_c18_v1" ) end end hook.Add( "Initialize", "City18", City18 ) [/lua] you need a space after changelevel otherwise its running changelevelrp_c18_v1 instead of changelevel rp_c18_v1
RunConsoleCommand automatically does this. The first parameter of it is the command to run, the rest of the parameters are the arguments. It automatically spaces them, formats them (Adds quotation as needed), and then runs it Thus the line [lua]RunConsoleCommand( "sendmessage", "hello", "good sir" )[/lua] Will run the command [code]sendmessage "hello" "good sir"[/code] in the console
[QUOTE=Helix Alioth;17279326]you need a space after changelevel otherwise its running changelevelrp_c18_v1 instead of changelevel rp_c18_v1[/QUOTE] No. It will work without the space. Edit: Darn it gmt2001 you beat me to it. :C
[lua] local changemap = "rp_c18_v1"; hook.Add("InitPostEntity", "ChangeTheMap", function() if(game.GetMap() != changemap) then game.ConsoleCommand("changelevel " .. changemap .. "\n") end end);[/lua] This should work.
hmm. You do have a point. The result of game.GetMap might not be available when Initialize is called
Sorry, you need to Log In to post a reply to this thread.