Author Topic: How do you script a duel?  (Read 383 times)

Legacy_Jthesunshinegirl

  • Newbie
  • *
  • Posts: 34
  • Karma: +0/-0
How do you script a duel?
« on: June 16, 2011, 06:46:24 pm »


               I am trying to create a dueling club scenario for my module. Basically, what is supposed to happen is that the PC and his companion duel two NPCs, and the duel ends when one of the NPCs gets down to 1 HP. I've figured out how to get the one NPC to surrender when her health gets too low, but I still have two problems I'm hoping someone can help with.
First, after the one NPC surrenders, her companion keeps fighting the PC and the PC's companion also continues fighting. I only want one of the opponents to have to "die" before they both surrender. Is there a way to expand the surrender script to get everyone to stop fighting?
Second, the other NPCs in the room join the fight if it goes on too long. These NPCs are supposed to be spectators and not get involved. I suspect this has something to do with factions, but I don't really understand how they work. I currently have them set as commoners, but they still start attacking the PC.
Any help/advice would be greatly appreciated. I'm pretty new at this and just wanted to try some things out, but I don't want to get in over my head.
               
               

               
            

Legacy__Knightmare_

  • Full Member
  • ***
  • Posts: 191
  • Karma: +0/-0
How do you script a duel?
« Reply #1 on: June 16, 2011, 07:58:34 pm »


               For #1, loop through all the creatures within X distance of a waypoint located at the center of the arena. Use GetFirst/NextObjectInShape() or something similar. When it finds a creature, have it ClearAllActions(TRUE) whichs should clear combat states, and if they are not players/PCs change their faction to one not hostile to the player (such as Commoner).

For #2, This is probably a faction issue as you stated. Change the spectators to a custom made faction this is neutral (50) to both the player and the fighting NPCs' factions.
               
               

               


                     Modifié par _Knightmare_, 16 juin 2011 - 06:59 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
How do you script a duel?
« Reply #2 on: June 16, 2011, 08:03:46 pm »


               Try something like the following script in the OnDamaged event of both of the NPCs. If you can give both of the NPCs the same tag, then you can use this same script for both of them. Otherwise each will have to have their own script with the correct tag plugged into it. Also make sure both NPCs are checked "immortal"

~You can change the 4 to whatever you want. That line is just saying that if the current HPs of the NPC are less than 4 then do stuff.
~Put the tag of the NPC's partner where it says "NPC Tag Here". Not the tag of self(unless the tags are the same which would be ideal).


void main()
{
    int iCurrHP = GetCurrentHitPoints(OBJECT_SELF);

    if (iCurrHP < 4)
    {
        object oDamager = GetLastDamager(OBJECT_SELF);
        object oPal = GetNearestObjectByTag("NPC Tag Here", OBJECT_SELF);
        object oArea = GetArea(OBJECT_SELF);

        ClearAllActions(TRUE);
        AssignCommand(oPal, ClearAllActions(TRUE));
        object oFactionMem = GetFirstFactionMember(oDamager, FALSE);
        while (GetIsObjectValid(oFactionMem))
        {
            if (GetArea(oFactionMem) == oArea)
            {
                AssignCommand(oFactionMem, ClearAllActions(TRUE));
                SetIsTemporaryFriend(oFactionMem, OBJECT_SELF, FALSE);
                AssignCommand(oPal, SetIsTemporaryFriend(oFactionMem, oPal, FALSE));
            }
            oFactionMem = GetNextFactionMember(oDamager, FALSE);
        }
    }
    ExecuteScript("nw_sc_default6", OBJECT_SELF);
}


Hope it helps. Good luck.
               
               

               


                     Modifié par GhostOfGod, 16 juin 2011 - 07:08 .
                     
                  


            

Legacy_Jthesunshinegirl

  • Newbie
  • *
  • Posts: 34
  • Karma: +0/-0
How do you script a duel?
« Reply #3 on: June 18, 2011, 11:40:48 pm »


               Thank you both for your help! It's working properly now. '<img'>
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
How do you script a duel?
« Reply #4 on: June 19, 2011, 04:38:31 am »


               Whoops. Just noticed a typo. If you are still keeping tabs on this thread then this line:

ExecuteScript("nw_sc_default6", OBJECT_SELF);

should be:

ExecuteScript("nw_c2_default6", OBJECT_SELF);

Sorry bout that.
               
               

               
            

Legacy_Jthesunshinegirl

  • Newbie
  • *
  • Posts: 34
  • Karma: +0/-0
How do you script a duel?
« Reply #5 on: June 20, 2011, 10:58:32 pm »


               Thanks for the update. It seemed to work fine how it was, but I'll gladly take your word for it. Would you mind explaining the difference between the two, just so I know?
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
How do you script a duel?
« Reply #6 on: June 21, 2011, 03:25:48 am »


               Well it was just a typo on my part as far as the name of the script gos. But that line isn't 100% needed. It just fires the default script after the custom one if the default behavior is still needed/wanted. The default is "nw_c2_default6".
               
               

               


                     Modifié par GhostOfGod, 21 juin 2011 - 02:26 .