Freedom Force Forums > Scripting Forum
Spawning a Hero File Character
GogglesPizanno:
So I'm trying to figure out a way to spawn a "hero file based" character from a mission script. I know it can be done as both FFX and EZScript do it in some form or other. I was hoping it already existed in some m25 or ffx function that I could just call, but that would be just too easy.
I don't necessarily need exact code, but just an idea about how to get a template for a hero file.
M25:
IIRC, you just use the regular spawn functions with the name of the hero file you want to spawn (without the extension).
GogglesPizanno:
That's it?
I refuse to believe its that simple. :blink:
But I'll try it when i get home.
Thanks.
catwhowalksbyhimself:
I'm pretty sure spawning from a hero file was different. Could be wrong, though.
M25:
OK, I took a look at the code. Spawning from the hero file is handled by the game, but it spawns as part of the player's team, so you need to do some contortions if you don't want that to happen.
Here's some (untested) code that shows the steps.
--- Code: ---import cshelper
import ai
import ffx
import m25ai
import m25team
def CustomSpawn(name, template, marker, as_hero=0, team=m25team.TEAM_BADGUYS):
#spawn the character
cshelper.spawn(name,template,marker)
if not as_hero:
#prevent the newly spawned character from being player controlled
if ffx.FFX_HasPortrait(name):
js.AI_DestroyHeroAI(name)
ffx.FFX_ObjectSetAttr(name, 'fakehero', 1)
js.AI_MakeHeroAI(name)
#if the character is to be a villain, stop the built-in AI from targeting other villains
ai = cshelper.findAI(name)
ai.removeNaturalKillGoal()
#and let the custom AI handle targeting
m25ai.SetBrawler(name)
m25ai.SetTeam(name, team)
#finally, set up the full custom AI if desired
m25ai.SetupAI(name)
--- End code ---
Navigation
[0] Message Index
[#] Next page
Go to full version