Is it possible to divide my lua into 2 parts?

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

Ace_Azzameen_5
Jedi
Jedi
Posts: 1119
Joined: Sat Apr 23, 2005 8:52 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

Re: Is it possible to divide my lua into 2 parts?

Post by Ace_Azzameen_5 »

I'm not sure if he's going to do it for you.
I'm having a hard time following this thread, so, maybe I'll start from the beginning and ask WHY you must split your LUA into two parts?
Can't you just
some_random_number = math.random(1,4)
If some_random_number >= 3 then
ReadDataFile(lvl with a model in it)
elseif some_random_number <=2 then
ReadDataFile(lvl with other model in it)
else
print("")
print("Message Severity AA: 5")
print("I messed up with my < > logic, this should never happen and nothing got loaded")
print("")
end
Deviss
Master of the Force
Master of the Force
Posts: 3772
Joined: Tue Aug 12, 2008 7:59 pm
Projects :: Clone Wars Extended
Games I'm Playing :: BF2

Re: Is it possible to divide my lua into 2 parts?

Post by Deviss »

Ace_Azzameen_5 wrote:I'm not sure if he's going to do it for you.
I'm having a hard time following this thread, so, maybe I'll start from the beginning and ask WHY you must split your LUA into two parts?
Can't you just
some_random_number = math.random(1,4)
If some_random_number >= 3 then
ReadDataFile(lvl with a model in it)
elseif some_random_number <=2 then
ReadDataFile(lvl with other model in it)
else
print("")
print("Message Severity AA: 5")
print("I messed up with my < > logic, this should never happen and nothing got loaded")
print("")
end
zerted said me time ago: i'm just really slow at getting back to people.
so i hope he can do it for me :) , of course i could am wrong xD, and partition it in 2 parts because so i can use the second part for all lua files so when i change models names etc i only need modify 1 file :) that is the thing i am searching, no need modify 120 luas xD
Ace_Azzameen_5
Jedi
Jedi
Posts: 1119
Joined: Sat Apr 23, 2005 8:52 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

Re: Is it possible to divide my lua into 2 parts?

Post by Ace_Azzameen_5 »

You could just modify your one LUA? And if the same model name appears over and over there is the "replace" function of notepad...
I'm also not sure how you know how to make 120 .lua's but not 2.
Also, what does "when I change one model I have to modify 120 files" have to do with the in-game scripts?
Deviss
Master of the Force
Master of the Force
Posts: 3772
Joined: Tue Aug 12, 2008 7:59 pm
Projects :: Clone Wars Extended
Games I'm Playing :: BF2

Re: Is it possible to divide my lua into 2 parts?

Post by Deviss »

Ace_Azzameen_5 wrote:You could just modify your one LUA? And if the same model name appears over and over there is the "replace" function of notepad...
I'm also not sure how you know how to make 120 .lua's but not 2.
Also, what does "when I change one model I have to modify 120 files" have to do with the in-game scripts?
i mean for example i want change random model to other name, so i must modify 120 lua files (because i have random models in 120) :S, for this reason i wanted divide lua in 2 parts one from map sides etc and the second with random models only :)



EDIT
bumping my own topic xD, i was reading about custom lvl by zerted, but i dont understand how use them for put my random units chunk :S could anyone help me please? maybe mav because i know he made one thing simil to the mine :)

thanks in advance
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: Is it possible to divide my lua into 2 parts?

Post by [RDH]Zerted »

I rewrote my doc on making a custom lvl. The new version gives people three different ways to do it:
Hidden/Spoiler:
Overview
* This tutorial will guide you through three different ways of munging a custom lvl file. The first way lets you use VisualMunge, the second way is better if you plan on making multiple custom lvl files, and the third way is easiest if you are only doing it once.


Requirements
* SWBF2 mod tools
* Basic understanding of modding
* Basic understanding of the munge process
* This guide will assume the mod map's code is XXX
* This guide will assume the lvl you want to created will be named: upgrade.lvl


-------------
-- Way One --
-------------
1) Create the folder: data_XXX\Shell
2) Create the text file: data_XXX\Shell\shell.req
3) Create the folder: data_XXX\Shell\scripts
4) Create the script file: data_XXX\Shell\scripts\test.lua
5) In shell.req, add the following code (The 'test' should match the name of the script created in step 5, but without its file extension):

ucft
{
REQN
{
"script"
"test"
}
}

6) Open VisualMunge, click "Unselect All", check "Shell", click "Munge"
7) When VisualMunge finishes, it will have created the lvl file: data_XXX\_LVL_PC\shell.lvl
8) Rename shell.lvl to upgrade.lvl, then copy it to where you need the file.
Note) The test.lua script is just an example script file. You should change the req file to reflect whatever it is you are trying to munging.
Note) Anything that can go into the game's shell.lvl can now be put into your custom lvl through the shell.req.


