How can I make a day and night cycle?

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

SkinnyODST
Lieutenant Colonel
Lieutenant Colonel
Posts: 545
Joined: Mon Jul 04, 2016 10:56 pm
Location: My other account
Contact:

How can I make a day and night cycle?

Post by SkinnyODST »

I`ve seen this done on other maps like Katholis Sea Haven where each time you load up the map, it cycles through rainy weather, day time, night time etc. How do I do this?
Thanks
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: How can I make a day and night cycle?

Post by Marth8880 »

SkinnyODST
Lieutenant Colonel
Lieutenant Colonel
Posts: 545
Joined: Mon Jul 04, 2016 10:56 pm
Location: My other account
Contact:

Re: How can I make a day and night cycle?

Post by SkinnyODST »

Wow, this tut is so hard to understand for me.
Hidden/Spoiler:
[quote]Then put this function between load and init.[/quote]
Where is load and init?
Hidden/Spoiler:
[quote] Look at any space map. There's an extra "sky" folder in the
world_whatevermodidis folder. Probably best to copy that to your map.[/quote]
What does he mean "any space map"? I`ve looked in the space template folder in the modtools folder and I have no idea what hes talking about. I can find a "sky" folder, but I don`t know where this "extra" one is
User avatar
AceMastermind
Gametoast Staff
Gametoast Staff
Posts: 3285
Joined: Mon Aug 21, 2006 6:23 am
Contact:

Re: How can I make a day and night cycle?

Post by AceMastermind »

SkinnyODST wrote:Wow, this tut is so hard to understand for me.
Hidden/Spoiler:
[quote]Then put this function between load and init.

Where is load and init?[/quote]
This is my interpretation of that:

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
The weather function is inserted between the other 2 functions here, not inside either one.
Whether or not that is correct though I don't know, I never needed to use this.


and I assume when he says this:
Put this right under function ScriptPostLoad()

Code: Select all

WeatherMode = math.random(1,3)
weather()
that he means to put it inside the ScriptPostLoad() function on the line after "function ScriptPostLoad()" like this:

Code: Select all

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


SkinnyODST wrote:
Look at any space map. There's an extra "sky" folder in the
world_whatevermodidis folder. Probably best to copy that to your map.
What does he mean "any space map"? I`ve looked in the space template folder in the modtools folder and I have no idea what hes talking about. I can find a "sky" folder, but I don`t know where this "extra" one is
I would just forget the word "extra" is there, he likely just means the "sky" folder here:
data_SPC\Worlds\SPC\sky
It might be best here to create a space map for reference.


We should probably modify the tutorial to clarify this stuff, I can see how it may be confusing.
SkinnyODST
Lieutenant Colonel
Lieutenant Colonel
Posts: 545
Joined: Mon Jul 04, 2016 10:56 pm
Location: My other account
Contact:

Re: How can I make a day and night cycle?

Post by SkinnyODST »

Thanks. And I was going to write on the topic how hard it is to understand but the last comment on it was from 2009...
Delta327
Master Sergeant
Master Sergeant
Posts: 160
Joined: Thu Jan 21, 2016 8:55 pm
Projects :: Shattered Galaxy
Games I'm Playing :: Swbf2
xbox live or psn: No gamertag set
Location: In the Mid Rim of the galaxy

Re: How can I make a day and night cycle?

Post by Delta327 »

Well i looked at the tutorial its kinda hard to undersrand to and can i look at a example on a lua file?
ARCTroopaNate
Jedi
Jedi
Posts: 1161
Joined: Mon Mar 21, 2011 8:12 pm
Projects :: Star Wars Battlefront - Tides of War
Games I'm Playing :: SWBF2 RC EAW
xbox live or psn: I have ps4
Location: STALKER!
Contact:

Re: How can I make a day and night cycle?

Post by ARCTroopaNate »

Hidden/Spoiler:
[code]function ScriptPostLoad()
WeatherMode = math.random(1,3)
weather()

--This defines the CPs. These need to happen first
cp1 = CommandPost:New{name = "cp1"}
cp2 = CommandPost:New{name = "cp2"}
cp3 = CommandPost:New{name = "cp3"}

cp6 = CommandPost:New{name = "cp6"}
cp7 = CommandPost:New{name = "cp7"}
cp8 = CommandPost:New{name = "cp8"}

--This sets up the actual objective. This needs to happen after cp's are defined
conquest = ObjectiveConquest:New{teamATT = ATT, teamDEF = DEF, textATT = "game.modes.con", textDEF = "game.modes.con2", multiplayerRules = true}

--This adds the CPs to the objective. This needs to happen after the objective is set up
conquest:AddCommandPost(cp1)
conquest:AddCommandPost(cp2)
conquest:AddCommandPost(cp3)

conquest:AddCommandPost(cp6)
conquest:AddCommandPost(cp7)
conquest:AddCommandPost(cp8)

herosupport:AddSpawnCP("CP1","CP1_spawnpath")
herosupport:AddSpawnCP("CP2","CP2_spawnpath")
herosupport:AddSpawnCP("CP3","CP3_spawnpath")
herosupport:AddSpawnCP("CP6","CP6_spawnpath")
herosupport:AddSpawnCP("CP7","CP7_spawnpath")
herosupport:AddSpawnCP("CP8","CP8_spawnpath")
herosupport:Start()

KillObject("camry")
KillObject("explorer")
KillObject("camry1")
KillObject("explorer1")
KillObject("camry2")
KillObject("explorer2")
KillObject("camry3")
KillObject("explorer3")
KillObject("camry4")
KillObject("explorer4")

SetClassProperty("rep_hero_anakin", "SoldierMusic", "afv_amb_hero_01")
SetClassProperty("ghez_hokan", "SoldierMusic", "afv_amb_hero_02")

conquest:Start()
AddAIGoal(1, "conquest", 1000)
AddAIGoal(2, "conquest", 1000)
AddAIGoal(3, "conquest", 1000)
EnableSPHeroRules()
end

function weather()
if WeatherMode == 1 then
ReadDataFile("dc:AFV\\sky.lvl", "cloud")
elseif WeatherMode == 2 then
ReadDataFile("dc:AFV\\sky.lvl", "clear")
elseif WeatherMode == 3 then
ReadDataFile("dc:AFV\\sky.lvl", "night")
end
end[/code]
User avatar
GAB
1st Lieutenant
1st Lieutenant
Posts: 431
Joined: Sun Jul 03, 2011 8:56 pm
Location: Somewhere around the world
Contact:

Re: How can I make a day and night cycle?

Post by GAB »

Indeed that tutorial is not as clear as it could, so here's a (hopefully) better version.

In this I'll be using ABC as the mod ID. This tutorial assumes that you already have your variants' .fx, .sky, .ter, and .lgt files or that you at least know what they are and how to create them. Strictly speaking, steps 1 and 2 of part 1 are not necessary but they'll help you to organize your files better.

Part 1 - Setting Up Your Folders and Files

1. Go to data_ABC/Worlds/ABC/world1, create one folder for each variant you intend to have in your map. These folders will contain your variant specific files.

2. Paste each variant's .fx, .sky, .lgt and .ter files into their corresponding folders. Generally, .fx and .sky files may also require some extra textures and models, so make sure these are moved to their appropriate folders as well. You may not want to use multiple terrains. If that's the case, don't worry about .ter files.

3. Now, go to data_ABC/Worlds/ABC, create a new folder there and name it "sky".

4. Inside it, create a new folder and name it "REQ".

5. Now, open this new folder and create one .req file for each variant you intend to have in your map. Then, give each .req a unique variant name.

6. Open up one of the .reqs you created and put the following code in it:
Hidden/Spoiler:
[code]
ucft
{
REQN
{
"config"
"name_of_variant's_sky_file"
}
REQN
{
"light"
"name_of_variant's_lgt_file"
}
REQN
{
"envfx"
"name_of_variant's_fx_file"
}
REQN
{
"terrain"
"name_of_variant's_ter_file"
}
}[/code]Replace each of the placeholders with the appropriate file names. Don't remove the quotation marks.
Repeat this step for each .req you created in step 5.

7. Go back to data_ABC/Worlds/ABC/sky, create a new .req file and name it "sky". Put the following code in it:
Hidden/Spoiler:
[code]ucft
{
REQN
{
"lvl"
"name_of_variant1_req_file"
"name_of_variant2_req_file"
"name_of_variant3_req_file"
"name_of_variant4_req_file"
}
}[/code]Replace each of the placeholders with the file names of the .reqs you created in step 5. Don't remove the quotation marks.
Part 2 - Setting Up Your Lua

1. Open your map's Lua and find this line: function ScriptInit()

2. Below that, add the following code:

Code: Select all

WeatherMode = math.random(1,x)
x = Number of variants you intend to have in your map.

3. Now, find this line: ReadDataFile("dc:ABC\\ABC.lvl", "ABC_conquest")

4. Below that, add the following code:
Hidden/Spoiler:
[code]if WeatherMode == 1 then
ReadDataFile("dc:ABC\\sky.lvl", "name_of_variant1_req_file")
elseif WeatherMode == 2 then
ReadDataFile("dc:ABC\\sky.lvl", "name_of_variant2_req_file")
elseif WeatherMode == 3 then
ReadDataFile("dc:ABC\\sky.lvl", "name_of_variant3_req_file")
elseif WeatherMode == 4 then
ReadDataFile("dc:ABC\\sky.lvl", "name_of_variant4_req_file")
end[/code]Replace the placeholders with the file names of the .reqs you created in step 5 of part 1. Don't remove the quotation marks. The number of conditions in the code above is equal to the number of variants you intend to have in your map, so modify this code according to your needs.
Part 3 - Getting Ready to Munge

1. Open your map's world file (.wld) with a text editor.
2. Find the line LightName("ABC.lgt"); and remove it. this is necessary for the game to be able to load your variants' lighting files.
3. Still in your map's world file, find the line SkyName("ABC.sky") and remove it as well so that the game can load your variants' sky files.
4. Now, open your map's .req (which should be named ABC.req), located in the world1 folder and find and remove this section:
Hidden/Spoiler:
[code]REQN
{
"envfx"
"ABC"
}[/code]This section of the file is not necessary because you'll be loading your world effects files (.fx) through your variant specific .reqs from steps 5 and 6 of part 1.
5. (Only if you're using multiple terrains) In your world1 folder, delete your map's terrain file (it should be named ABC.ter). This is necessary because if this terrain is munged, it will be loaded at all times insted of your variants' terrains. Alternatively, removing the TerrainName("ABC.ter") line from the world file has the same practical effects but it causes the minimap to not appear, for some reason.

And that's it. If I didn't miss anything you should be ready to munge.

Some Very Important Notes

SWBF2's mod tools weren't desinged for all of this, which means there are some things you need to be aware of:

First, when you open your map in ZeroEditor, it will load a sort of generic ambient lighting due to what we did in step 2 of part 3 of this tutorial. In order to remedy this, do the following:
1. Open the map's world file (.wld) with a text editor:
2. Look for the following line ScriptName("DummyScript.dll");
3. Above that, add LightName("ABC.lgt"); (Don't forget the semicolon at the end of the line)
4. Go to the folder which contains the files of the variant you want the lighting to be loaded in the editor.
5. Copy the .lgt file in that folder and paste it in the world1 folder.
6. Rename the file you have just pasted to ABC. If you are asked if you wish to overwrite any file, do it.
7. Open the world in ZE and the variant's lighting should be loaded in the editor.

This is only really needed if you want to edit a variant's lighting. If you are going to do anything else, don't worry about the lighting.

Second and most important: ZeroEditor can't open world files (.wld) which do not have a terrain assigned to them. This is really important if you are working with multiple terrains because, since you have to do step 5 of part 3 every time you munge, you have to essentially to the oposite whenever you want to open you map in ZE (i.e. copying one of your variant's terrains to the world1 folder and renaming it to ABC). That's why I whenever I'm not working on map aesthetics I generally skip step 5 of part 3.

That's it. I tried to make this tutorial as comprehensible as possible but like Sky_216 said in his original tut, this is for fairly experienced modders. In my opinion, this is as almost as complicated as Battlefront 2 mapping gets, so be patient and try to understand what you're doing.

I wrote this tutorial a little bit in a hurry and then the lights went out and I had to write part of it again, so if someone finds a mistake, please tell so that I can edit it.

EDIT:

Here's part 1 of this tutorial sumarized in a single diagram:
Hidden/Spoiler:
Image
Last edited by GAB on Mon Jun 01, 2020 4:55 pm, edited 11 times in total.
Delta327
Master Sergeant
Master Sergeant
Posts: 160
Joined: Thu Jan 21, 2016 8:55 pm
Projects :: Shattered Galaxy
Games I'm Playing :: Swbf2
xbox live or psn: No gamertag set
Location: In the Mid Rim of the galaxy

Re: How can I make a day and night cycle?

Post by Delta327 »

While where on the light and day cycle.
How do you add diffrent terrain files to the map and ingame?
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: How can I make a day and night cycle?

Post by Marth8880 »

@GAB: Would you mind expanding on how to implement multiple terrains? :o That part seems unclear. This is how I currently understand it based on what you're saying:

If the TER file referenced by TerrainName in the WLD file DOES NOT exist, and a differently-named TER file that DOES exist is referenced in a REQ file, then the map will use that differently-named TER file.

Is this correct?
User avatar
GAB
1st Lieutenant
1st Lieutenant
Posts: 431
Joined: Sun Jul 03, 2011 8:56 pm
Location: Somewhere around the world
Contact:

Re: How can I make a day and night cycle?

Post by GAB »

Delta327 wrote:While where on the light and day cycle.
How do you add diffrent terrain files to the map and ingame?
Marth8880 wrote: @GAB: Would you mind expanding on how to implement multiple terrains? That part seems nuclear
You can create multiple terrains by saving your map in Zero Editor and when the dialog box appears you select Terrain File (*.TER) in the file type just like this:
Hidden/Spoiler:
Image
This generates a file of the terrain you currently have in the editor in your map's world1 folder. You can then go back to the editor, change whatever you want (e.g. color the terrain in a way that matches the lighting of another variant) and repeat the process. In the end you will have two identical terrains that only differ by their painted colors. You can then use each of these terrains in specific variants of your day/night cycle just like the tutorial says.
Marth8880 wrote: This is how I currently understand it based on what you're saying:If the TER file referenced by TerrainName in the WLD file DOES NOT exist, and a differently-named TER file that DOES exist is referenced in a REQ file, then the map will use that differently-named TER file.Is this correct?
Yep.
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: How can I make a day and night cycle?

Post by Marth8880 »

Very good to know. HUGE thanks, GAB! :thumbs:
Delta327
Master Sergeant
Master Sergeant
Posts: 160
Joined: Thu Jan 21, 2016 8:55 pm
Projects :: Shattered Galaxy
Games I'm Playing :: Swbf2
xbox live or psn: No gamertag set
Location: In the Mid Rim of the galaxy

Re: How can I make a day and night cycle?

Post by Delta327 »

Im a little confused about how make it on ZE?

Just to carify ive saved the ter before but it dosent show up ingame. Do you just remove it from your .wld file?
User avatar
GAB
1st Lieutenant
1st Lieutenant
Posts: 431
Joined: Sun Jul 03, 2011 8:56 pm
Location: Somewhere around the world
Contact:

Re: How can I make a day and night cycle?

Post by GAB »

Delta327 wrote:Just to carify ive saved the ter before but it dosent show up ingame.
Do you have the Lua code from step 4 of part 2 correctly referencing the .req file from step 7 of part 1 and step 5 and 6 of the same part?
Does the .req file mentioned in step 7 of part 1 have a correct reference to your variant's .req file from steps 5 and 6 of part 1?
Does your variant's .req file from steps 5 and 6 of part 1 contain a correct reference to your terrain file?
Delta327 wrote:Do you just remove it from your .wld file?
As step 5 of part 3 says, this is one of your options, but it will cost you your minimap.
Delta327
Master Sergeant
Master Sergeant
Posts: 160
Joined: Thu Jan 21, 2016 8:55 pm
Projects :: Shattered Galaxy
Games I'm Playing :: Swbf2
xbox live or psn: No gamertag set
Location: In the Mid Rim of the galaxy

Re: How can I make a day and night cycle?

Post by Delta327 »

Its working but is putting the terrain ramdomly
User avatar
GAB
1st Lieutenant
1st Lieutenant
Posts: 431
Joined: Sun Jul 03, 2011 8:56 pm
Location: Somewhere around the world
Contact:

Re: How can I make a day and night cycle?

Post by GAB »

Delta327 wrote:Its working but is putting the terrain ramdomly
You mean that every match the game loads a different terrain? If so, then you succeeded.
User avatar
Oceans14
Command Sergeant Major
Command Sergeant Major
Posts: 296
Joined: Mon Apr 27, 2015 7:09 pm
Projects :: Athenova Campaign
Games I'm Playing :: SWBF2
Location: Planet 4546b

Re: How can I make a day and night cycle?

Post by Oceans14 »

Great tut GAB. Assuming I just wanted a particular sky/lighting/terrain for a particular game mode (i.e. idk day for conquest, night for campaign) I would just load the appropriate variant in scriptinit, yes? All that weathermode stuff is just in place to allow for randomness?
User avatar
GAB
1st Lieutenant
1st Lieutenant
Posts: 431
Joined: Sun Jul 03, 2011 8:56 pm
Location: Somewhere around the world
Contact:

Re: How can I make a day and night cycle?

Post by GAB »

Exactly.
SkinnyODST
Lieutenant Colonel
Lieutenant Colonel
Posts: 545
Joined: Mon Jul 04, 2016 10:56 pm
Location: My other account
Contact:

Re: How can I make a day and night cycle?

Post by SkinnyODST »

Well that is a very good tutorial. Thanks GAB! But yes it is quite advanced, and seeing as this is my first map I don`t want to go too overboard with it, so I think that what Oceans14 said is a very good idea for me. So to add in different weather for each era through LUA, I`m guessing that I do all the same stuff in your tut but skip the whole random weather part in the LUA? I`ve tried adding this, in one of my era`s LUAs but got errors for missing brackets.
Hidden/Spoiler:
[code] ReadDataFile("sound\\yav.lvl;yav1cw")
ReadDataFile("dc:CCC\\CCC.lvl", "CCC_conquest")
ReadDataFile("dc:CCC\\sky.lvl", "CCC_night")
ReadDataFile("SIDE\\\\des.lvl",
"rep_inf_ep2_pilot")
ReadDataFile("dc:SIDE\\rep.lvl",[/code]
I don`t know if this is normal but none of my LUAs have a ReadDataFile("dc:CCC\\CCC.lvl", "CCC_conquest") in them, I had to add that part in.
PS - the "rep_inf_ep2_pilot") thing is supposed to be there for this 3rd team I have.
User avatar
GAB
1st Lieutenant
1st Lieutenant
Posts: 431
Joined: Sun Jul 03, 2011 8:56 pm
Location: Somewhere around the world
Contact:

