Yeah, nothing returns character class names simply. What you quoted from me is how to compare strings of object class names, but character class names are different. The suggestion that you're given in the
Battlefront2_scripting_system.doc is to use "GetEntityClassName(GetCharacterUnit(player))," but as you've seen, that doesn't work.
What you can pull is the ID of the class (0-n) based on the order classes are loaded in (with AddUnitClass) using GetCharacterClass. I did a short test and verified this awful hackjob of a workaround, and while I'm sure you could make it cleaner, it's a starting point.
I edited SetupTeams.lua (since that's where classes are added by default) around line 17 to initialize two tables:
Code: Select all
--ADDED
unittablemaster1 = {}
unittablemaster2 = {}
-- for each specified side...
I then edited the
for loop that adds classes to fill those (non-local) tables:
Code: Select all
-- add unit classes in type order
--ADDED: changed _ to index
for index, 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])
--ADDED
table.insert (unittablemaster1, {unitteam = team, unitclass = side[type][1]})
print("Added one", index)
print("Unittable", unittablemaster1[1].unitteam)
if index ~= 1 and unittablemaster1[1].unitteam ~= team then
print("Checked index")
table.insert (unittablemaster2, {unitteam = team, unitclass = side[type][1]})
end
end
end
Then you can call your table positions however you want. I used a test function with OnCharacterChangeClass (added to ScriptPostLoad) to test:
Code: Select all
testname = OnCharacterChangeClass(
function(player)
if GetCharacterUnit(player) then
if GetObjectTeam(GetCharacterUnit(player)) == 1 then
print(unittablemaster1[GetCharacterClass(player) + 1].unitclass)
elseif GetObjectTeam(GetCharacterUnit(player)) == 2 then
print(unittablemaster2[GetCharacterClass(player) + 1].unitclass)
end
end
end
)
That'll spit back your character class names as strings, which is what you want.
Edit: A simpler way might just to be to write a function that tests AddUnitClass for its team and class name arguments every time it's run (and make your table from that), but you'd have to make sure to run it before ScriptPostLoad. Same principle, though.