• Welcome to Freedom Reborn Archive.
 

Spawning a Hero File Character

Started by GogglesPizanno, September 19, 2008, 10:55:39 AM

Previous topic - Next topic

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.


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)


stumpy

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.

M25

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.