• Reload script?
    31 replies, posted
Hi, im trying to create a script that will reload/restart/whatever itself each 30 seconds. Im thinking I could make a timer, then restart when the time is 0. [CODE]Like, timer.Simple( 5, function() restart() end )[/CODE] [but restart isn't a function?]
[QUOTE=ZombieKingAAA;49676470]Hi, im trying to create a script that will reload/restart/whatever itself each 30 seconds. Im thinking I could make a timer, then restart when the time is 0. [CODE]Like, timer.Simple( 5, function() restart() end )[/CODE] [but restart isn't a function?][/QUOTE] Why would you need to re-load your script every 30 seconds?
[QUOTE=GGG KILLER;49676494]Why would you need to re-load your script every 30 seconds?[/QUOTE] so I could update information in a file.
[QUOTE=ZombieKingAAA;49676500]so I could update information in a file.[/QUOTE] 1. Wouldn't you need to reload the file instead of the script, or is the file the script? 2. Why would you update it while the server is live by editing lua files? 3. What are you trying to do?
I suppose you could try some kind of hacky workaround like doing lua_run for your serverside scripts and lua_run_cl for the clientside ones (after [URL="https://wiki.garrysmod.com/page/File/Read"]reading[/URL] them) Not sure if that would work though
[QUOTE=GGG KILLER;49676508]1. Wouldn't you need to reload the file instead of the script, or is the file the script? 2. Why would you update it while the server is live by editing lua files? 3. What are you trying to do?[/QUOTE] I want to reload the script, so it would edit a file with new content. what And I'm trying to get the names of players connected to the server, and put that in a file that Bash (I run my server on Debian) and can be used for any reason. Sense I can't seem to find a way to make the file update when a player joins, I'm going to make it simpler by just reloading the script every 30 seconds, which in turn will re-write the file in case a player has joined in the last 30 seconds.
[QUOTE=ZombieKingAAA;49676526]I'm trying to get the names of players connected to the server[/QUOTE] Use the [URL="https://wiki.garrysmod.com/page/GM/PlayerConnect"]PlayerConnect[/URL] hook? [CODE] hook.Add( 'PlayerConnect', 'WriteNamesToFile', function( name, ip ) file.Append( 'somefile.txt', name .. ' joined the server at ' .. util.DateStamp() ) end [/CODE]
[QUOTE=MPan1;49676535]Use the [URL="https://wiki.garrysmod.com/page/GM/PlayerConnect"]PlayerConnect[/URL] hook?[/QUOTE] Right now I just need the name of the function that will reload the script. I barely started the whole GLua thing.
There isn't a function that reloads scripts, as far as I know, but as I was saying before, you could try running your code with the lua_run and lua_run_cl commands, so then when it would be run, and probably replace your old code. But, if you used the PlayerConnect hook, you wouldn't need to do something as hacky as that.
Alright, ill try my way with the hook.
[QUOTE=ZombieKingAAA;49676552]Alright, ill try my way with the hook.[/QUOTE] You can use timer.Simple with the include function....
[QUOTE=GGG KILLER;49676555]You can use timer.Simple with the include function....[/QUOTE] Yes but I need a function that will reload the script, for an infinite loop.
what I suggested will do exactly what you want. If you use include, the file will be loaded again and the timer set again, and the same will happen after the timer runs. infinitely. [editline]5th February 2016[/editline] or you can make a function and have timer.Create call it each X seconds with the repetitions set to 0 (so it'll never stop)
[QUOTE=GGG KILLER;49676576]what I suggested will do exactly what you want. If you use include, the file will be loaded again and the timer set again, and the same will happen after the timer runs. infinitely. [editline]5th February 2016[/editline] or you can make a function and have timer.Create call it each X seconds with the repetitions set to 0 (so it'll never stop)[/QUOTE] I I just have no idea how to use timers. FML I have: timer.Create( "TimerTest" , 10 , 0 , print("what")) Then i get: [ERROR] lua/autorun/luatest.lua:9: bad argument #4 to 'Create' (function expected, got no value) 1. Create - [C]:-1 2. unknown - lua/autorun/luatest.lua:9
[QUOTE=ZombieKingAAA;49676606]I I just have no idea how to use timers. FML I have: timer.Create( "TimerTest" , 10 , 0 , print("what")) Then i get: [ERROR] lua/autorun/luatest.lua:9: bad argument #4 to 'Create' (function expected, got no value) 1. Create - [C]:-1 2. unknown - lua/autorun/luatest.lua:9[/QUOTE] That's because the 4th value has to be a function: [lua] timer.Create( "TimerTest" , 10 , 0 , function() print("what") end) [/lua] EDIT: All hail FP's code highlighter and its *[I]great[/I]* job.
[QUOTE=GGG KILLER;49676634]That's because the 4th value has to be a function: [lua] timer.Create( "TimerTest" , 10 , 0 , function() print("what") end) [/lua][/QUOTE] I tried that, nothing happened. [CODE] if SERVER then timer.Create( "TimerTest" , 10 , 0 , function() Msg("what") end) end [/CODE]
[QUOTE=ZombieKingAAA;49676640]I tried that, nothing happened. [CODE] if SERVER then timer.Create( "TimerTest" , 10 , 0 , function() Msg("what") end) end [/CODE][/QUOTE] It takes 10 seconds to run after the file is loaded. Where did you place the file?
[QUOTE=GGG KILLER;49676643]It takes 10 seconds to run after the file is loaded. Where did you place the file?[/QUOTE] Autorun. I waited more than 10 seconds, too. garrysmod\lua\autorun\Luatest.lua
[QUOTE=ZombieKingAAA;49676648]Autorun. I waited more than 10 seconds, too. garrysmod\lua\autorun\Luatest.lua[/QUOTE] Are you sure the file is loading? Try running "lua_openscript Luatest.lua" on the server console
[QUOTE=GGG KILLER;49676677]Are you sure the file is loading? Try running "lua_openscript Luatest.lua" on the server console[/QUOTE] Did that, it just said "Running script autorun\Luatest.lua..." I also moved it outside autorun, still no results.
Try removing the if to check if its the server and place the file in autorun/server
[QUOTE=GGG KILLER;49676761]Try removing the if to check if its the server and place the file in autorun/server[/QUOTE] So just a timer.Create( "TimerTest" , 10 , 0 , function() print("what") end) ? (and move it) [B]Edit[/B] Still nothing
hm.... try adding the timer inside a initialize hook like in the example in [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/timer/Create]timer.Create[/url]
you should rethink this as a synchronous process instead of timers add a player to the file when they join, remove them when they leave. store everything in a table for easy access and just write out the file when needed but if you'd detail your scenario a bit more specific, there could be a better solution am i assuming that you want to show online players on a site without sourcequeries?
Im going to try again tomorrow.
[QUOTE=Giraffen93;49676847]you should rethink this as a synchronous process instead of timers add a player to the file when they join, remove them when they leave. store everything in a table for easy access and just write out the file when needed but if you'd detail your scenario a bit more specific, there could be a better solution am i assuming that you want to show online players on a site without sourcequeries?[/QUOTE] A loading screen more specifically, and he is starting with Lua and has tried to use PlayerConnenct and PlayerDisconnect hooks but wasn't able to understand how to properly use them (an apparently the same with timers)
Why not just write the loading screen in PHP, and get the player list through RCon? Surely that's the easiest and more efficient way of doing things?
[QUOTE=James xX;49677223]Why not just write the loading screen in PHP, and get the player list through RCon? Surely that's the easiest and more efficient way of doing things?[/QUOTE] having rcon enabled is just screaming "destroy my server"
[QUOTE=James xX;49677223]Why not just write the loading screen in PHP, and get the player list through RCon? Surely that's the easiest and more efficient way of doing things?[/QUOTE] We've already recommended that, but nothing. [editline]5th February 2016[/editline] [QUOTE=Giraffen93;49677274]having rcon enabled is just screaming "destroy my server"[/QUOTE] You can use PHP's SourceQuery to retrieve players list without having to enable RCon, it uses the same protocol as valve games to retrieve information from the server
or just make a webserver running in srcds and print out chat and players live like i did :cool:
Sorry, you need to Log In to post a reply to this thread.