not really tested thoroughly yet..

Code: Select all
//::///////////////////////////////////////////////
//:: Name ply_toggle_chest
//:: FileName ply_toggle_chest.nss
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/* Locks / unlocks the chest with the tag that is the
same as the levers tag, but without the initial "LEV_"
flips the switch accordingly, as well as informing
the PC of what happened.
Might also work for doors.
*/
//:://////////////////////////////////////////////
//:: Created By: JollyOrc
//:: Created On: March 17th, 2004
//:://////////////////////////////////////////////
void FlipSwitch(object oSwitch)
{
if (GetLocalInt(oSwitch, "status"))
{
AssignCommand(oSwitch, PlayAnimation(ANIMATION_PLACEABLE_DEACTIVATE));
SetLocalInt(oSwitch, "status", 0);
}
else
{
AssignCommand(oSwitch, PlayAnimation(ANIMATION_PLACEABLE_ACTIVATE));
SetLocalInt(oSwitch, "status", 1);
}
}
void ToggleChest(object oChest, object oPC)
{
if (GetLocked(oChest))
{
SetLocked(oChest, FALSE);
FloatingTextStringOnCreature("open.",oPC);
}
else
{
SetLocked(oChest, TRUE);
FloatingTextStringOnCreature("closed.",oPC);
}
}
void main()
{
string sTempTag = GetTag(OBJECT_SELF);
int iLength = GetStringLength(sTempTag);
int iSubLength = iLength - GetStringLength("LEV_");
string ContTag = GetStringRight (sTempTag, iSubLength);
object oCont = GetObjectByTag(ContTag);
object oPC = GetLastUsedBy();
if (GetIsObjectValid(oCont))
{
ToggleChest(oCont, oPC);
FlipSwitch(OBJECT_SELF);
}
}