-------------
-- Way Two --
-------------
1) Create the folder: data_XXX\Upgrade
2) Create the file: data_XXX\Upgrade.req
3) In Upgrade.req, add the following code:

ucft
{

}

4) Create the folder: data_XXX\_BUILD\Upgrade
5) Copy: data_XXX\_BUILD\Shell\clean.bat
To: data_XXX\_BUILD\Upgrade\clean.bat
6) Copy: data_XXX\_BUILD\Shell\menu.bat
To: data_XXX\_BUILD\Upgrade\menu.bat
7) In your new data_XXX\_BUILD\Upgrade\menu.bat, replace all "shell" with "upgrade"
8) Now use your Upgrade.req as if it were a Shell.req. This means anything you could put in shell.lvl you could put in upgrade.lvl.
9) To create/munge your Upgrade.lvl, run: data_XXX\_BUILD\Upgrade\menu.bat
Note) To clean when you have issues, run: data_XXX\_BUILD\Upgrade\clean.bat
Note) Anything that can go into the game's shell.lvl can now be put into your custom lvl through the shell.req.
Note) If you wanted to add non-shell.lvl stuff to your upgrade.lvl (such as custom sides), copy the "menu.bat" and "clean.bat" from the _BUILD folder of the type of lvl you want to make instead of copying them from the Shell _BUILD folder. If that doesn't work or if you don't understand, follow Way Three as described below.
Note) Copy upgrade.lvl to where ever you need it in your map's addon folder.


---------------
-- Way Three --
---------------
1) Find the .req file that controls the type of things you want in your upgrade.lvl. As an example, core.req contains localization strings and mission.req contains config, some level data, and general Lua scripts.
2) Find the .lvl file the .req ends up creating. These are normally in: data_XXX\_LVL_PC
3) Backup the .req file. One way this can be done is by copying the file to another location.
4) Edit the original .req file (not the backuped one) to include only the things you want in your upgrade.lvl.
5) Use VisualMunge to munge that .req into its .lvl file.
6) Rename the new .lvl into upgrade.lvl.
7) Restore the .req's backup
8) Use VisualMunge to get the restored .req's original .lvl file.
Note) Copy upgrade.lvl to where ever you need it in your map's addon folder.
To do what you want, you'll need to create an lvl (or you could always make more than one) that holds your models and a script. We'll call the lvl legion.lvl and the script legion_config.lua. The script should contain functions for the things you want done. A quick example:

Code: Select all

function LegionDataSetup()
    --read in the models here
end

function LegionUnitSetup
    --add units to teams here
end
In ScriptPostLoad near where ingame.lvl is loaded, load your lvl. Don't forget, you will need to include the path to your lvl (it isn't included in this example): ReadDataFile("legion.lvl")

On the next line, process the script: ScriptDB_DoFile("legion_config")

Now, just call those LegionXXXX functions whenever you need them. When the map is using ReadDataFile to load the units, vehicles, etc... use LegionDataSetup(). When it's time to setup the teams, use LegionUnitSetup().


There are many ways to do it, this way seemed to be the easiest way to explain it w/o having to go into a lot of details into how things work. Also I haven't tested this exact method, but it should work.
Deviss
Master of the Force
Master of the Force
Posts: 3772
Joined: Tue Aug 12, 2008 7:59 pm
Projects :: Clone Wars Extended
Games I'm Playing :: BF2

Re: Is it possible to divide my lua into 2 parts?

Post by Deviss »

[RDH]Zerted wrote:I rewrote my doc on making a custom lvl. The new version gives people three different ways to do it:
Hidden/Spoiler:
Overview
* This tutorial will guide you through three different ways of munging a custom lvl file. The first way lets you use VisualMunge, the second way is better if you plan on making multiple custom lvl files, and the third way is easiest if you are only doing it once.


Requirements
* SWBF2 mod tools
* Basic understanding of modding
* Basic understanding of the munge process
* This guide will assume the mod map's code is XXX
* This guide will assume the lvl you want to created will be named: upgrade.lvl


-------------
-- Way One --
-------------
1) Create the folder: data_XXX\Shell
2) Create the text file: data_XXX\Shell\shell.req
3) Create the folder: data_XXX\Shell\scripts
4) Create the script file: data_XXX\Shell\scripts\test.lua
5) In shell.req, add the following code (The 'test' should match the name of the script created in step 5, but without its file extension):

ucft
{
REQN
{
"script"
"test"
}
}

