SleepKiller's Mungeless Light Changer

Started by SleepKiller, May 28, 2014, 06:24:26 PM

Previous topic - Next topic
Are you sick and tired of people not being able to customize the lighting on your map after you've shipped it? Do you wish you didn't have to remunge just to change the lighting on your map? Do you wish you could just edit a single file and have the lighting be changed when you reload the map? Well now you can! Introducing the- Wait that joke is old.

So for those of you who don't know (most of you) I not too long ago made some nifty scripts for Snake's SWBF Museum, one of which let's you ship your map with the ability to change your world's lighting based off an lua script instead of having to remunge the world or munge your own lighting config file. (The script basically does the latter but dynamically and on demand.)

Installing and Integrating It
It is relatively simple to install and integrate first step you're going to do is download the zip file attached to this post. Once you have that extract the contents anywhere and leave a windows explorer window open at those extracted files.

Step 1.
Open your map's mission.req and add this section to it before the last } it's very important that you put it before the last curly bracket but after the second to last curly bracket. Got it?

REQN
{
"script"
"LightFunctions"
}


Step 2.
From the zip folder you downloaded copy LightFunctions.lua and put it into the same folder as your map's scripts. If you don't know what I'm talking about you need to learn to mod a bit more before trying to implement this ;)

Step 3.
Open your map lua scripts and find the line that your world.lvl is loaded on. It looks something like this ReadDataFile("dc:swbf4ever\\swbf4ever.lvl"), only with your map name instead of swbf4ever. Now once you've found that line put these three lines anywhere after it.

Code (lua) Select
dofile("Addon/YOURMAPIDHERE/lighting.lua"); --This loads the lighting config stored as an lua script.
SetLighting("Addon/YOURMAPIDHERE/Data/_LVL_PC/lighting.config"); --This calls the magical function that does everything.
ReadDataFile("dc:lighting.config"); --This loads up the file made by the magical function.


Replace YOURMAPIDHERE with well, your map ID.

Step 4.
Take the file lighting.lua from the zip and place it in your Addon folder. (The one with addme.script in.)

Step 5.
Munge and you should now be done. Enjoy your new found ability to edit lighting in the map without remunging. Pro Tip: Restarting the map also reloads it.


If you encounter any problems while doing this post your code and detail the steps you took. So I can know where you went wrong or where I went wrong in explaining something.


Wow that's seriously cool.  A little off topic, but how feasible do you think an ingame lighting change is? (I guess some functionality may be unchangeable mid-game as you are using it on the map load up, so there's that)

If you were to add another Escape GUI menu, and added a few sliders, would it be possible to connect the GUI with an offbeat of your script to change it with internal memory values (instead of taking them from a file)?

Again, nice work and thanks for sharing!

Quote from: -RepublicCommando- on May 28, 2014, 07:44:24 PM
Wow that's seriously cool.  A little off topic, but how feasible do you think an ingame lighting change is? (I guess some functionality may be unchangeable mid-game as you are using it on the map load up, so there's that)

If you were to add another Escape GUI menu, and added a few sliders, would it be possible to connect the GUI with an offbeat of your script to change it with internal memory values (instead of taking them from a file)?

Again, nice work and thanks for sharing!
This script can be executed midgame and you could integrate it with SWBF's GUI. If anyone decides to undertake this endeavour all you need to know about the script is that it expects these variables to be defined before it's executed. It doesn't care where or how they're defined so long as they have valid values in them.

Code (lua) Select
AmbientLight = {110,110,120};
VehicleAmbientLight = {105,105,105};
UnitAmbientLightTop = {170,160,180};
UnitAmbientLightBottom = {110,90,40};

SunAngle = {140,-10};
SunDegree = {90};
SunColour = {120, 120, 120};


Just define those values to what you want then call SetLighting and it'll make the .config file you can load up. If you're loading it up ingame you may need to use ReadDataFileIngame instead of ReadDataFile, but I don't actually know if there is any difference. (Someone should do some testing on that at some point.)

Can this possibly work in BFII? Quite ingenius SK, very awesome.
Battfront Stuff if your interested.
http://www.youtube.com/user/411Remnant

Quote from: 411Remnant on May 28, 2014, 10:53:46 PM
Can this possibly work in BFII? Quite ingenius SK, very awesome.
I don't think so. SWBFII's lighting system is a fair bit more powerful. I think it stores it's information in objects as opposed to static world variables. While you could create a file on demand like this does for SWBFII's lighting system I think the light objects would just be added to the world as opposed to overwriting the previous information.

SWBFII does have a much more powerful scripting API than SWBF1 has. If you can disable/destroy the light objects before loading new ones it could work. Of course I am just guessing here, for all I know SWBFII does have static variables for ambient lighting. In which case you could get what you want quite easily. You're better off asking someone who knows the SWBFII engine and how it handles lighting than me however.