Author Topic: Traps damaging NPCs of the same faction  (Read 423 times)

Legacy_Terrorble

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
Traps damaging NPCs of the same faction
« on: April 22, 2013, 02:00:00 am »


               I am using Sir Elric's trap system from the vault.  Great in many ways, but when I spawn traps in an area with NPCs from a custom faction, they trigger the traps when they walk over them.  My intention is to have the traps friendly to the NPCs of those areas.  They are already hostile to the player, which is what I want.

Sir Elric's system spawns the traps from the area OnEnter essentially using CreateTrapAtLocation().  It uses STANDARD_FACTION_HOSTILE in the arguments.  I am guessing the problem has something to do with that.

How do I get around this?
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Traps damaging NPCs of the same faction
« Reply #1 on: April 22, 2013, 02:14:46 am »


               Make the traps infinite and use a custom script that checks for the custom faction on that area.  If the triggering occurs have the trap destroyed.

If these traps are supposed to be friendly to a PC in any circumstance, then the issue is much more complicated.
               
               

               
            

Legacy_Terrorble

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
Traps damaging NPCs of the same faction
« Reply #2 on: April 22, 2013, 04:57:41 am »


               Okay, so make the trap infinite, then you are saying in its impact script, have it compare the entering NPC's faction to say TRAP_SAFE_FACTION|string|... that I set on the area to see whether it activates or not?  Or by "custom script" did you mean something else?

To do this, I could add a check to the 50ish nw_t1_ or x2_t1_ scripts to see if they should activate, right?  (Sir Elric's system doesn't specify a custom impact script, so it uses the defaults)
               
               

               
            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Traps damaging NPCs of the same faction
« Reply #3 on: April 22, 2013, 05:20:02 am »


               

Terrorble wrote...

Okay, so make the trap infinite, then you are saying in its impact script, have it compare the entering NPC's faction to say TRAP_SAFE_FACTION|string|... that I set on the area to see whether it activates or not?  Or by "custom script" did you mean something else?

To do this, I could add a check to the 50ish nw_t1_ or x2_t1_ scripts to see if they should activate, right?  (Sir Elric's system doesn't specify a custom impact script, so it uses the defaults)


Here is an impact script that directly looks up the script for you.

void main()
{
object oEnter = GetEnteringObject();
object oFaction = GetLocalObject(GetArea(oEnter), "TrapFaction");
if(GetFirstFactionMember(oFaction) == GetFirstFactionMember(oEnter)) return;
ExecuteScript(Get2DAString("traps", "TrapScript", GetTrapBaseType(OBJECT_SELF)), OBJECT_SELF);
DestroyObject(OBJECT_SELF, 0.1);
}
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Traps damaging NPCs of the same faction
« Reply #4 on: April 23, 2013, 01:47:38 am »


               You could also just write an exception in the script that looks at a local int on the npc.  So No_TrapMe
set to 1 on any npc you want to not activate the trap.  In this way you could have some npc's that would trigger the trap, or maybe a friendly npc guide that shows the pc, (sets the local No_TrapMe) in a certain area for a certain time where the traps are, so they can be avoided, or perhaps recovered.  You can always make them unrecoverable, if you want.

Regarding traps:
http://nwvault.ign.c....Detail&id=3632
               
               

               


                     Modifié par ffbj, 23 avril 2013 - 12:52 .
                     
                  


            

Legacy_WhiZard

  • Hero Member
  • *****
  • Posts: 2149
  • Karma: +0/-0
Traps damaging NPCs of the same faction
« Reply #5 on: April 23, 2013, 02:24:18 am »


               Good point.  I was envisioning the worst (multiple custom factions with the possibility of members from one faction invading another factions area).  If you want the members resilient to all traps set in this manner you could also up the reputation between both them and the standard faction of the trap.  You will never trigger traps of a friendly faction, though you will trigger them for a neutral or hostile faction.
               
               

               
            

Legacy_Terrorble

  • Sr. Member
  • ****
  • Posts: 370
  • Karma: +0/-0
Traps damaging NPCs of the same faction
« Reply #6 on: April 24, 2013, 03:43:41 am »


               

WhiZard wrote...

void main()
{
object oEnter = GetEnteringObject();
object oFaction = GetLocalObject(GetArea(oEnter), "TrapFaction");
if(GetFirstFactionMember(oFaction) == GetFirstFactionMember(oEnter)) return;
ExecuteScript(Get2DAString("traps", "TrapScript", GetTrapBaseType(OBJECT_SELF)), OBJECT_SELF);
DestroyObject(OBJECT_SELF, 0.1);
}


This worked nicely for me.  Comparing first faction members of two objects and firing the trap script based on its 2da entry were both new ways to do things I previously didn't know - got my answer and learned a few things at the same time.
Thanks to both of you.