6) Open VisualMunge, click "Unselect All", check "Shell", click "Munge"
7) When VisualMunge finishes, it will have created the lvl file: data_XXX\_LVL_PC\shell.lvl
8) Rename shell.lvl to upgrade.lvl, then copy it to where you need the file.
Note) The test.lua script is just an example script file. You should change the req file to reflect whatever it is you are trying to munging.
Note) Anything that can go into the game's shell.lvl can now be put into your custom lvl through the shell.req.


-------------
-- Way Two --
-------------
1) Create the folder: data_XXX\Upgrade
2) Create the file: data_XXX\Upgrade.req
3) In Upgrade.req, add the following code:

ucft
{

}

4) Create the folder: data_XXX\_BUILD\Upgrade
5) Copy: data_XXX\_BUILD\Shell\clean.bat
To: data_XXX\_BUILD\Upgrade\clean.bat
6) Copy: data_XXX\_BUILD\Shell\menu.bat
To: data_XXX\_BUILD\Upgrade\menu.bat
7) In your new data_XXX\_BUILD\Upgrade\menu.bat, replace all "shell" with "upgrade"
8) Now use your Upgrade.req as if it were a Shell.req. This means anything you could put in shell.lvl you could put in upgrade.lvl.
9) To create/munge your Upgrade.lvl, run: data_XXX\_BUILD\Upgrade\menu.bat
Note) To clean when you have issues, run: data_XXX\_BUILD\Upgrade\clean.bat
Note) Anything that can go into the game's shell.lvl can now be put into your custom lvl through the shell.req.
Note) If you wanted to add non-shell.lvl stuff to your upgrade.lvl (such as custom sides), copy the "menu.bat" and "clean.bat" from the _BUILD folder of the type of lvl you want to make instead of copying them from the Shell _BUILD folder. If that doesn't work or if you don't understand, follow Way Three as described below.
Note) Copy upgrade.lvl to where ever you need it in your map's addon folder.


---------------
-- Way Three --
---------------
1) Find the .req file that controls the type of things you want in your upgrade.lvl. As an example, core.req contains localization strings and mission.req contains config, some level data, and general Lua scripts.
2) Find the .lvl file the .req ends up creating. These are normally in: data_XXX\_LVL_PC
3) Backup the .req file. One way this can be done is by copying the file to another location.
4) Edit the original .req file (not the backuped one) to include only the things you want in your upgrade.lvl.
5) Use VisualMunge to munge that .req into its .lvl file.
6) Rename the new .lvl into upgrade.lvl.
7) Restore the .req's backup
8) Use VisualMunge to get the restored .req's original .lvl file.
Note) Copy upgrade.lvl to where ever you need it in your map's addon folder.
To do what you want, you'll need to create an lvl (or you could always make more than one) that holds your models and a script. We'll call the lvl legion.lvl and the script legion_config.lua. The script should contain functions for the things you want done. A quick example:

Code: Select all

function LegionDataSetup()
    --read in the models here
end

function LegionUnitSetup
    --add units to teams here
end
In ScriptPostLoad near where ingame.lvl is loaded, load your lvl. Don't forget, you will need to include the path to your lvl (it isn't included in this example): ReadDataFile("legion.lvl")

On the next line, process the script: ScriptDB_DoFile("legion_config")

Now, just call those LegionXXXX functions whenever you need them. When the map is using ReadDataFile to load the units, vehicles, etc... use LegionDataSetup(). When it's time to setup the teams, use LegionUnitSetup().


There are many ways to do it, this way seemed to be the easiest way to explain it w/o having to go into a lot of details into how things work. Also I haven't tested this exact method, but it should work.
wow you broke my brain :shock: , i dont understand what part are of legion_config.lua and what parts are on my xxxc_con.lua :S i know i requested much, but could i request put the lines in lua examples please ? i really got confuse
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Re: Is it possible to divide my lua into 2 parts?

Post by [RDH]Zerted »

I can't give you the exact code you need because I don't know exactly what you plan on doing. legion_config.lua (legion50x.lua) should have all the legion stuff that is common to all your maps.

Here's some untested example code. It has one team being loaded from legion_config.lua:
Hidden/Spoiler:
legion_config.lua/legion50x.lua:[code]function SetupModelChanging()
--TODO add your model changing code here
end

function LegionDataSetup()
--read in the models here
ReadDataFile("dc:..\\deviss\\common\\50X.lvl",
"legion1",
"legion2",
"legion3",
"legion4",
"legion5",
"legion6",
"legion7",
"legion8",
"legion9")
end

function LegionUnitSetup
--add units to teams here
SetupTeams{
rep = {
team = REP,
units = 50,
reinforcements = 150,
soldier = { "legion1",15, 20},
pilot = { "legion2",4,5},
assault = { "legion3",4,5},
sniper = { "legion4",4,5},
marine = { "legion5",4,5},
engineer = { "legion6",4,5},
officer = { "legion7",4,5},
special = { "legion8",4,5},
commander = { "legion9",2,3},
},
}
end[/code]XXXc_con.lua:[code]--
-- Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
--
ScriptCB_DoFile("setup_teams")
ScriptCB_DoFile("ObjectiveConquest")

