Can I execute LUA scripts in Gmod through map events?
9 replies, posted
For example, can I have a button that, when you press e on it executes a LUA script?
It's better to have the gamemode check if the entity itself is fired, and then run script based upon that.
You can use lua_run which can execute single lines of lua. With that, you can run console commands on the server to run a lua script. lua_run can be found in the garrysmd.fdg
Example on one of my maps, I have a dynamic prototype daynight cycle that emulates true darkness, but it requires a lua script to work. So I have buttons that run a line of lua which execute a console command on the server which executes a function in the script itself.
This is the line I put into lua_run's 'code' key.
[code]RunConsoleCommand('dnc_settime', '0')[/code]
This is the same as me opening the console as a server owner or in singleplayer and typing [B]dnc_settime 0[/B]
[QUOTE=Statua;46435565]You can use lua_run which can execute single lines of lua. With that, you can run console commands on the server to run a lua script. lua_run can be found in the garrysmd.fdg
Example on one of my maps, I have a dynamic prototype daynight cycle that emulates true darkness, but it requires a lua script to work. So I have buttons that run a line of lua which execute a console command on the server which executes a function in the script itself.
This is the line I put into lua_run's 'code' key.
[code]RunConsoleCommand('dnc_settime', '0')[/code]
This is the same as me opening the console as a server owner or in singleplayer and typing [B]dnc_settime 0[/B][/QUOTE]
[url]https://developer.valvesoftware.com/wiki/Point_servercommand[/url]
?
[QUOTE=PortalGod;46436441][url]https://developer.valvesoftware.com/wiki/Point_servercommand[/url]
?[/QUOTE]
Garry disabled it because lol
Yep. You cant use those ents in Garry's Mod. Probably some preventative measure so mappers cant put a secret button that gives them rights or something. A good idea but lua con commands work just fine lmfao.
So could you pakrat a lua script into your map and have the lua_run execute that script?
[QUOTE=Kemerd;46423113]It's better to have the gamemode check if the entity itself is fired, and then run script based upon that.[/QUOTE]
How would you go about that exactly?
[QUOTE=BlackMadd;46443359]How would you go about that exactly?[/QUOTE]
[code]
for k, v in pairs(ents.GetAll()) do
if v:GetClass() == "env_specialthingy" then
YourFunction(v)
end
end
[/code]
[QUOTE=Exho;46446255][code]
for k, v in pairs(ents.GetAll()) do
if v:GetClass() == "env_specialthingy" then
YourFunction(v)
end
end
[/code][/QUOTE]
Either that or GetName instead of GetClass.
If you're looking to fire a lua script from a trigger check out this:
[URL="http://facepunch.com/showthread.php?t=1436171"]http://facepunch.com/showthread.php?t=1436171[/URL]
Sorry, you need to Log In to post a reply to this thread.