Server Totals
Mikona - (1)
Deglos - (1)
Elysia - (1)
Wilderness - (1)
Ferrell - (0)
M'Chek - (0)
Le'Or - (0)
Visimontium - (0)
Underdark - (0)
Total players: 4
Gallery

Links Menu

lock / unlock a chest / door via lever

Moderators: Nighthawk4, Dungeon Masters

lock / unlock a chest / door via lever

PostAuthor: JollyOrc » Wed Mar 17, 2004 11:10 am

Something similar came up during a conversation in the IRC.

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);
    }
}
User avatar
JollyOrc
QA Resource
 
Posts: 3900
Joined: Fri Jan 17, 2003 11:41 am
Location: Germany
Timezone: GMT+1

Return to NWN Scripting

Who is online

Registered users: Angel of Death, Bing [Bot], silverfields2