-- Republic Attacking (attacker is always #1)
local REP = 1
local CIS = 2
-- These variables do not change
local ATT = 1
local DEF = 2

---------------------------------------------------------------------------
-- FUNCTION: ScriptInit
-- PURPOSE: This function is only run once
-- INPUT:
-- OUTPUT:
-- NOTES: The name, 'ScriptInit' is a chosen convention, and each
-- mission script must contain a version of this function, as
-- it is called from C to start the mission.
---------------------------------------------------------------------------

function ScriptPostLoad()
--This defines the CPs. These need to happen first
cp1 = CommandPost:New{name = "cp1-1"}
cp2 = CommandPost:New{name = "cp2-1"}
cp3 = CommandPost:New{name = "cp3-1"}
cp4 = CommandPost:New{name = "cp4-1"}
cp5 = CommandPost:New{name = "cp5-1"}
cp6 = CommandPost:New{name = "cp6-1"}

--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(cp4)
conquest:AddCommandPost(cp5)
conquest:AddCommandPost(cp6)

conquest:Start()

SetupModelChanging() --setups and starts the model chaning timer

EnableSPHeroRules()
end

function ScriptInit()
ReadDataFile("legion50x") --loads your custom lvl file
ScriptCB_DoFile("legion_config") --loads the lua script that was inside your custom lvl file
ReadDataFile("ingame.lvl")

SetMemoryPoolSize("Music", 200)

ReadDataFile("sound\\fel.lvl;fel1cw")
ReadDataFile("dc:sound\\ABC.lvl;ABCcw")
SetMaxFlyHeight(53)
SetMaxPlayerFlyHeight (53)
ReadDataFile("SIDE\\rep.lvl",
"rep_hero_aalya")

LegionDataSetup() --reads in the units

ReadDataFile("dc:SIDE\\fed.lvl",
"cis_droid1",
"cis_droid2",
"cis_droid3",
"cis_droid4",
"cis_droid5",
"cis_droid6",
"cis_droid7",
"cis_droid9",
"cis_hero")

ReadDataFile("dc:SIDE\\veh.lvl",
"cis_tread_snailtank",
"rep_walk_oneman_atst")

SetAttackingTeam(ATT)

LegionUnitSetup() --setups the Legion team

SetupTeams{
cis = {
team = CIS,
units = 50,
reinforcements = 150,
soldier = { "cis_droid1",10, 30},
pilot = { "cis_droid2",5,7},
assault = { "cis_droid3",5,7},
sniper = { "cis_droid4",5,7},
marine = { "cis_droid5",8,9},
engineer = { "cis_droid6",4,5},
officer = { "cis_droid7",4,5},
commander = { "cis_droid9",2,4},
},
}

SetHeroClass(REP, "rep_hero_aalya")
SetHeroClass(CIS, "cis_hero")

-- Level Stats
ClearWalkers()
AddWalkerType(1, 2)
AddWalkerType(0, 4)
local weaponCnt = 1600
SetMemoryPoolSize("Aimer", 1024)
SetMemoryPoolSize("AmmoCounter", weaponCnt)
SetMemoryPoolSize("BaseHint", 1024)
SetMemoryPoolSize("EnergyBar", weaponCnt)
SetMemoryPoolSize("CommandWalker", 1)
SetMemoryPoolSize("EntityHover", 4)
SetMemoryPoolSize("EntityLight", 33)
SetMemoryPoolSize("EntitySoundStream", 100)
SetMemoryPoolSize("EntitySoundStatic", 200)
SetMemoryPoolSize("EntityWalker", 5)
SetMemoryPoolSize("MountedTurret", 100)
SetMemoryPoolSize("Obstacle", 1024)
SetMemoryPoolSize("PathNode", 1024)
SetMemoryPoolSize("SoldierAnimation", 1024)
SetMemoryPoolSize("TreeGridStack", 1024)
SetMemoryPoolSize("Weapon", 1024)
SetMemoryPoolSize("FlagItem", 5)
SetMemoryPoolSize("AcklayData", 6)
SetMemoryPoolSize("EntityFlyer", 6)

SetSpawnDelay(10.0, 0.25)
ReadDataFile("xxx\\xxx1.lvl", "xxx1_conquest")
SetDenseEnvironment("false")
SetAIViewMultiplier(0.65)

-- Birdies
SetNumBirdTypes(1)
SetBirdType(0,1.0,"bird")

-- Sound Stats...
-- Camera Stats...
end[/code]
Post Reply