advanced lua scripting

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

Post Reply
User avatar
Anakin
Master of the Force
Master of the Force
Posts: 4817
Joined: Sat Sep 19, 2009 11:37 am
Projects :: RC Side Mod - Remastered - SWBF3 Legacy
Location: Mos Espa (germany)

advanced lua scripting

Post by Anakin »

Hey,

i'm looking forward to do some scripting, but i'm not 100% sure how to do so, or if this is even possible.
So what i need ist:
1) browsing directories and get folder names,
2) string manipulation,
3) check if a file exist,
4) load that file if it does exist.

specialy for 1) and 2) i'm not sure how to do so
Marth8880
Resistance Leader
Posts: 5042
Joined: Tue Feb 09, 2010 8:43 pm
Projects :: DI2 + Psychosis
Games I'm Playing :: Silent Hill 2
xbox live or psn: Marth8880
Location: Edinburgh, UK
Contact:

Re: advanced lua scripting

Post by Marth8880 »

Anakin wrote:1) browsing directories and get folder names,
Unfortunately Lua doesn't come with any file system libraries, and SWBF2's Lua implementation lacks the I/O library (among others).
Anakin wrote:2) string manipulation,
What specifically are you trying to do with strings? See here: https://www.lua.org/pil/20.html
Anakin wrote:3) check if a file exist,
4) load that file if it does exist.
See `ScriptCB_IsFileExist(filePath)`, which returns true if a file at the specified path exists, or nil if not. As for loading the file, you'd obviously want `ReadDataFile(lvlFilePath)` or `ScriptCB_DoFile(scriptFilePath)` depending on the file type.
User avatar
Anakin
Master of the Force
Master of the Force
Posts: 4817
Joined: Sat Sep 19, 2009 11:37 am
Projects :: RC Side Mod - Remastered - SWBF3 Legacy
Location: Mos Espa (germany)

Re: advanced lua scripting

Post by Anakin »

to avoid the user and GC script conflicts I thought of an user and GC script that search in all subfolders from the addon folder for a special file and load it.

Let's say this way:
addon\XXX\scripts\xxx_scripts.lvl (GC script)
Addon\xxx\scripts\xxx_ingame.lvl (userscript)

So I need to get a list of folder names (xxx) and manipulate a string to build the total path where I wanna search for the file and (if it exist) load it
Marth8880
Resistance Leader
Posts: 5042
Joined: Tue Feb 09, 2010 8:43 pm
Projects :: DI2 + Psychosis
Games I'm Playing :: Silent Hill 2
xbox live or psn: Marth8880
Location: Edinburgh, UK
Contact:

Re: advanced lua scripting

Post by Marth8880 »

Anakin wrote:So I need to get a list of folder names (xxx) and manipulate a string to build the total path where I wanna search for the file and (if it exist) load it
Unfortunately you can't.

However, I wrote a batch script for MEU that installs user scripts/GCs by looking through existing ones by name and installing it in the first available "slot". The script is here: https://www.dropbox.com/s/h6dup8qht2wxz ... s.zip?dl=0

To use it, you just pass an argument to the script with a value of either `custom_gc` or `user_script`. You'll also need to edit BIN_DIR, USERSCRIPTS_DIR, and TEMP_DIR to reflect your own project.
Post Reply