Author Topic: Surrender script?  (Read 1092 times)

Legacy_TrekSL

  • Newbie
  • *
  • Posts: 35
  • Karma: +0/-0
Surrender script?
« on: July 20, 2011, 06:10:15 pm »


               OK, I'm being a plonker - all I want to do during a fight is get the opposing npc to switch faction to the player again and 'yield' by starting a conversation after he's lost some health... Unfortunately, he fights to the death... what have I done wrong??
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Surrender script?
« Reply #1 on: July 20, 2011, 06:31:44 pm »


               Function - SurrenderToEnemies
               
               

               
            

Legacy_TrekSL

  • Newbie
  • *
  • Posts: 35
  • Karma: +0/-0
Surrender script?
« Reply #2 on: July 20, 2011, 07:38:34 pm »


               suspect I've gone blind. Spent an hour looking in the lexicon for something like that!
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Surrender script?
« Reply #3 on: July 20, 2011, 08:13:49 pm »


               There is also the SetIsTemporaryFriend function which can be set to either a limited amount of time or permanent. And I suspect, though I may be wrong, that with either of these functions it is possible to kill the NPC before they get to be friendly. So you might want to make sure their "immortal" box is checked.
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Surrender script?
« Reply #4 on: July 20, 2011, 08:50:24 pm »


               How does one get the functionality of SurrenderToEnemies but for less time than 3 minutes?
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Surrender script?
« Reply #5 on: July 20, 2011, 09:13:09 pm »


               

henesua wrote...

How does one get the functionality of SurrenderToEnemies but for less time than 3 minutes?



SetIsTemporaryFriend
               
               

               
            

Legacy_TSMDude

  • Hero Member
  • *****
  • Posts: 1515
  • Karma: +0/-0
Surrender script?
« Reply #6 on: July 20, 2011, 09:15:50 pm »


               You know i wrote this whole freaking script not knowing this was in here...I feel dunderheadish now....
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Surrender script?
« Reply #7 on: July 20, 2011, 09:28:59 pm »


               I have not had much success with SetIsTemporaryFriend ending combat. I'll try some more experiments.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Surrender script?
« Reply #8 on: July 20, 2011, 09:49:33 pm »


               

henesua wrote...

I have not had much success with SetIsTemporaryFriend ending combat. I'll try some more experiments.


I dont think it stops combat.   If you do not Clear the actions of the Characters involved,  They will still wack each other.   In that case the rep wil most likely get adjusted right back to hostile.  That would be my guess anyway.  
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Surrender script?
« Reply #9 on: July 20, 2011, 10:08:32 pm »


               

henesua wrote...

I have not had much success with SetIsTemporaryFriend ending combat. I'll try some more experiments.


You will need to do a ClearAllActions(TRUE);, for both the player and the NPC, at the same time. As well as any of the players henchmen etc. It's not nearly as simple as using the function Lightfoot suggested. But if you need a specific amount of time this might be the way to go.
               
               

               


                     Modifié par GhostOfGod, 20 juillet 2011 - 09:10 .
                     
                  


            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Surrender script?
« Reply #10 on: July 21, 2011, 01:27:34 am »


               Thanks. I'll fiddle more with this. I had only been clearing all actions for the NPC. Perhaps that was my problem. It would be good to figure this out and create a custom function that I can use to replace the surrender function.
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Surrender script?
« Reply #11 on: July 27, 2011, 06:46:27 am »


               FYI - this seems to work with one enemy present


SetCommandable(TRUE, oPC);
SetCommandable(TRUE, oEnemy);
AssignCommand(oPC, ClearAllActions(TRUE));
SetIsTemporaryFriend(oEnemy, oPC, TRUE, fTime);
AssignCommand(oEnemy, ClearAllActions(TRUE));
SetIsTemporaryFriend(oPC, oEnemy, TRUE, fTime);


But the full function is failing, and I can't find the error.

http://pastebin.com/Dxx3V5ST
               
               

               


                     Modifié par henesua, 27 juillet 2011 - 05:53 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Surrender script?
« Reply #12 on: July 27, 2011, 11:07:11 am »


               This is what I came up with. Tested and seems to be working fine. There might be a better way to do it though. Hopefully it can help you.


void StopFactionCombat(object oPC, object oEnemy)
{
    int iNth = 1;
    object oCombatant = GetNearestCreature(CREATURE_TYPE_IS_ALIVE, TRUE, oPC, iNth);
    object oMember;
    while (GetIsObjectValid(oCombatant))
    {
        if (GetFactionEqual(oEnemy, oCombatant))
        {
            oMember = GetFirstFactionMember(oPC, FALSE);
            while (GetIsObjectValid(oMember))
            {
                if (GetCurrentAction(oMember) == ACTION_ATTACKOBJECT)
                AssignCommand(oMember, ClearAllActions(TRUE));
                if (GetCurrentAction(oCombatant) == ACTION_ATTACKOBJECT)
                AssignCommand(oCombatant, ClearAllActions(TRUE));
                SetIsTemporaryFriend(oMember, oCombatant, FALSE);
                oMember = GetNextFactionMember(oPC, FALSE);
            }
        }
        iNth++;
        oCombatant = GetNearestCreature(CREATURE_TYPE_IS_ALIVE, TRUE, oPC, iNth);
    }
}
void main()
{
    object oPC = GetLastDamager(OBJECT_SELF);
    object oEnemy = OBJECT_SELF;
    if (GetCurrentHitPoints(OBJECT_SELF) < 4)
    StopFactionCombat(oPC, oEnemy);
}


P.S. Using the GetFirst/NextFactionMember functions works fine for single player as well since associates are considered faction members.
               
               

               


                     Modifié par GhostOfGod, 27 juillet 2011 - 10:09 .
                     
                  


            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Surrender script?
« Reply #13 on: July 27, 2011, 05:22:25 pm »


               Thanks GoG.

You did not use GetNearestEnemy as I did. Rather you are simply going through all nearby creatures. Is there something wrong with the GetNearestEnemy function?

Curious as to your thinking here.
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Surrender script?
« Reply #14 on: July 27, 2011, 06:42:43 pm »


               Honestly, I just didn't know there was a "GetNearestEnemy" function. I've never used it. I just tried to look for it in nw_i0_generic and can't find it though it is on the list of functions.