Tanksy Posted January 29, 2017 Share Posted January 29, 2017 When modifying scripts, can you place a separate script that overwrites the existing script when the game loads or must you overwrite the original file? Is there a way to overwrite existing functions with your own? I would like a clear explanation of the scripting process, where to put custom scripts, and if you can make say, a custom script that adds a type of asteroid that can be generated, without modifying the original asteroid generation scripts. So far we have barely any documentation apart from the API documents that aren't complete, and the posts by the developer talking about how custom functions are ran and how scripts can be attached to entities. Is modding the original scripts to add in extra functions at all possible without overwriting original files to keep things working alongside other mods? Link to comment Share on other sites More sharing options...
ThunderDodge Posted January 29, 2017 Share Posted January 29, 2017 You can use the command in your custom script: require( "player/alienattack" ) if its in scripts/player: require( "player/alienattack" ) as far as i know, you have then access to all variables & function's in this file. Worked for me tho. Files getting "merged" Link to comment Share on other sites More sharing options...
Tanksy Posted January 29, 2017 Author Share Posted January 29, 2017 So, if the script file has a requirement of another script, the custom script will be loaded alongside the one it requires? Link to comment Share on other sites More sharing options...
ThunderDodge Posted January 29, 2017 Share Posted January 29, 2017 Yes Link to comment Share on other sites More sharing options...
Tanksy Posted January 30, 2017 Author Share Posted January 30, 2017 Interesting! Could this be used to overwrite existing functions or at least add to them, without overwriting the original files to make installing/uninstalling the mod easier? Link to comment Share on other sites More sharing options...
ThunderDodge Posted January 30, 2017 Share Posted January 30, 2017 Depends on the script If the new scripts runs after the one with the original code, yes. ( per execute ) Adding things beneath a function without deleting it: function actual_func( ply ) print( "hi" ) end local old_func = actual_func( ... ) -- basically you know the parameters, but we cant define them here. Let's call it placeholder. function myfunc() print("hey, how are you?" ) end function old_func( ply ) myfunc() end Output: Hi hey, how are you? Btw this is very experimental, and i dont recommend to use this. Why would you even overwrite a function? Mostly you use this to hook into function's, that are hardcoded like "addScript()" for a super noobish CheatProtection or logging. You can still call things like "addMetheor..." if you required that file. There are many things you just can't edit, without overhaul the default code. Hooking in a default function isn't always that good, if the function returns something important and you return just before that in your function, the old one is broken. That causes errors and leads to disfunctionallity. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now