Map command lua help.


So i have a server that i want to run a command (server side) on certain maps, but i do not know how to do so. I will give an example, lets say the server changed map to “mg_scary_course_v3” what i want it to do is if it loaded that map, i want the server to run this command: “dr_death_rate 0”. Any ideas on how to do this? like what code and where i put it etc?

thanks, -sam :slight_smile:

Something like this

function MapDetect()
  if game.GetMap == "mapname" then
hook.Add( "Initialize", "MapDetect", MapDetect )

thanks, ill try it now :slight_smile:

Put it in server side code BTW forgot to mention that :smiley:

Iv’e put it in lua/autorun/scarycoursemap.lua


[editline]28th February 2014[/editline]

Iv’e heard that RunConsoleCommand makes it run on Client side, ill try it with “say TEST”

[editline]28th February 2014[/editline]

It did not work, add me on skype we can do it quicker :slight_smile:


The say won’t work as it is before the chat even initializes.

Just try it with a convar like sv_cheats and see if the convar has changed after a map change


Dr_highlight_admins not sv_cheats

I cant do that, my server is going to public, i know it dont work anyways because the command i wanted did not work.

Is there no other way to get this to work? :stuck_out_tongue:

The say command won’t work and I gave it as an example, use a convar for testing…

i didn’t use say after that, i used the command i wanted like i said lol, ill try it with sv_cheats 1 on anyways :stuck_out_tongue:

[editline]28th February 2014[/editline]

It didn’t work, :confused:

It should be in lua/autorun/server. Try this.

[lua]game.ConsoleCommand("dr_deathrate 0

Tried that, did not work :confused:

I do all things related to map manipulation in InitPostEntity - after the map has spawned it’s own entities.

Are you sure that you’re using game.ConsoleCommand correctly in a SERVER-side file? Show us your code, and inclusion methods please.