Aller au contenu

Photo

Using Levers to Open Doors


  • Veuillez vous connecter pour répondre
2 réponses à ce sujet

#1
Lucrane

Lucrane
  • Members
  • 163 messages
Hey All,

As the title suggest, I'm trying to figure out how to have a lever open a door when its used. The problems I am running into is the lever placeable I have in the area, does get the hand icon when moused over but when clicked does nothing. On top of that the door that is supposed to be opened by the lever just opens on its own as you enter the area. Anyone know the steps on how to go about making a lever open a door and actually having the lever animate? Thanks again.

~Lucrane

#2
sea-

sea-
  • Members
  • 264 messages
You need to make a custom placeable lever as well as your own script to get this to work. The script on the placeable should look something like this:

#include "placeable_h"

void main()
{
    //standard variables
    event ev          = GetCurrentEvent();
    int nEventType    = GetEventType(ev);
    int bEventHandled = FALSE;
    object oThis      = OBJECT_SELF;
    object oPC        = GetHero();

    switch (nEventType)
    {
        case EVENT_TYPE_USE:
        {
            //collect door and lever            
            object oDoor = UT_GetNearestObjectByTag(OBJECT_SELF, "door_name");
            object oLever = UT_GetNearestObjectByTag(OBJECT_SELF, "door_lever");
            
            //sends open command to the door
            SetPlaceableState(oDoor, PLC_STATE_DOOR_OPEN);

            //sets lever to non-interactive
            SetObjectInteractive(oLever, FALSE);

            break;
        }
    }

    if (!bEventHandled)
    {
        HandleEvent(ev, RESOURCE_SCRIPT_PLACEABLE_CORE);
    }
}

To make the door swing open and closed, instead of simply opening once, you need to keep track of a variable on the placeable and set it to something like 0 or 1, where 0 = closed and 1 = open, changing the placeable state accordingly.

Modifié par sea-, 02 août 2012 - 11:08 .


#3
Lucrane

Lucrane
  • Members
  • 163 messages
Worked like a charm! Thanks :D

-Lucrane