Page 1 of 1

Random Sky/Fx/Lighting Tutorial (FAQ)

Posted: Wed May 06, 2009 9:44 am
by Sky_216
For fairly experienced modders only.


This will teach you how to add random sky, environment fx, and lighting to your map.These are very useful to make your map feel different between rounds.


First up, the lua part (this is just the code I use).


Put this inside the ScriptPostLoad() function on the line after "function ScriptPostLoad()" :

Code: Select all

WeatherMode = math.random(1,3)
weather()
like this:

Code: Select all

function ScriptPostLoad()
    WeatherMode = math.random(1,3)
    weather()
    --snip
end

Then put this function between ScriptPostLoad() and ScriptInit() :

Code: Select all

function weather()
    if WeatherMode == 1 then
        ReadDataFile("dc:AMI\\sky.lvl", "cloud")
    elseif WeatherMode == 2 then 
        ReadDataFile("dc:AMI\\sky.lvl", "clear")
    elseif WeatherMode == 3 then 
        ReadDataFile("dc:AMI\\sky.lvl", "rainy")
    end
end
like this:

Code: Select all

function ScriptPostLoad()
    --snip
end


function weather()
    if WeatherMode == 1 then
        ReadDataFile("dc:AMI\\sky.lvl", "cloud")
    elseif WeatherMode == 2 then 
        ReadDataFile("dc:AMI\\sky.lvl", "clear")
    elseif WeatherMode == 3 then 
        ReadDataFile("dc:AMI\\sky.lvl", "rainy")
    end
end


function ScriptInit()
    --snip
end
Obviously these are just examples.



The actual stuff:

Now, have a look at your map's sky file in the "world1" folder. Anything in here will be in all weather modes (I tend to just leave a couple of things like fog range).

Now you need to set up the "sky" lvl. If you look at any space map, there's a "sky" folder in the data_ABC\Worlds\ABC folder. You need a "sky" folder in your data_ABC\Worlds\ABC folder. Probably best to just copy that to your map.

The main req file (called spa_sky in the space maps) calls for the different reqs that load the skies (and fx and lighting if you want). It's name is the name of the lvl loaded through your lua (ie mine was simply "sky").

Inside the REQ folder are the REQ files for each different sky. To add fx/lighting loading to them as well (the "config" part is just the sky file), add this after the config part (which calls for the sky file in the "sky" folder)

Code: Select all

REQN
{
    "envfx"
    "whateverfxnameis"
}

REQN
{
    "light"
    "whateverworldlightnameis"
}
This calls your fx/lighting files from the "world1" folder. Make several fx files and you can load different ones thru this (ie "AMI", "AMI_Rain"). Copy and rename LGT files and you can load different ones through this (ie "AMI", "AMIgrey")

The sky files in the "sky" folder tell the map what "extra stuff" (ie different skydomes) to load for each sky setting. Don't load any skydomes in your main sky file (one in the "world1" folder).

To get the fx/lighting thing to work, do this:
Go to your worlds REQ file in world1. Find this part:

Code: Select all

REQN
{
    "envfx"
    "whateverworldfxnameis"
}
And delete it. Without doing this you can't load different fx files.

Also open up your maps "wld" file with a text editor like Notepad++, and delete the "LightName" line near the top. This will let you load different lighting files (if you're using them).



Anyway hope this helps a few more modders et up random skies etc.

Re: Random Sky/Fx/Lighting Tutorial

Posted: Wed May 06, 2009 9:46 am
by RogueKnight
Yes! I am soooo using this in my new "secret" project!

Thanks a lot Sky!

EDIT: You wouldn't happen to know how to add random heros/units too?

Re: Random Sky/Fx/Lighting Tutorial

Posted: Wed May 06, 2009 9:49 am
by Sky_216
DarthRogueKnight wrote:Yes! I am soooo using this in my new "secret" project!

Thanks a lot Sky!

EDIT: You wouldn't happen to know how to add random heros/units too?
Download and look at Mav's scripts for adding DT era - they include a seperate script to add random heroes/units.

Re: Random Sky/Fx/Lighting Tutorial

Posted: Wed May 06, 2009 9:50 am
by RogueKnight
Ah, ok, thanks a bunch Sky!

Re: Random Sky/Fx/Lighting Tutorial

Posted: Wed May 06, 2009 10:10 am
by YaNkFaN
great work sky I currently am working on trying to implement random ground textures or changed ones via loading custom sides but to no effect if I get it working I will post it here. And admins this should definitly be put in the everything you need to know thread.

Re: Random Sky/Fx/Lighting Tutorial

Posted: Wed May 06, 2009 10:25 am
by Sky_216
@YaNk: you could try to do the following:
Do what I said above with lighting - but for .ter rather than .lgt ie edit in ZE, save, rename the one you just saved, edit again, save again so you have multiple copies.

Then add this bit to lighting + fx + config:

REQN
{
"terrain"
"whateverterrainnameis"
}

And remove the TerrainName line from your .wld file.

No guarantees this'll work but it's worth a try if the sides thing is playing up.

Re: Random Sky/Fx/Lighting Tutorial

Posted: Wed May 06, 2009 10:36 am
by YaNkFaN
that may work but would require 2 .ter files so i guess copying them would do the trick but right now it's about actually loading the textures into the game via sides I have the custom side but the game isn't recognizing them or knowing what to do with them. I guess I'll try that when i get home see if it works.

Re: Random Sky/Fx/Lighting Tutorial

Posted: Wed May 06, 2009 11:32 am
by da_great_ghost
So basically this allows you to have random weather/time of day in a map? Purely awesome! But is it like custom skydomes where if played online each player has a different type of enviroment?

Re: Random Sky/Fx/Lighting Tutorial

Posted: Wed May 06, 2009 3:39 pm
by Superm9
Thanks so much Sky! I will attempt to implement that now... :bowdown:

Re: Random Sky/Fx/Lighting Tutorial

Posted: Wed May 06, 2009 4:05 pm
by Frisbeetarian
da_great_ghost wrote:But is it like custom skydomes where if played online each player has a different type of enviroment?
Yes

Re: Random Sky/Fx/Lighting Tutorial

Posted: Wed May 06, 2009 4:42 pm
by Fiodis
At last, random skys explained! Thanks for this, Sky.

Re: Random Sky/Fx/Lighting Tutorial

Posted: Wed May 06, 2009 6:25 pm
by YaNkFaN
.ter files can be edited by hexeditor this theoretically means you can make two that read different textures and load them randomly (assuming sky's way works going to try that out now) I don't reccomend making more than 2 random terrains due to the fact that
a) they are each about 28mb each
b) lighting can supplement for small changes needed in textures and lighting is about a 2kb file.

Re: Random Sky/Fx/Lighting Tutorial

Posted: Thu May 07, 2009 4:21 am
by sampip
Whoop! Thanks! I will definitely use this in my new map.
EDIT: NVM those errrors, It's working, and better than that, I fixed it myself (there's a first). That just proves that trying to add random sky for 45 minutes pays off :lol: Now for lighting and fx... :runaway:

Re: Random Sky/Fx/Lighting Tutorial (FAQ)

Posted: Wed May 27, 2009 5:06 pm
by obiboba3po
sky this is a great find and something original and fun to do in maps. thanks :)