Freedom Reborn Archive

Freedom Force Forums => Scripting Forum => Topic started by: GogglesPizanno on September 19, 2008, 10:55:39 AM

Title: Spawning a Hero File Character
Post by: GogglesPizanno on September 19, 2008, 10:55:39 AM
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.

Title: Re: Spawning a Hero File Character
Post by: M25 on September 19, 2008, 01:32:28 PM
IIRC, you just use the regular spawn functions with the name of the hero file you want to spawn (without the extension).


Title: Re: Spawning a Hero File Character
Post by: GogglesPizanno on September 19, 2008, 01:48:11 PM
That's it?
I refuse to believe its that simple.  :blink:
But I'll try it when i get home.

Thanks.
Title: Re: Spawning a Hero File Character
Post by: catwhowalksbyhimself on September 19, 2008, 09:21:15 PM
I'm pretty sure spawning from a hero file was different.  Could be wrong, though.
Title: Re: Spawning a Hero File Character
Post by: M25 on September 19, 2008, 11:36:20 PM
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.


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)

Title: Re: Spawning a Hero File Character
Post by: stumpy on September 20, 2008, 05:18:33 AM
I never knew that AI_MakeHeroAI() was needed after AI_DestroyHeroAI() if the character was to be a baddy. Does the minion AI that AI_DestroyHeroAI() leaves a character with not work right? I would have hoped that having a baddy character with minion AI (even if he was to be controlled by scripted AI) would help powers like Hypnosis and Rally work properly.
Title: Re: Spawning a Hero File Character
Post by: M25 on September 20, 2008, 12:25:51 PM
Yes, I remember playing around with this stuff, and I believe that the AI simply didn't work at all without the AI_MakeHeroAI().  It wouldn't even respond to the custom scripted AI.  It's been a while though.  It's possible I missed something.