Page 1 of 1

How Do I add Custom Units to a released map?

Posted: Mon May 26, 2014 11:49 am
by KeepAmazinn
How do I put in custom Units (Ex 212 Battalion) into a custom map that only uses stock sides?

Re: How Do I add Custom Units to a released map?

Posted: Mon May 26, 2014 12:34 pm
by Kingpin
You would have to have the source for the map, so it would only be possible unless on the stock maps. Unless you knew the names of the units that the LUA called for, then you could munge custom ones and replace them in the addon. However, if you are doing it on a stock map, it would not be so complicated. Simply create a custom era.
Some Useful Links:
http://www.gametoast.com/viewtopic.php? ... 96#p287596
http://www.gametoast.com/viewtopic.php? ... 94#p281994
Also, check the v1.3 patch documentation; I found some useful stuff regarding changing the name, era icon, and so on.

Re: How Do I add Custom Units to a released map?

Posted: Mon May 26, 2014 12:47 pm
by commanderawesome
KeepAmazinn wrote:How do I put in custom Units (Ex 212 Battalion) into a custom map that only uses stock sides?
That's a tricky one. You might be able to do it with THIS, but I don't know if it works with other mod missions. Another option is, while a bit tedeous, you mentioned other clone units, if you have BFX installed, you can load in the legion skins via the fake console's code console:
Hidden/Spoiler:
Just type in ReadDataFile("SIDE\\BFX\\SIDENAME.lvl", "insert unit name here")

Example:
ReadDataFile("SIDE\\BFX\\212.lvl", "rep_inf_212_rifleman", "rep_inf_212_engineer", "rep_inf_212_jettrooper")

Skins: (do NOT load the anything other than the above units)
212.lvl=212th attack battalion
501.lvl=501st legion
shk.lvl=shock troopers

Re: How Do I add Custom Units to a released map?

Posted: Mon May 26, 2014 6:46 pm
by Nedarb7
What commanderawesome suggested would probably do the trick. Here's an example:

