Author Topic: Attacking an Object deactivates Trap  (Read 607 times)

Legacy_Lethal_Bottle

  • Newbie
  • *
  • Posts: 28
  • Karma: +0/-0
Attacking an Object deactivates Trap
« on: September 24, 2010, 08:38:55 am »


               Hi everybody ^^ my first post~

This should be a simple one I think, but one that's useful for lots of scripting noobs too xD

How do I make a trap deactivate if an object is attacked? 
(i.e. I have a statue that when shot with an arrow, or anything, deactivates the trap in the room)

I thought this would be easy to make with other scripts I've found, but I can't get it to compile...

So far I have made this to go in the OnDamaged or OnPhysicalAttacked script slots:
  • void main()
  • {
  • object oPC = GetLastDamager();
  • if (!GetIsPC(oPC)) return;
  • object oTrapObject = GetObjectByTag("TRAP_TAG_HERE");
  • SetTrapActive(FALSE, oTrapObject);
  • }
The compile error is: (6): ERROR: DECLARATION DOES NOT MATCH PARAMETERS

Thanks for the help! (in advance)

I would also like it if when attacked, a visual effect of fire began on the statue. (The statue is the CEP one holding a bowl over it's head) I'd like to have some fire appear in that bowl, but obviously I don't want the fire re-triggering again and again if the PC starts shooting the statue for whatever reason ^^

- bottle
               
               

               


                     Modifié par Lethal_Bottle, 24 septembre 2010 - 07:41 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Attacking an Object deactivates Trap
« Reply #1 on: September 24, 2010, 09:28:13 am »


               Looks like you just have the parameters in this line reversed:

SetTrapActive(FALSE, oTrapObject);

Should be:

SetTrapActive(oTrapObject, FALSE);
               
               

               
            

Legacy_Lethal_Bottle

  • Newbie
  • *
  • Posts: 28
  • Karma: +0/-0
Attacking an Object deactivates Trap
« Reply #2 on: September 24, 2010, 11:09:03 am »


               Thank you so much, it works perfectly now!



If it's not to much trouble would you be able to help me with any of the following:



1. Making a 'chime' noise when the statue is struck and damaged,

2. Raising the detectable DC of the Trap or suddenly making it undetectable (so that the red squares disappear)



Again, thanks '<img'>
               
               

               
            

Legacy_Baragg

  • Sr. Member
  • ****
  • Posts: 496
  • Karma: +0/-0
Attacking an Object deactivates Trap
« Reply #3 on: September 24, 2010, 05:06:58 pm »


               You could use this in the placeables on damaged to play a gong sound:
PlaySound("as_cv_gongring1");

As to traps, setting the detect dc use this:

// Set the DC for detecting oTrapObject.
// - oTrapObject: a placeable, door or trigger
// - nDetectDC: must be between 0 and 250.
void SetTrapDetectDC(object oTrapObject, int nDetectDC)

As to makind it undetectable use:

// Sets whether or not the trapped object can be detected.
// - oTrapObject: a placeable, door or trigger
// - nDetectable: TRUE/FALSE
// Note: Setting a trapped object to not be detectable will
// not make the trap disappear if it has already been detected.
void SetTrapDetectable(object oTrapObject, int nDetectable=TRUE)

Just did a lot of fiddling with traps for my bud TheMythe, so these were freash in my head.':blush:'
               
               

               


                     Modifié par Baragg, 24 septembre 2010 - 04:07 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Attacking an Object deactivates Trap
« Reply #4 on: September 24, 2010, 08:26:58 pm »


               And if you still want to make a flame in the bowl appear only once you could do something like this. First put a waypoint at the exact spot you want the flame to appear and give it a unique tag.
Add this chunk of script to yours and plug in the tag you just gave your waypoint where it says "Tag of waypoint here". Also plug in the correct res ref of the flame/fire you want to use where it says "res ref of flame":


int iActiveFlame = GetLocalInt(OBJECT_SELF, "MY_FLAME");
if (iActiveFlame != TRUE)
        {
        object oWP = GetWaypointByTag("Tag of waypoint here");
        location lWP = GetLocation(oWP);
        CreateObject(OBJECT_TYPE_PLACEABLE, "res ref of flame", lWP);
        SetLocalInt(OBJECT_SELF, "MY_FLAME", TRUE);
        }


If this is a persistent world and you want other players to be able to do this then you will want to do this a bit different.
Hope it helps. Good luck.
               
               

               


                     Modifié par GhostOfGod, 24 septembre 2010 - 07:27 .
                     
                  


            

Legacy_Lethal_Bottle

  • Newbie
  • *
  • Posts: 28
  • Karma: +0/-0
Attacking an Object deactivates Trap
« Reply #5 on: September 26, 2010, 01:35:53 pm »


               Wow thanks for all the replies, all really great stuff! ^^ I implemented the Gong sound and the flame script. Although, I was unable to get a way point in the bowl (they don't seem to be able to lift off the ground, so I settled with a shaft of light appearing instead ^^



The only script I haven't put in is your second scripts Baragg, I was unsure where they should both go, and also reading the notes in the second one it says that this won't make an already detected trap become undectable, when in actual fact that's what I wanted ^^, when the PC enters the room they immediately spot the  (it has a spot DC of 0), then when they shoot the statue I'd like to make it so the red square disappears, is this possible? ^^



Thanks again for all your help!
               
               

               
            

Legacy_kalbaern

  • Hero Member
  • *****
  • Posts: 1531
  • Karma: +0/-0
Attacking an Object deactivates Trap
« Reply #6 on: September 26, 2010, 04:22:38 pm »


               

Lethal_Bottle wrote...

Wow thanks for all the replies, all really great stuff! ^^ I implemented the Gong sound and the flame script. Although, I was unable to get a way point in the bowl (they don't seem to be able to lift off the ground, so I settled with a shaft of light appearing instead ^^

The only script I haven't put in is your second scripts Baragg, I was unsure where they should both go, and also reading the notes in the second one it says that this won't make an already detected trap become undectable, when in actual fact that's what I wanted ^^, when the PC enters the room they immediately spot the (it has a spot DC of 0), then when they shoot the statue I'd like to make it so the red square disappears, is this possible? ^^

Thanks again for all your help!


Place your waypoint as close as possible to where you need it. Then right click it and use the "adjust location" option to manually move it. X and Y axis control the where on the map it rests. The Z axis controls the height. Play around and use the "apply" button to see which way your adjustments are moving the waypoint (or placeables). You'll get the hand of it in no time. '<img'>
               
               

               
            

Legacy_ffbj

  • Hero Member
  • *****
  • Posts: 1097
  • Karma: +0/-0
Attacking an Object deactivates Trap
« Reply #7 on: September 26, 2010, 05:01:18 pm »


               I don't think it can do what you are asking. To be clear let's restate that you want a previously detected trap to become undetectable after an object, in this case a statue has been damaged correct? So not deactivated as the title states. Though what deactivating the trap would do to the detectablility of a previously detected trap, I am uncertain. Maybe make it undetectable since its no longer activated, but lets assume that's not what you want, you want them to still be able to trigger the trap, but just not see it, right? Well let's assume that it is what you want. The short answer is no I believe due to the somewhat cryptic explantion of the function:

// Sets whether or not the trapped object can be detected.
// - oTrapObject: a placeable, door or trigger
// - nDetectable: TRUE/FALSE
// Note: Setting a trapped object to not be detectable will
// not make the trap disappear if it has already been detected.
void SetTrapDetectable(object oTrapObject, int nDetectable=TRUE)

I think they should have said it like this:
// Note: Setting a trapped object to (un)detectable will
// not make the trap trigger disappear if it has already been detected.

Anyway short answer appears to be no. A possible work around would be to blind the original person who detected the trap, with the idea that whoever detects can't see it anymore.
I did make an out-of-the-box detrapper on the vault that you might find some use for.


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

               


                     Modifié par ffbj, 26 septembre 2010 - 04:17 .
                     
                  


            

Legacy_Lethal_Bottle

  • Newbie
  • *
  • Posts: 28
  • Karma: +0/-0
Attacking an Object deactivates Trap
« Reply #8 on: September 27, 2010, 01:33:27 am »


               Thanks for the tip Kalbaern! The fire looks much better than the shaft of light '<img'>



Thanks for your help too ffbj, you misunderstood slightly what I was asking for, but I think you answered my question anyway ^^



What I wanted was for the PC to detect the trap. Shoot an arrow at a statue, triggering the gong sound and creating the fire in the statue bowl, and this then deactivating AND making the trap undetectable '<img'>



I've got all of it working except that once the trap is deactivated, it's still detectable. So in the end the PC has to walk over the red box, which just feels a little sloppy for me. I would like the red box to disappear, so that the PC knows for sure they've solved the puzzle and can walk over it! '<img'>



I thought you could just reset the Detection DC to something really high after it's been deactivated. But I am a total beginner at scripting, so I am unsure how to do that ^^, also I don't know if this will make the box suddenly disappear (and lastly I didn't know if it was possible or not), but you seem to have answered my question!



(Your de-trapping Hobbit looks great btw!)

               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Attacking an Object deactivates Trap
« Reply #9 on: September 27, 2010, 01:55:38 am »


               You will want to loop through all the PC and see if they have detected the trap or not.

// - oTrapObject: a placeable, door or trigger
// - oCreature
// * Returns TRUE if oCreature has detected oTrapObject
int GetTrapDetectedBy(object oTrapObject, object oCreature)

if they can see the trap.  The function above returns TRUE for them, You will want to set it to where they can not see the trap. 

// Set whether or not the creature oDetector has detected the trapped object oTrap.
// - oTrap: A trapped trigger, placeable or door object.
// - oDetector: This is the creature that the detected status of the trap is being adjusted for.
// - bDetected: A Boolean that sets whether the trapped object has been detected or not.
int SetTrapDetectedBy(object oTrap, object oDetector, int bDetected=TRUE)


               
               

               
            

Legacy_Lethal_Bottle

  • Newbie
  • *
  • Posts: 28
  • Karma: +0/-0
Attacking an Object deactivates Trap
« Reply #10 on: September 28, 2010, 12:32:55 am »


                Really thanks for your help, just as I am a complete novice at this really, can you help me integrate those scripts into my current one? '<img'>

Here's the script so far. I tried adding in the above lines but it wouldn't compile, so if someone could help me with that, I'd appreciate it lots!

  • // "trap1" = trap Tag
  • // "flame_waypoint = waypoint Tag
  • // "flamelarge001" = resref of placable
  • void main()
  • {
  • object oPC = GetLastDamager();
  • if (!GetIsPC(oPC)) return;
  • object oTrapObject = GetObjectByTag("trap1");
  • SetTrapActive(oTrapObject, FALSE);
  • int iActiveFlame = GetLocalInt(OBJECT_SELF, "MY_FLAME");
  • if (iActiveFlame != TRUE)
  •      {
  •      object oWP = GetWaypointByTag("flame_waypoint");
  •      location lWP = GetLocation(oWP);
  •      CreateObject(OBJECT_TYPE_PLACEABLE, "flamelarge001", lWP);
  •      SetLocalInt(OBJECT_SELF, "MY_FLAME", TRUE);
  •      }
  • PlaySound("as_cv_gongring1");
  • }
This script is placed into the OnDamaged script slot of the statue. ':lol:' thanks for your help everyone '<img'>
               
               

               
            

Legacy_Baragg

  • Sr. Member
  • ****
  • Posts: 496
  • Karma: +0/-0
Attacking an Object deactivates Trap
« Reply #11 on: September 28, 2010, 01:27:41 am »


               Here just added those lines and it compiles:




 // "trap1" = trap Tag

 // "flame_waypoint = waypoint Tag

 // "flamelarge001" = resref of placable

void main()

{
 object oPC = GetLastDamager();

 if (!GetIsPC(oPC)) return;

 object oTrapObject = GetObjectByTag("trap1");
 object oArea = GetArea(OBJECT_SELF);
 object oDetector;
 object oChecker = GetFirstObjectInArea(oArea);

 while(GetIsObjectValid(oChecker))
 {//determine which pc in this area detected the trap
    if(GetIsPC(oChecker))
    {
        if(GetTrapDetectedBy(oTrapObject, oChecker))
        {
            oDetector = oChecker;
        }

    }
    oChecker = GetNextObjectInArea(oArea);
 }

 SetTrapDetectedBy(oTrapObject, oDetector, FALSE);
 SetTrapActive(oTrapObject, FALSE);


 int iActiveFlame = GetLocalInt(OBJECT_SELF, "MY_FLAME");

 if (iActiveFlame != TRUE)

      {

      object oWP = GetWaypointByTag("flame_waypoint");

      location lWP = GetLocation(oWP);

      CreateObject(OBJECT_TYPE_PLACEABLE, "flamelarge001", lWP);

      SetLocalInt(OBJECT_SELF, "MY_FLAME", TRUE);

      }

 PlaySound("as_cv_gongring1");




}

               
               

               
            

Legacy_Lethal_Bottle

  • Newbie
  • *
  • Posts: 28
  • Karma: +0/-0
Attacking an Object deactivates Trap
« Reply #12 on: September 28, 2010, 04:07:21 pm »


                Thanks:lol:, it compiles, and almost works. However it makes the Trap undetected simply for a single heartbeat (6 seconds) and then it is re-detected again by the PC. Is there anyway to make it permanent?

Also, I want to apologise that the script he is now beyond my understanding completely, and so this thread has degenerated into a series of script requests! '<img'> haha

Thanks so much for all your help everyone! It IS really appreciated! ':lol:'
               
               

               
            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Attacking an Object deactivates Trap
« Reply #13 on: September 28, 2010, 04:36:03 pm »


               Somewhat of a solution would be to set the detect DC to a ridiculously high number. The highest you can go is 250. So right after these two lines:



SetTrapDetectedBy(oTrapObject, oDetector, FALSE);

SetTrapActive(oTrapObject, FALSE);



Add this:

SetTrapDetectDC(oTrapObject, 250);



However if you want it to be easily detectable again later you will need a script somewhere else to set the dc back to a lower amount.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Attacking an Object deactivates Trap
« Reply #14 on: September 28, 2010, 05:20:21 pm »


               No need to reset the DC.  Just set the trap undectable.



SetTrapDetectable(oTrapObject,FALSE);



Then reset it to dectable when you make it active again.