• Map sv_gravity changer script
    29 replies, posted
Hi guys, I run a ttt server which by personal choice, I set the sv_gravity to 200 (Players find this fun), but there are the downsides unfortunately, some maps are exploitable and people tend to hide outside these maps. I have had a friend of mine code a little script to assist me with my issue, but his script doesnt seem to work The code: [CODE]local changemaps = { ttt_mw2_terminal_v1 = true, ttt_minecraft_b5 = true } hook.Add( "Initialize", "ChangeBackMaps", function() if changemaps[game.GetMap()] then RunConsoleCommand( "sv_gravity", "600" ) end end)[/CODE] I have placed this lua file in: lua/autorun/server/ and it didnt work. I also tried to put it in /lua/autorun/ also that didnt work :( (I saved the file as mapgrav.lua) Could it be a problem with the code or the placement of the file? [B]EDIT:[/B] To clarify, on those listed maps, I want the gravity to change to 600.
[code] local changemaps = {"ttt_mw2_terminal_v1", "ttt_minecraft_b5" } hook.Add( "Initialize", "ChangeBackMaps", function() if (table.HasValue(changemaps, game.GetMap())) then RunConsoleCommand( "sv_gravity", "600" ) end end) [/code] lua/autorun/server
Set the default gravity to 600 ( Basically don't set it to 200 ) and use the lua script to change it to 200 if the map is not in the table.
[del][B]GM:Initialize [/B]is only called on the server's initial start up if I remember correctly, meaning the hook gets called for the first map you're on, but not for every subsequent map change. You'd have to restart the SRCDS process entirely for it to get called again.[/del] Lolcats' modification is less optimized (ignoring the use of the Initialize hook problem above) because[B] table.HasValue [/B]loops through every table element until it finds a match (O(n) time), instead of performing a more efficient hash function to see if the index exists (O(1) time).
[QUOTE=Mista Tea;45279657][B]GM:Initialize [/B]is only called on the server's initial start up if I remember correctly, meaning if you change the map to one of the maps that you want the gravity set to 600, the hook will never get called. Lolcats' modification is less optimized (ignoring the use of the Initialize hook problem above) because[B] table.HasValue [/B]loops through every table element until it finds a match, instead of performing a more efficient hash function to see if the index exists.[/QUOTE] GM:Initialize is called on every map start, Lua state is destroyed between changelevels so all hooks are called again if map changes.
[QUOTE=Robotboy655;45279673]GM:Initialize is called on every map start, Lua state is destroyed between changelevels so all hooks are called again if map changes.[/QUOTE] My mistake, I thought I had remembered reading otherwise. Thank you for the clarification. My point still stands in regard to using table.HasValue. Other than being less optimized, it changes nothing in terms of OP's problem.
Regardless of the fact that it's being called when it starts, and it's only being called once, and the difference is literally negligible, The OP didn't make his problem clear. If he wants those maps to be at 600 gravity, then it's correct. If he wants those maps to be at 200 gravity, then all he needs to do is change it to 200.
[QUOTE=Lolcats;45279636][code] local changemaps = {"ttt_mw2_terminal_v1", "ttt_minecraft_b5" } hook.Add( "Initialize", "ChangeBackMaps", function() if (table.HasValue(changemaps, game.GetMap())) then RunConsoleCommand( "sv_gravity", "600" ) end end) [/code] lua/autorun/server[/QUOTE] Doesnt work :(
-snip-
[IMG]http://i.gyazo.com/b21d4d360086cc8c8605bc25972aee31.png[/IMG] ? My exact code: [code] local changemaps = {"gm_flatgrass", "ttt_minecraft_b5" } hook.Add( "Initialize", "ChangeBackMaps", function() if (table.HasValue(changemaps, game.GetMap())) then RunConsoleCommand( "sv_gravity", "200" ) print("Gravity changed to 200!") end end) [/code] Make sure you're actually saving it as a .lua file too...
[QUOTE=Lolcats;45279636][code] local changemaps = {"ttt_mw2_terminal_v1", "ttt_minecraft_b5" } hook.Add( "Initialize", "ChangeBackMaps", function() if (table.HasValue(changemaps, game.GetMap())) then RunConsoleCommand( "sv_gravity", "600" ) end end) [/code] lua/autorun/server[/QUOTE] table.HasValue is horribly expensive. Just change the maps to be equal to true in the table.
To clarify guys, my default gravity that I have set is 200 in my server.cfg I want the gravity on the map ttt_minecraft_b5, to be set to 600.
[QUOTE=KayKayy;45279860]To clarify guys, my default gravity that I have set is 200 in my server.cfg I want the gravity on the map ttt_minecraft_b5, to be set to 600.[/QUOTE] Your original code should work then; does it print that line in console when you change to that map? Otherwise, you could always use Player:SetGravity.
[QUOTE=Robotboy655;45279638]Set the default gravity to 600 ( Basically don't set it to 200 ) and use the lua script to change it to 200 if the map is not in the table.[/QUOTE] [editline]3rd July 2014[/editline] The problem might be is that server.cfg is called AFTER GM:Initialize
[QUOTE=code_gs;45279866]Your original code should work then; does it print that line in console when you change to that map? Otherwise, you could always use Player:SetGravity.[/QUOTE] It doesn't print :/
[QUOTE=KayKayy;45279882]It doesn't print :/[/QUOTE] [QUOTE=Robotboy655;45279638]Set the default gravity to 600 ( Basically don't set it to 200 ) and use the lua script to change it to 200 if the map is not in the table.[/QUOTE] [QUOTE=Robotboy655;45279868][editline]3rd July 2014[/editline] The problem might be is that server.cfg is called AFTER GM:Initialize[/QUOTE]
[QUOTE=KayKayy;45279882]It doesn't print :/[/QUOTE] That makes no sense. Try putting a timer in the initialize hook to make sure the server.cfg is called first.
[QUOTE=code_gs;45279890]That makes no sense. Try putting a timer in the initialize hook to make sure the server.cfg is called first.[/QUOTE] Pls why timers, I already posted how to solve it :suicide:
[QUOTE=Robotboy655;45279892]Pls why timers, I already posted how to solve it :suicide:[/QUOTE] He would have to change the hook he's using then. If the server.cfg is called after, then it would change the value back to the default one no matter what he sets it to in initialize.
[QUOTE=code_gs;45279903]He would have to change the hook he's using then. If the server.cfg is called after, then it would change the value back to the default one no matter what he sets it to in initialize.[/QUOTE] If he removes sv_gravity from the config, it will use the default value and it will not override the value set by the script. No need for other hooks, just replace the number and add an ! in the if and you are set.
[QUOTE=Robotboy655;45279929]If he removes sv_gravity from the config, it will use the default value and it will not override the value set by the script. No need for other hooks, just replace the number and add an ! in the if and you are set.[/QUOTE] Oh, I didn't interpret you saying that as to take it out of the server.cfg.
Okay, so I got rid of the sv_gravity 200 in the server.cfg and it's using the default gravity. I changed the code of the script so it modifies the gravity to change to 200, but still, when I restart the server, it doesnt print anything nor change the gravity
Show new code.
-snip- ^
[QUOTE=Robotboy655;45279957]Show new code.[/QUOTE] [CODE] local changemaps = {"ttt_mw2_terminal_v1", "ttt_minecraft_b5" } hook.Add( "Initialize", "ChangeBackMaps", function() if (table.HasValue(changemaps, game.GetMap())) then RunConsoleCommand( "sv_gravity", "200" ) print("Gravity changed to 200!") end end) [/CODE]
[code]local changemaps = { ttt_mw2_terminal_v1 = true, ttt_minecraft_b5 = true } hook.Add( "Initialize", "ChangeBackMaps", function() if changemaps[ game.GetMap() ]then RunConsoleCommand( "sv_gravity", "600" ) print( "Gravity set to 600!" ) else RunConsoleCommand( "sv_gravity", "200" ) print( "Gravity set to 200!" ) end end)[/code]
[QUOTE=code_gs;45279977][code]local changemaps = { ttt_mw2_terminal_v1 = true, ttt_minecraft_b5 = true } hook.Add( "Initialize", "ChangeBackMaps", function() if changemaps[ game.GetMap() ]then RunConsoleCommand( "sv_gravity", "600" ) print( "Gravity set to 600!" ) else RunConsoleCommand( "sv_gravity", "200" ) print( "Gravity set to 200!" ) end end)[/code][/QUOTE] I tried that code. Still not damn printing :/ [IMG]https://www.dropbox.com/s/bwneeqgsk5o8ahb/Screenshot%202014-07-03%2017.04.29.png[/IMG]
[QUOTE=KayKayy;45280011]I tried that code. Still not damn printing :/ [IMG]https://www.dropbox.com/s/bwneeqgsk5o8ahb/Screenshot%202014-07-03%2017.04.29.png[/IMG][/QUOTE] You gotta be blind because it is printing "Gravity set to 600!"
[t]http://puu.sh/9UMqk/7015dd9c48.jpg[/t] I even zoomed in for you so your eyes wouldn't have to strain too hard looking for it.
HAHHAAHA fuck me xD I am blind :') Thank you guys so much! <3
Sorry, you need to Log In to post a reply to this thread.