Aller au contenu

Photo

Need help triggering a fight between two hostiles


6 réponses à ce sujet

#1
Sonmeister

Sonmeister
  • Members
  • 167 messages
I'm trying to trigger some creatures to appear (which is working) but then I want them to fight each other before they attack my pc but instead they all charge at me.  Tell me what I am doing wrong - here's the basic original script, I've also tried these variations  UT_CombatStart(oAttacker, oTarget, TRUE, TRUE);  UT_CombatStart(oAttacker, oTarget, FALSE, TRUE);  UT_CombatStart(oAttacker, oTarget, TRUE, FALSE);

//::///////////////////////////////////////////////
//:: Trigger Events Template
//:: Copyright © 2003 Bioware Corp.
//:://////////////////////////////////////////////
/*
    Trigger events : Activate fight
*/
//:://////////////////////////////////////////////
//:: Created By: 
//:: Created On: 
//:://////////////////////////////////////////////

#include "log_h"
#include "utility_h"
#include "wrappers_h"
#include "events_h"

const int TEAM_ONE = 333;
const int TEAM_TWO = 334;

const string OGRE = "mr_ogre";
const string DRAKE = "mr_drake";

object oAttacker = GetObjectByTag(OGRE);
object oTarget = GetObjectByTag(DRAKE);

void main()
{
    event ev = GetCurrentEvent();
    int nEventType = GetEventType(ev);
    string sDebug;
    object oPC = GetHero();
    object oParty = GetParty(oPC);
    int nEventHandled = FALSE;

    switch(nEventType)
    {
        ////////////////////////////////////////////////////////////////////////
        // Sent by: The engine
        // When: The object spawns into the game. This can happen only once,
        //       regardless of save games.
        ////////////////////////////////////////////////////////////////////////
        case EVENT_TYPE_SPAWN:
        {
            break;
        }
        ////////////////////////////////////////////////////////////////////////
        // Sent by: The engine
        // When: A creature enters the trigger
        ////////////////////////////////////////////////////////////////////////
        case EVENT_TYPE_ENTER:
        {
            object oCreature = GetEventCreator(ev);
            int nOnce = GetLocalInt(OBJECT_SELF,TRIGGER_DO_ONCE_A);

            if (nOnce == FALSE)
            {
                SetLocalInt(OBJECT_SELF, TRIGGER_DO_ONCE_A, TRUE);

                //Activate the teams
                UT_TeamAppears(TEAM_ONE);
                UT_TeamAppears(TEAM_TWO);

                // Start a fight between the teams
                UT_CombatStart(oAttacker, oTarget);
            }


            break;
        }
        ////////////////////////////////////////////////////////////////////////
        // Sent by: The engine
        // When: A creature exits the trigger
        ////////////////////////////////////////////////////////////////////////
        case EVENT_TYPE_EXIT:
        {
            object oCreature = GetEventCreator(ev);

            break;
        }

    }
    if (!nEventHandled)
    {
        HandleEvent(ev, RESOURCE_SCRIPT_TRIGGER_CORE);
    }
}

#2
Kilrogg_

Kilrogg_
  • Members
  • 296 messages
They're attacking you because they aren't hostile to each other. Members of groups that are not hostile cannot attack each other in any way.

I had to do a similar thing for my mod recently and it's fairly simple. Use SetGroupId and SetGroupHostility after spawning them:

        SetGroupId(oBadGuy, 1);
        SetGroupId(oOtherBadGuy, 2);
        SetGroupHostility(1, 2, TRUE);

Then use AddCommand to add a CommandAttack to each bad guy, with each other as the target.

Should work just fine. Obviously you will most likely pull aggro off them if you attack them, so if you need to force them to attack each other to the death even if the player interacts, I'm not sure how to do that.

For the record, the group ID can be anything, it overrides the one in the creature's properties and can just be a number.

Modifié par Kilrogg_, 03 juillet 2010 - 02:04 .


#3
FergusM

FergusM
  • Members
  • 460 messages

Should work just fine. Obviously you will most likely pull aggro off them if you attack them, so if you need to force them to attack each other to the death even if the player interacts, I'm not sure how to do that.


I think you can do something like:

UpdateThreatTable(guy,histarget,9999.0);

Modifié par FergusM, 03 juillet 2010 - 02:05 .


#4
Sonmeister

Sonmeister
  • Members
  • 167 messages
Thanks Kilrogg, works great. Haven't tried the UpdateThreatTable yet.

#5
Kilrogg_

Kilrogg_
  • Members
  • 296 messages
Just to clarify, the attack command is not necessary if the two parties are closer to each other than to the player. They'll go for each other's throats anyway, and in fact UpdateThreatTable might be a better choice than an attack command.

#6
DavidSims

DavidSims
  • BioWare Employees
  • 196 messages
I can't say for certain what is happening in the original code, because I don't know the starting groups of the creatures. Combat start does a number of different things depending on the situation, but generally it moves creatures into the hostile group if they are told to attack the PC, or it generates hostility between the groups of the two creatures specified. If the two creatures are in the same group, it does nothing.

Be very careful about setting creature groups to arbitrary numbers and changing the hostility between those groups. Groups 0-3 are the PC group, the hostile group, the friendly group and the neutral group. module_core will set up the hostility for those groups, and past that point they shouldn't be touched.

If you want to creatures to attack each other, you probably want them to have custom groups. Groups can be any number, but be aware of the possibility of a number being used elsewhere. If you're in your own module that's not a big deal, but keep track of it somewhere. If you're making an add-in to Single Player, avoid any group number less than 60, because they are used in the campaign. Modifying the hostility between those groups could cause problems somewhere. To avoid conflicts with DLC or Awakening, I'd stay over 100000. Again, that's only for add-ins, custom modules should be fine with anything over 3, although avoiding 36 is important if you take advantage of the "fake dead" zombie ambush system.

Killrog's code works, but it's using the existing hostile and friendly groups. The creature in group 1 will be hostile to the player, while the creature in group 2 will show up as an ally. If that is desired, then great, the only change I'd make is to use the constants GROUP_HOSTILE and GROUP_FRIENDLY instead of the numbers. If it's not desired, I'd pick a couple of large numbers and use those groups instead.

Note: one thing to be clear on is that teams and groups are very different things. Group is used to determine hostility. Team is a helpful way to lump creatures together and grab them through scripting.

Modifié par DavidSims, 05 juillet 2010 - 03:48 .


#7
Kilrogg_

Kilrogg_
  • Members
  • 296 messages
I actually use 30 and 31 in my script, but changed it to 1 and 2 for the example's sake.



Good to know :)