Creating a Mod for existing gamemode without copying?
7 replies, posted
I was wondering if it is possible to somehow make a modification to any gamemode that's already on the workshop, without extracting and copying all the code in it and then modify that? Some way to replace certain functions and inject new ones where they are needed, as well as add new .lua files to the mode? So that it can be uploaded to the Workshop but requires the original gamemode subscribed too before it does anything?
I have an awesome mod for a mode but I don't want to upload the entire thing to the Workshop as that would direct traffic away from the original because it doesn't require the original to run. And that would also be stealing code in some way. So are there any functions or anything that inject lines of code and/or modifies functions, or maybe just a way that requires a specific addon subscribed?
Create a new gamemode and use the old one as a base and override the functions you need to edit.
[QUOTE=_FR_Starfox64;46488457]Create a new gamemode and use the old one as a base and override the functions you need to edit.[/QUOTE]
So in this case just copy the structure of the original gamemode's directory, but only keeping files that are modified, and in those files only keep the functions that are modified and adding new lines?
So if I have my init.lua have a function, say DoSomething(), if I derive from a gamemode with this function but I put it in my init.lua, it will [B]replace[/B] the [I]entire[/I] function "DoSomething()"? And if I add anything that's not in the original init.lua, it would simply be [I]added[/I] to the original?
[QUOTE=Zet0r;46488824]So in this case just copy the structure of the original gamemode's directory, but only keeping files that are modified, and in those files only keep the functions that are modified and adding new lines?
So if I have my init.lua have a function, say DoSomething(), if I derive from a gamemode with this function but I put it in my init.lua, it will [B]replace[/B] the [I]entire[/I] function "DoSomething()"? And if I add anything that's not in the original init.lua, it would simply be [I]added[/I] to the original?[/QUOTE]
Yes, if you are only editing a part of a function make sure to add the whole base function to it.
It doesn't quite work. The console spams me with errors trying to use stuff that is indexed in the original file. In the beginning it wouldn't even let me get the weapons you should when spawning, but after I added DeriveGamemode("[gamemode]") to every modified file, it did but still spams me with the first errors. It also says "[Original gamemode] is creating script errors!" where some line tries to use a NULL entity :/
Does local files and functions not index across all files by the same name?
If the functions you are using are using localized variables from the base file it won't work, you have to find a way to get them.
You should only be calling DeriveGamemode once within the shared file of your new gamemode. Read here:
[url]https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index1143.html[/url]
It's about Fretta but it applies the same.
I have managed to get it fully functional, although with cl_init and shared not derived. When I had them derive the game would freeze every time I died, for no apparent reason. I even copied function by function from the original mode of the functions I hadn't modified, and the game still froze even when my modified file was literally a copy of my original mod (which was not derived but had everything; modified functions [I]and[/I] non-modified). It stopped freezing after I disabled the DeriveGamemode() line :/
Sorry, you need to Log In to post a reply to this thread.