• File Order Loader - Useful code snippet for giving files/directories priority!
    1 replies, posted
I recently needed to make this for a gamemode I'm creating. I haven't seen anyone make this, or post this, so I thought I would. What is it: This snippet is to load specific files and directories first, so if you have load dependency, then this is for you. Config Snippit (this should be placed in autorun): https://pastebin.com/hBAbc3Jz In this snippit: You'll see the function a function PL.Func.loadFiles(). The arguments passed is #1, a table of strings that end in .lua to be classified as lua files, otherwise, they will be classified as directories to load. The second argument is the string parent of the directory for all these tables to be run through with their directories and strings. PL.LoadOrder["initial"] = {}, this contains your initial files and directories to run through. This will run in the order you list it as. For example, look at 'PL.LoadOrder["initial"]["blocks"]'. This will first include the sv_file1.lua, then it will add all the files in the gmbase, and then in the factions directory, and then the entities, and then finally add the cl_file2.lua. You can also see 'PL.LoadOrder["initial"]["blocks"]["gmbase"]' is defined. When, 'PL.LoadOrder["initial"]["blocks"]' calls the gmbase directory, this will run all the files/directories listed in 'PL.LoadOrder["initial"]["blocks"]["gmbase"]' first, and then everything else in your gmbase directory. You should by now have an idea on how this works. Note: Your files must have a prefix of sh, sv, or cl, so that the code knows whether to add it to shared, server, or client respectively. Also note: If any folder has the same name of any folder in the addon/gamemode/whatever is being loaded, only the first folder loaded will load. Folders with the same name afterwards will not load. If you really wish, you can fix this. I didn't need to for myself. Also note: You can have table values in any of your configured tables, the script will just ignore them. Actual snippit for loading files here (this can be placed wherever, but most likely with your configured stuff): https://pastebin.com/krAJnkyx Let me know if you have any questions.
I should add, you don't need to write out every file. You only config the order of what loads first, then after the loader goes through with your order, it loads every other single files and directory that is in the filepath passed as the second argument
Sorry, you need to Log In to post a reply to this thread.