Aller au contenu

Photo

Best way to have a creature fight, take damage, then run away?


  • Veuillez vous connecter pour répondre
4 réponses à ce sujet

#1
Talisander

Talisander
  • Members
  • 173 messages
Hey all, so I've already got this kind of working in game, but I feel like I might be doing it in a strange way and I wanted to discuss what people think the best way to achieve this is.

Basically, some guards attack you and fight for a while, but before they die they flee the battle.  The player shouldn't be able to kill them all -- it might be interesting to have a system flexible enough that a few could be killed while most get away, but the most important thing story-wise is that they run away and the player isn't completely butchering them.

Right now I'm enabling the surrender variable on my creature, and then having a conversation run on surrender with some ambient dialog I want ("Run Awaay!" and so on,) and then I'm giving the end node of that conversation a simple script:

void main()

{

      object oGuard = OBJECT_SELF;
      UT_QuickMoveObject(oGuard, "0", TRUE, FALSE, TRUE, FALSE);

}



I'm also setting the creature to be immortal, so it will surrender when it reaches 0 health but won't die.  The only thing I have left to fix is that I want groups of creatures to attack, and only run away on an individual basis, when they've taken some damage.  What I'm going to try is to make several similar creatures and give each of them their own group, which hopefully will make one creature's surrender not affect the other creatures.

This seems a little awkward to me, and I wonder if there's a better way?  I do want them all to have different faces though, so maybe creating seperate creatures is the way to go...

Should I be using surrender plot flags and running the scripts off of those, or writing a script to replace CREATURE_CORE on the creature to listen for a surrender event on each creature, and do the running away function there? 



*edit*

Oh, and the last possibility I can think of is that there seems to be some scripting for creatures who are supposed to retreat in the singleplayer game.  I think it's related to custom AI stuff.


For example: 
lot100cr_hurlock_emissary.nss has a function Emissary_ActivateRetreat() which I'm looking at now.


Thanks for reading,


Alex

Modifié par Talisander, 18 juillet 2010 - 09:42 .


#2
SynysterLyfe

SynysterLyfe
  • Members
  • 32 messages
I have a similar thing happening in my module.

What I did was set the creatures to Immortal, then put the following in their event handling scripts:

switch(eType)
    {
        case EVENT_TYPE_DAMAGED:
        {
           
            // Because they're Immortal their health won't drop below 1
            if(GetCurrentHealth(OBJECT_SELF) == 1.0)
            {
                // This makes them non-hostile and moves them to a pre-defined retreat waypoint
                UT_CombatStop(OBJECT_SELF, GetHero());
                AddCommand(OBJECT_SELF, CommandMoveToObject(GetObjectByTag("retreat_wp")));

                // This stuff is for if you want something to fire when everyone in the team is "killed"
                int nTeamID = GetTeamId(OBJECT_SELF);
                if(nTeamID != -1)
                {
                    SetTeamId(OBJECT_SELF, -1);

                    object [] arTeam = GetTeam(nTeamID);
                    int nSize = GetArraySize(arTeam);

                    if(nSize == 0)
                    {
                        // Here's where you put the script to fire when the team is "dead"
                    }
                }
            }

            bEventHandled = TRUE;
            break;
        }
}

Now if you want some guards to die, just make a couple of them mortal. The chances of them hitting exactly 1 HP is pretty slim, so they should die without triggering the script.

Hope this helps :lol:

#3
Guest_dewkl_*

Guest_dewkl_*
  • Guests
Writing/editing the creature script is the easiest way to go. I would do something like synysterlyfe, except I'd also make it check for the creature's team and set waypoint depending on that (so they flee in different directions).  I would also make it surrender before the last hitpoint to make it seem more natural (minimum+random number).

As for randomized headmorphs, I'm not sure. I've been wondering this myself. Doesn't seem like it's possible (through scripting, that is).

#4
SynysterLyfe

SynysterLyfe
  • Members
  • 32 messages
Yea. If you want it to surrender before the last hitpoint then just turn the Health == 1.0 into Health <= (minimum + random number) like dewkl suggested.



But having them all on different teams would make the "on team death" part of the script fire multiple times, once for each team. But if you're not worried about that then dewkl's suggestion is a good one for making them flee in different directions.

#5
Talisander

Talisander
  • Members
  • 173 messages
Hey guys, I just realized I never properly thanked either of you for this one, so... thanks :)

Also, I thought I'd post the code I'm using right now, which I've made a few changes to.


...

object oPC = GetHero();
object oThis = OBJECT_SELF;

...

case EVENT_TYPE_DAMAGED:
{
float fmaxHP = GetMaxHealth(oThis);
float fcurrentHP = GetCurrentHealth(oThis);


if((fcurrentHP/fmaxHP) < 0.3f)
{

UT_CombatStop(oThis, oPC);
UT_QuickMoveObject(oThis, "wp_townguard_flee", TRUE, FALSE, TRUE, TRUE);


int nTeamID = GetTeamId(oThis);

//could base which waypoint they run to on team number here (nTeamID),
//allowing multiple escape paths with one generic creature script

if(nTeamID != -1)
{
SetTeamId(oThis, -1); // this de-registers the creature from the team
object [] arTeam = GetTeam(nTeamID);
int nSize = GetArraySize(arTeam);

if(nSize == 0) // no more team members
{
// send team death event to area of this creature
SendEventTeamDestroyed(GetArea(oThis), nTeamID);
}
}

}


break;
}



I like the idea of having them run away when they've lost a randomized amount of health, but it doesn't matter in the area I'm making, because the enemies are losing big chunks of health, so you're not really keeping track of how low they are.

The one improvement of my script is that it sends a team destroyed event to the area. That way you can handle teams of creatures getting killed and teams of creatures running away like this all in the same place!

Thanks again guys!

Alex

Modifié par Talisander, 09 août 2010 - 12:02 .