Lua Function Question Force Spawn
Posted: Mon Dec 24, 2012 6:35 pm
I'm trying to grab the odf name of a unit as it spawns.
Here's what I have for code.
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...
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)
...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...