Lua Function Question Force Spawn

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

Post Reply
kinetosimpetus
Imperial Systems Expert
Imperial Systems Expert
Posts: 2381
Joined: Wed Mar 25, 2009 4:15 pm
Projects :: A secret project
Games I'm Playing :: Warframe STO

Lua Function Question Force Spawn

Post by kinetosimpetus »

I'm trying to grab the odf name of a unit as it spawns.

Here's what I have for code.

Code: Select all

    dudespawned = OnCharacterSpawn( --someone spawned

        function(character)
            self:Debug_Out("Dude spawned")

            --AI
            if IsCharacterHuman(character) == false then 
                self:Debug_Out("Dude was AI")

                local unit = GetCharacterUnit(character)
                local class_str = GetEntityClassName(unit) --This line is the major issue I'm hitting right now. either returns an int or nil depending on what the parameter is (character or unit), need a string that is the unit class's odf name
                
                if class_str == nil then
                    self:Debug_Out("class_str == nil")
                else
                    self:Debug_Out("class_str == " .. class_str)
                ...
The Human/AI check is working fine.



I just looked at the Geonosis training campaign script, and it uses integers to identify which class is spawned as, but that doesn't seem like it will work for me. My troopers won't always have the same index. Is there a way to map the index to the odf name, preferably with a function call, or a series of calls that I could code instead of hardcoding a terabyte of information about all my units? (ok, maybe not a terabyte, but getting this one thing working would save me a looooot of work.)

Could I modify setup_teams to keep track of the odf name and index relationship?

EDIT: edited my function script to include a new version of SetupTeams() that takes twice as many parameters for each unit and stores them in tables for querying.

Got my data stored, now I'm looking for how to force spawn a particular unit class, preferably without using a separate ambush team. I tried searching, but didn't find anything. I'll doublecheck the EYN now...
Post Reply