Author Topic: Triggers, Manual Traps, and ActionSpeakString  (Read 657 times)

Legacy_treetrunker

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
Triggers, Manual Traps, and ActionSpeakString
« on: July 29, 2010, 10:12:56 pm »


                So, I've been having trouble with a series of scripts of mine. Basically, I have set a trigger to pick a random number from 1 to 4, which should change other triggers to do different things. I have 4 manual traps set up. If their number is called by the initial trigger, then the manual trap opens the door out of the area. If not, then it casts a spell at the player.

Here is my code:

OnEnter Script for trigger CHEST_CODE:  (The first trigger of the 5)
void main()
{
 SetLocalInt(GetObjectByTag("CHEST_CODE"), "nChestCode",d4());
}

The other 4 triggers are set up around rune plates, which the player is supposed to step on. Their code is like this.
void main()

object oPC = GetFirstPC(); 
if (GetLocalInt(GetObjectByTag("CHEST_CODE"), "nChestCode") == 1) 
{  
SetLocked(GetObjectByTag("CRYPT_DOOR"),FALSE);  
AssignCommand(GetObjectByTag("PLATE01"),ActionSpeakString("You hear the sound of turning gears indicating that the door to the crypt has unlocked.")); }
 else {  
AssignCommand(GetObjectByTag("PLATE01"),ActionCastSpellAtObject(115, oPC,0,TRUE,1,1,TRUE));
 }
}

This is the script for trigger PLATETRAP01, and the scripts for the other triggers are the same, they just use the numbers 2, 3, or 4 in their conditional.

The random number is working fine, and the correct trigger always unlocks the door, but the SpeakString never fires, and the trap never fires for any of the other plates.
               
               

               


                     Modifié par treetrunker, 29 juillet 2010 - 09:15 .
                     
                  


            

Legacy_treetrunker

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
Triggers, Manual Traps, and ActionSpeakString
« Reply #1 on: July 29, 2010, 10:14:43 pm »


               Still attempting to format this correctly....

And if more info is needed to help solve this problem, just ask.
               
               

               


                     Modifié par treetrunker, 29 juillet 2010 - 09:31 .
                     
                  


            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Triggers, Manual Traps, and ActionSpeakString
« Reply #2 on: July 29, 2010, 10:36:24 pm »


               if the Lock/Unlock part of the script works, then the immediate reason that springs to mind for the speak and spell fire to be failing are the following.



1. If you have thousands of placeables, or hundreds of areas, action queues globally can be ....tiresome, in which case spells being fired, take a minute or two to kick in. However, this shouldnt affect SpeakString functions in any case.

2. Ensure the objects are valid. I suspect perhaps the tag is incorrect, or perhaps there is a querk with those functions that the objects need to be instantiated (create an instance of them first.)



Try





object oPlate = GetObjectByTag("PLATE01");
if(oPlate == OBJECT_INVALID)
   {
     AssignCommand(GetModule(),"THE PLATE COULD NOT BE FOUND");
     return;
   }
AssignCommand(oPlate,ActionSpeakString("You hear the sound of turning gears indicating that the door to the crypt has unlocked.")); }



Its generally good practice to ensure that the object exists, before doing things with it.



Also, make sure

1. The tag is correct, try to keep these in lowercase or all in the same case throughout your module, it helps when it comes to scripting if you dont have to switch from one case to another.

2. The object is not static - Static objects, although being capable of speaking, will not retain their proper name when spoken, as for actions like spell casting, I dont know if they can do that.

3. Ensure the object is not being destroyed, or is otherwise busy doing something else.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Triggers, Manual Traps, and ActionSpeakString
« Reply #3 on: July 29, 2010, 10:52:13 pm »


               A few Questions?

Are all of the triggers in the same area?

Am I correct that the tags of the triggers are:
CHEST_CODE
PLATE01
PLATE02
PLATE03
PLATE04

Or are they the Tags of the Rune Plates?

If they are the Triggers:  I dont think the triggers can cast spells. One of the reasons all standard traps have an Inpact script.  Also Since the trigger is not seen, Even if it speaks a string the PC will not hear it unless they can see the speaker.  

If the Tags belong to the Rune Plates: If they are static, they can't cast the spell. (or I at least don't think they can.) 

Are the rune Plates Placeables?
               
               

               


                     Modifié par Lightfoot8, 30 juillet 2010 - 03:55 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Triggers, Manual Traps, and ActionSpeakString
« Reply #4 on: July 30, 2010, 04:59:34 am »


               This here will work if you have a placeable with the same tag as the trigger close by.  The placeable will be used to cast the spells and speak.  Note they should not be static.

#include "x0_i0_projtrap"
void main()
{
object oPC = GetEnteringObject();
string sTag = GetTag(OBJECT_SELF);
int nPlateNumber = StringToInt(GetStringRight(sTag,2));
object oArea = GetArea(OBJECT_SELF);
if ( sTag == "CHEST_CODE" ) SetLocalInt(oArea, "nChestCode",d4());
else if (GetStringLeft(sTag,5)== "PLATE")
{
if (GetLocalInt(oArea, "nChestCode") == nPlateNumber)
{
SetLocked(GetObjectByTag("CRYPT_DOOR"),FALSE);
AssignCommand(GetProjectileTrapOrigin(oPC),SpeakString("You hear the sound of turning gears indicating that the door to the crypt has unlocked."));
}
else
{
switch (nPlateNumber)
{
case 1:
TriggerProjectileTrap(SPELL_MELFS_ACID_ARROW, oPC, 9);
break;
case 2:
TriggerProjectileTrap(SPELL_FLAME_ARROW, oPC, 5);
break;
case 3:
TriggerProjectileTrap(SPELL_ELECTRIC_JOLT, oPC, 1);
break;
case 4:
TriggerProjectileTrap(SPELL_MAGIC_MISSILE, oPC, 1);
break;
}
[/list]}
[/list]}
[/list]}

Edit: I forgot to say.  You place the script on all Five placeables.
               
               

               


                     Modifié par Lightfoot8, 30 juillet 2010 - 04:05 .
                     
                  


            

Legacy_treetrunker

  • Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
Triggers, Manual Traps, and ActionSpeakString
« Reply #5 on: July 30, 2010, 08:20:09 am »


               Thanks for your help guys. I got it to work. My script was actually fine, I had just screwed up my tags, and the tags I was assigning to the plates were actually on the triggers. I got that sorted out and now it works perfectly.

Thanks again!