Author Topic: Unlock / open door script needed please  (Read 340 times)

Legacy_DarthZchouR

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
Unlock / open door script needed please
« on: August 15, 2011, 12:41:15 am »


               Hello, all:
Looking for some help here please. I have a crypt area where a lever is pulled and a locked door is unlocked and opened for 300 seconds before it closes and locks again. The script I have does not fire:

void main()
{
    ExecuteScript("x2_plc_used_act", OBJECT_SELF);//<-- do lever animation
    object oPC = GetLastUsedBy();
    if (!GetIsPC(oPC)) return;
    object oTarget = GetObjectByTag(GetLocalString(OBJECT_SELF, "SCDoor_001"));
    if(!GetIsObjectValid(oTarget)) return;
    FloatingTextStringOnCreature(GetLocalString(OBJECT_SELF, "Something creaks in the distance"), oPC);
    ActionUnlockObject(oTarget);
    ActionOpenDoor(oTarget);
    float fDelay = GetLocalFloat(OBJECT_SELF, "300");
    DelayCommand(fDelay, ActionCloseDoor(oTarget));
    DelayCommand(fDelay, ActionLockObject(oTarget));
}

Any chance for some assistance / tweaking please? Thanks in advance!
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Unlock / open door script needed please
« Reply #1 on: August 15, 2011, 02:20:38 am »


               

DarthZchouR wrote...

Hello, all:
Looking for some help here please. I have a crypt area where a lever is pulled and a locked door is unlocked and opened for 300 seconds before it closes and locks again. The script I have does not fire:

void main()
{
    ExecuteScript("x2_plc_used_act", OBJECT_SELF);//<-- do lever animation
    object oPC = GetLastUsedBy();
    if (!GetIsPC(oPC)) return;
    object oTarget = GetObjectByTag(GetLocalString(OBJECT_SELF, "SCDoor_001"));
    if(!GetIsObjectValid(oTarget)) return;
    FloatingTextStringOnCreature(GetLocalString(OBJECT_SELF, "Something creaks in the distance"), oPC);
    ActionUnlockObject(oTarget);
    ActionOpenDoor(oTarget);
    float fDelay = GetLocalFloat(OBJECT_SELF, "300");
    DelayCommand(fDelay, ActionCloseDoor(oTarget));
    DelayCommand(fDelay, ActionLockObject(oTarget));
}

Any chance for some assistance / tweaking please? Thanks in advance!


It looks like you are useing GetLocalString when all you really want is the string that you are feeding it as the local strings lable.

So try. 
object oTarget = GetObjectByTag( "SCDoor_001"); // assuming that the tag for your door is  "SCDoor_001"
and

FloatingTextStringOnCreature( "Something creaks in the distance", oPC); // Assuming that is what you want to displayed and not the value of a local var named  "Something creaks in the distance"
               
               

               
            

Legacy_Melkior_King

  • Full Member
  • ***
  • Posts: 234
  • Karma: +0/-0
Unlock / open door script needed please
« Reply #2 on: August 15, 2011, 02:13:58 pm »


               I'd assume that the OP is trying to make this script as generic as possible so that it can be used on any lever to unlock any door without needing to edit the script.  If that's the case, then
object oTarget = GetObjectByTag(GetLocalString(OBJECT_SELF, "SCDoor_001"));
is the logical choice.  It will get the tag of the door from the local variable SCDoor_001 on the lever so that the script does not need to be changed.

If that's so then I'd assume the OP also meant to allow different text to be displayed for each door/lever combo and different time delays to be set before the door is closed and locked.

I don't think the "action" commands are appropriate here since they are intended to be used on mobile creatures which can then move to the object before performing the action.

Also, this script has a potential module-breaker if a player keeps on using the lever over and over.  More and more delayed commands will be queued which could cause unacceptable lag.  At the least, as time runs out the door will play the "close" animation over and over.

I think this will work:
void main()
{
    object oPC = GetLastUsedBy();
    ExecuteScript("x2_plc_used_act", OBJECT_SELF);//<-- do lever animation

    if (!GetIsPC(oPC) && !GetLocalInt(OBJECT_SELF,"NW_DO_ONCE")) return;
    SetLocalInt(OBJECT_SELF,"NW_DO_ONCE",TRUE);//<-- stops this script from executing again
    object oTarget = GetObjectByTag(GetLocalString(OBJECT_SELF, "SCDoor_001"));
    if(!GetIsObjectValid(oTarget)) return;
    FloatingTextStringOnCreature(GetLocalString(OBJECT_SELF, "SCDoor_002"), oPC);
    SetLocked(oTarget,FALSE);
    AssignCommand(oTarget, PlayAnimation(ANIMATION_DOOR_OPEN1);
    float fDelay = GetLocalFloat(OBJECT_SELF, "SCDoor_003");
    DelayCommand(fDelay, AssignCommand(oTarget, PlayAnimation(ANIMATION_DOOR_CLOSE));
    DelayCommand(fDelay, SetLocked(oTarget,TRUE));
    DelayCommand(fDelay, DeleteLocalInt(OBJECT_SELF,"NW_DO_ONCE"));//<-- allows this script to execute again after the delay
}
In the toolset, on the lever set the string variable SCDoor_001 equal to the tag of the door which the lever must open, the value of the string variable SCDoor_002 to the text to be displayed when the lever is operated and the value of the floating-point variable SCDoor_003 to 300.0.
eg:
string SCDoor_001 = SCDoor_001
(Yes, you can have a variable and an object tag exactly the same.  The game won't get confused, although you might.) ;-)
string SCDoor_002 = Something creaks in the distance
float SCDoor_003 = 300.0

I hope this does what you want.
               
               

               


                     Modifié par Melkior_King, 15 août 2011 - 01:41 .