Author Topic: Random Traps on Ground  (Read 287 times)

Legacy_kalbaern

  • Hero Member
  • *****
  • Posts: 1531
  • Karma: +0/-0
Random Traps on Ground
« on: July 19, 2012, 10:27:11 pm »


               I've had random or rather semi random traps working for awhile now. They simply spawn in a trap with a random size and the location determined by the trigger and the nearest matching waypoint. However, it DCs to Spot them and their Disram/Recover DCs are fixed. As an example, any of the minor traps created seem to have a disarm DC of 22. Now, when I set them on a container or door via scripting, I can use the "SetTrapDetectDC" and "SetTrapDisarmDC" to adjust DC how I desire, but I can't seem to "grab" a trap spawned in from a trigger. I've tried setting the TAGs in the trap creation function to "TRAP", then using Get nearestObjectBy Tag, but it fails. I suspect it fails due to the trap not having existed already, therefore, their is no "nearest tagged object".

Any ideas?
               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Random Traps on Ground
« Reply #1 on: July 19, 2012, 10:46:23 pm »


               Perhaps when the trap spawns it can add itself to a list? Then when you need a reference for the trap you can take it from the list?
               
               

               
            

Legacy_Failed.Bard

  • Hero Member
  • *****
  • Posts: 1409
  • Karma: +0/-0
Random Traps on Ground
« Reply #2 on: July 19, 2012, 10:56:54 pm »


               I just tested it with this:

void main()
{
object oTrap = CreateTrapAtLocation (TRAP_BASE_TYPE_AVERAGE_ACID, GetLocation (GetObjectByTag ("TARGET")));
SetTrapDisarmDC (oTrap, 10);
SpeakString (IntToString (GetTrapDisarmDC (oTrap)));
}

It worked fine for me, at both 10 and 15.  What method are you using to create the trap?
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Random Traps on Ground
« Reply #3 on: July 19, 2012, 11:24:22 pm »


               Unfortunate but true, as there is no object through which to set the traps various attributes.
It seems to work as FB says though no object exists which the trap is on as the description states.
It's useful since you can vary the traps and the dc this way.
               
               

               


                     Modifié par ffbj, 19 juillet 2012 - 10:55 .
                     
                  


            

Legacy_kalbaern

  • Hero Member
  • *****
  • Posts: 1531
  • Karma: +0/-0
Random Traps on Ground
« Reply #4 on: July 20, 2012, 12:42:09 am »


               I'll play around, thanks guys. I'd gotten it working myself by just having a second script executed at the end of the one creating my random traps. The second one just looks for the TAG I'd set during creation and seems to work swell. I'll play around with FB's method next as it will help keep resources lower.
               
               

               
            

Legacy_kalbaern

  • Hero Member
  • *****
  • Posts: 1531
  • Karma: +0/-0
Random Traps on Ground
« Reply #5 on: July 20, 2012, 02:23:11 am »


               Here's what I ended up with, seems to work for me.

void main()
{
object oPC = GetEnteringObject();
if (!GetIsPC(oPC)) return;
if (GetLocalInt(OBJECT_SELF,"TRAPS")== 1) return;
SetLocalInt(OBJECT_SELF,"TRAPS",1);
object oTarget = GetNearestObjectByTag("WP_TRAP" + IntToString(d4()));
location lLocation = GetLocation(oTarget);
float fSize;
int nTrapType;
switch(Random(8))
{
case 0: fSize = 1.0f; break;
case 1: fSize = 1.25f; break;
case 2: fSize = 1.75f; break;
case 3: fSize = 1.00f; break;
case 4: fSize = 1.25f; break;
case 5: fSize = 1.50f; break;
case 6: fSize = 1.75f; break;
case 7: fSize = 2.0f; break;
}
switch(Random(6))
{
case 0: nTrapType = TRAP_BASE_TYPE_MINOR_ACID_SPLASH; break;
case 1: nTrapType = TRAP_BASE_TYPE_MINOR_FROST; break;
case 2: nTrapType = TRAP_BASE_TYPE_MINOR_HOLY; break;
case 3: nTrapType = TRAP_BASE_TYPE_MINOR_NEGATIVE; break;
case 4: nTrapType = TRAP_BASE_TYPE_MINOR_SPIKE; break;
case 5: nTrapType = TRAP_BASE_TYPE_MINOR_TANGLE; break;
}
object oTrap = CreateTrapAtLocation(nTrapType, lLocation, fSize,"", STANDARD_FACTION_HOSTILE, "", "");
SetTrapDetectDC(oTrap, 6+d6());
SetTrapDisarmDC(oTrap, 12+d12());
}


               
               

               


                     Modifié par kalbaern, 20 juillet 2012 - 01:23 .
                     
                  


            

Legacy_ShadowM

  • Hero Member
  • *****
  • Posts: 1373
  • Karma: +0/-0
Random Traps on Ground
« Reply #6 on: July 20, 2012, 02:38:26 am »


               You could also get the level of the PC and based off that scale the DCs and the traps '<img'>
               
               

               


                     Modifié par ShadowM, 20 juillet 2012 - 01:39 .
                     
                  


            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Random Traps on Ground
« Reply #7 on: July 21, 2012, 03:13:37 am »


               Yeah, that's a cool idea, which is the way I did it too.  Adding the level of the PC to the dc, just so it's not an auto-detect/auto-disarm.  I also did a switch for the trap creation but used a different strength trap and just added the size variation to that creation line, instead of a sperate case statement.  So the bigger traps are the most dangerous ones.
Specifically I use npc's to set traps, with met conditionals, causing the create trap script to fire.
Each trapper, usually scout will sometimes set a trap after a fight where the PC has fled the area, or the scout has simply lost contact with them.  Then the scout/npc will wander around dropping kits, on the ground.  Next I take the location of the kit to create the trap trigger and then destroy the kit.  In this way you can vary the number of traps that are set, and not use predetermined wp's as their set location.  So I might give 3-5 traps to a midlevel scout, for instance.