(!To keep up with the progress of the workaround check out commanderawesome's post!)

I want to change some of the sides on my maps to custom ones (212th for this scenario). However, instead of creating a new release I want to make it like some sort of addon-for-addon type download. To do this I realize that I will need to create a new game mode

*skips game mode making*

Now that I have my game mode set up I realize that I no longer have my (Dantooine for this scenario) mission scripts. Uh oh, what am I going to do now? After spending some time thinking, I discover that I can execute the mission script from the maps mission file and inject my own code as well. This seems to be the perfect solution. Now to business...

I create my early mission script, which looks like so:

Code: Select all

ReadDataFile("..\\..\\addon\\DAN\\data\\_LVL_PC\\mission.lvl", "dan1c_con")
ScriptCB_DoFile("dan1c_con")

(Reads sub lvl file (dan1c_con) from my Dantooine mission file, since that is where the mission script is loaded. Second I use ScriptCB_DoFile() to execute that script.)

Now that the LUA reads my original mission script I'm all set to go, right? Well, I haven't added my 212th battalion yet! How will I go about adding my 212th units without access to the SetUpTeams thingamajig in Dantooine's mission script? :runaway: The answer is that I actually do have all the access I need, that access is found in the setup_teams LUA file.

Having opened the setup_teams LUA I see that there is a bunch of juicy code that will help me accomplish my task. Before going insane trying change everything I start with the main thing I want to happen, 212th classes. Considering the fact that I will also be changing classes for my Coruscant, Mustafar, Vjun, and Bespin maps, I want to create a piece of code that wont effect every one of my maps. How in the world would it effect my other maps? The answer to that question is that "setup_teams" is used by all the maps, that means that if I don't want to have 212th, 501st, and all on the same map I got to do something.

On top of all that, I discovered that I will also need to load the map level file too! Why is that? Because the ReadDataFile() lines that call on the maps level file no longer function properly. After making some quick changes to the setup_teams LUA file, I got this as a result:

Code: Select all

function SetupTeams(sides)
    -- HACKish: load the turret .odf here (this is the easiest place to put it where it will
    --          be executed in every level
    --ReadDataFile("SIDE\\tur.lvl",                     --disabled for now until we settle on where exactly the .odf will end up
    --              "tur_bldg_defensegridturret")
    
    -- Load my map's level file, managed by the mapCode variable in the mission script
    if mapCode == 1 then
    ReadDataFile("..\\..\\addon\\DAN\\data\\_LVL_PC\\DAN\\DAN.lvl", "DAN_conquest")
    end
  
    -- list of types
    local typeList = { "soldier", "pilot", "assault", "sniper", "marine", "engineer", "officer", "special" }

    -- items for each team code
    local teamItems = nil
    if ScriptCB_IsMissionSetupSaved() then
		local missionSetup = ScriptCB_LoadMissionSetup()
        teamItems = missionSetup.units
    end
    
    -- for each specified side...
    for name, side in pairs(sides) do
        local team = side.team

        -- set team properties
        local name = string.lower(name)
        SetTeamName(team, name)
        SetTeamIcon(team, name .. "_icon", "hud_reinforcement_icon", "flag_icon")
        SetUnitCount(team, side.units)
        SetReinforcementCount(team, side.reinforcements)

        -- add unit classes in type order
        for _, type in ipairs(typeList) do
            if side[type] and (not teamItems or not teamItems[name] or teamItems[name][type]) then
                AddUnitClass(team, side[type][1], side[type][2], side[type][3])
            end
        end

        -- add hero class if available
        if side[hero] then
            AddHeroClass(side[hero])
        end
    end
	-- Inject Custom Units into mission 
	
	-- Variable "unitCode" found in mission lua
	if unitCode == 212 then 
        ReadDataFile("dc:SIDE\\212th.lvl", "212th_inf_clone")
	AddUnitClass(REP, 212th_inf_clone, 1, 25)
	end
end

("Ummm... what am I looking at?" - Possibly you... The only new code here is found at "-- Load my map's level file, managed by the mapCode variable in the mission script" to the first "end" that follows it and "-- Inject Custom Units" to the "end" before the last "end")

At last! I don't need to worry about the mixed legion issue or not having a map to play on. By creating if statements I have control over which map is loaded and what units appear on that map! Now I just need to make the statements true and read the side file so that my unit appears. To do this I decide that it will be best to put the variable in my mission LUA, that way I can control the side from there. Once I finished editing my mission LUA here was the result:

Code: Select all

-- Variables that make the if statements in the setup_teams LUA true
mapCode = 1
unitCode = 212

-- Execute my map's script
ReadDataFile("..\\..\\addon\\DAN\\data\\_LVL_PC\\mission.lvl", "dan1c_con")
ScriptCB_DoFile("dan1c_con")
I have finally accomplished what I wanted to do. Now all that is left is a munge. :D

*even further*

Let's say I was missing localize keys from my map, to fix this I would need to read that file in my mission script like so:

Code: Select all

ReadDataFile("..\\..\\addon\\mapID\\data\\_LVL_PC\\core.lvl")
(!Warning, the following workaround has not be tested. I do not guarantee that it will work!)
Let's say I didn't want stock units. I could encase the piece of code that adds the original mission scripts units like so:

Code: Select all

if useStockUnits == 1 then
            if side[type] and (not teamItems or not teamItems[name] or teamItems[name][type]) then
                AddUnitClass(team, side[type][1], side[type][2], side[type][3])
            end
         end
Being sure to create a "useStockUnits" variable in the mission script set to any number other than 1.

I hope you find that scenario helpful. I need a break :faint:

Re: How Do I add Custom Units to a released map?

Posted: Mon May 26, 2014 11:09 pm
by KeepAmazinn
commanderawesome wrote:
KeepAmazinn wrote:How do I put in custom Units (Ex 212 Battalion) into a custom map that only uses stock sides?
That's a tricky one. You might be able to do it with THIS, but I don't know if it works with other mod missions. Another option is, while a bit tedeous, you mentioned other clone units, if you have BFX installed, you can load in the legion skins via the fake console's code console:
Hidden/Spoiler:
Just type in ReadDataFile("SIDE\\BFX\\SIDENAME.lvl", "insert unit name here")

Example:
ReadDataFile("SIDE\\BFX\\212.lvl", "rep_inf_212_rifleman", "rep_inf_212_engineer", "rep_inf_212_jettrooper")

Skins: (do NOT load the anything other than the above units)
212.lvl=212th attack battalion
501.lvl=501st legion
shk.lvl=shock troopers
Tried what you said above and it didn't work.

Re: How Do I add Custom Units to a released map?

Posted: Mon May 26, 2014 11:23 pm
by commanderawesome
Nedarb7 wrote: (!Notice, this workaround has not confirmed to work with mod maps. To keep up with the progress of the workaround check out commanderawesome's post!)
Off topic:Maybe the admins should merge the two threads...