• Detecting a map change with Lua
    6 replies, posted
Is it possible to globally detect a map change caused by any addon / gamemode from another addon? I've thought of several ways to do this but for this it's necessary to change the calling addon itself. 1. Add another concommand that basically just executes some code before running the changelevel command itself (Since we can't override changelevel, I think [B](Is there a hacky method for this?)[/B]) 2. Just edit all operating gamemodes / rtv addons to run some code before the actual changelevel command Is this possible? Is there a native hook I'm overlooking? Is there a hacky way to achieve this? Thank you.
What for? You could use [url]http://wiki.garrysmod.com/page/GM/ShutDown[/url] and [url]http://wiki.garrysmod.com/page/GM/Initialize[/url] combo to "detect" if a map has been changed, but you will have to also rule out the possibility of a server restart or server shutdown. When a map is changed, the Lua state is destroyed and recreated from scratch.
[QUOTE=Robotboy655;48228920]What for? You could use [url]http://wiki.garrysmod.com/page/GM/ShutDown[/url] and [url]http://wiki.garrysmod.com/page/GM/Initialize[/url] combo to "detect" if a map has been changed, but you will have to also rule out the possibility of a server restart or server shutdown. When a map is changed, the Lua state is destroyed and recreated from scratch.[/QUOTE] To log player connections / disconnections. Not my idea but trying to figure out if it's possible. I was trying around with GM:Shutdown before and found out that it wasn't being called. I now see that I was a massive idiot and missed the capital D in ShutDown, so it wasn't getting called because the hook was invalid. Well, thank you anyway :)
[QUOTE=Gravious;48229712]To log player connections / disconnections. Not my idea but trying to figure out if it's possible. I was trying around with GM:Shutdown before and found out that it wasn't being called. I now see that I was a massive idiot and missed the capital D in ShutDown, so it wasn't getting called because the hook was invalid. Well, thank you anyway :)[/QUOTE] Log in what way? More specifics? There might be a workaround depending on what you want to do.
[QUOTE=Blasteh;48229807]Log in what way? More specifics? There might be a workaround depending on what you want to do.[/QUOTE] PlayerDisconnect doesn't get called on map change, to circumvent that we can now simply use GM:ShutDown to hook into a map change. I'd say this is solved for me, unless you have an easier solution to the problem.
[QUOTE=Gravious;48230107]PlayerDisconnect doesn't get called on map change, to circumvent that we can now simply use GM:ShutDown to hook into a map change. I'd say this is solved for me, unless you have an easier solution to the problem.[/QUOTE] I still have no idea what your needs are, so can't really suggest anything for you.
[QUOTE=Blasteh;48230333]I still have no idea what your needs are, so can't really suggest anything for you.[/QUOTE] As stated in the OP, detecting a map change, which we achieved now. Other than that, I don't really know much about the purpose of logging player activity like this, just needed to know if it was possible. I'll just mark this as solved since there's nothing more to contribute.
Sorry, you need to Log In to post a reply to this thread.