Re: How can I make a day and night cycle?

Post by GAB »

SkinnyODST wrote:Well that is a very good tutorial. Thanks GAB! But yes it is quite advanced, and seeing as this is my first map I don`t want to go too overboard with it, so I think that what Oceans14 said is a very good idea for me. So to add in different weather for each era through LUA, I`m guessing that I do all the same stuff in your tut but skip the whole random weather part in the LUA?
Yeah, I think that would work.
SkinnyODST wrote:I`ve tried adding this, in one of my era`s LUAs but got errors for missing brackets.
Hidden/Spoiler:
[code] ReadDataFile("sound\\yav.lvl;yav1cw")
ReadDataFile("dc:CCC\\CCC.lvl", "CCC_conquest")
ReadDataFile("dc:CCC\\sky.lvl", "CCC_night")
ReadDataFile("SIDE\\\\des.lvl",
"rep_inf_ep2_pilot")
ReadDataFile("dc:SIDE\\rep.lvl",[/code]
Post your munge log. Also, post your entire lua.
SkinnyODST wrote:I don`t know if this is normal but none of my LUAs have a ReadDataFile("dc:CCC\\CCC.lvl", "CCC_conquest") in them, I had to add that part in.
Are you sure? Because that is in no way normal. The Battlefront II Mission LUA Guide doc says why:
Hidden/Spoiler:
[quote="Battlefront II Mission LUA Guide"]This next line is a VERY important line. This reads in your level files, and the game mode files. Without these lines, the script wouldn’t know what level files to load, and you wouldn’t be able to run your level. The first part; “dc:ABC\\ABC.lvl” loads all the regular level files, and the second part, “ABC_conquest” specifies which game mode you’re going to be loading. So if this were a CTF script, you would see “ABC_ctf”, or “ABC_1flag”, or “ABC_eli” for hero assault.

ReadDataFile("dc:ABC\\ABC.lvl", "ABC_conquest")
[/quote]
This line usually is after the SetSpawnDelay(10.0, 0.25) line. If you've been able to run your map from the very beginning you shouldn't have had to add it. It has been sitting in your script somewhere.
Post Reply