Skip to content

Door won't open

I feel really silly asking this, but why won't the door in this script open? It's locked -
void main()
{

    object oPC = GetLastOpenedBy();
    if (!GetIsPC(oPC)) return;

    object oDoor = GetObjectByTag("STRENGTH_DOOR");

    if (GetAbilityScore(oPC, ABILITY_STRENGTH, 17))
    {
        SetLocked(oDoor, FALSE);
        ActionOpenDoor(oDoor);
    }
}

The test character has a strength score of 20, so I don't know what's happening...

Comments

  • TarotRedhandTarotRedhand Member Posts: 1,481
    edited June 2022
    Question - what calls this function? Where is it called from?

    TR
  • ZephiriusZephirius Member Posts: 419
    From the OnOpen handler of the door itself
  • TarotRedhandTarotRedhand Member Posts: 1,481
    Seeing as the door has yet to be opened, GetLastOpenedBy() won't work. Instead try this in your doors OnUsed event instead. Also, there's no need to call a function to find the door object that calls the function when there is OBJECT_SELF.
    void main()
    {
    
        object oPC = GetLastUsedBy();
    
        if(GetIsPC(oPC))
        {
            object oDoor = OBJECT_SELF;
    
            if (GetAbilityScore(oPC, ABILITY_STRENGTH, 17))
            {
                SetLocked(oDoor, FALSE);
                ActionOpenDoor(oDoor);
            }
        }
    }
    

    TR
  • ZephiriusZephirius Member Posts: 419
    edited June 2022
    I'm using a generic trigger now so GetEnteringObject()

    Doing it this way unlocks and opens the door, but anyone can bypass the strength test for some reason.
    Post edited by Zephirius on
  • ZephiriusZephirius Member Posts: 419
    Oh, there is no OnUsed() event. Only OnOpen(), On AreaTransistionClick(), OnFailToOpen() etc.
  • TarotRedhandTarotRedhand Member Posts: 1,481
    In that case try this script in the doors OnFailToOpen event
    void main()
    {
    
        object oPC = GetClickingObject();
    
        if(GetIsPC(oPC))
        {
            object oDoor = OBJECT_SELF;
    
            if (GetAbilityScore(oPC, ABILITY_STRENGTH) >= 17)
            {
                SetLocked(oDoor, FALSE);
                ActionOpenDoor(oDoor);
            }
        }
    }
    

    The probable reason why it is currently not working is because GetAbilityScore() only returns the ability score which means that it will always equate to TRUE (only a zero equates to FALSE). Also the third parameter of that function should be either TRUE or FALSE.

    TR
  • QuilistanQuilistan Member Posts: 186
    Just a thought but wouldn't this fit in the OnDamaged or OnPhysicalAttacked section? since the PC is trying to use force. You can set the door, so it doesn't get destroyed.
  • ZephiriusZephirius Member Posts: 419
    edited June 2022
    I changed the event to GetClickingObject()...
        object oPC = GetClickingObject();
        if (!GetIsPC(oPC)) return;
    
        object oDoor = OBJECT_SELF;
    
        int nStrength = ABILITY_STRENGTH;
        if (!GetIsPC(oPC)&&(nStrength >= 17))
        {
            SetLocked(oDoor, FALSE);
            ActionOpenDoor(oDoor);
        }
        else
        {
            AssignCommand(oPC, SetFacing(90.0));
            AssignCommand(oPC, ActionSpeakString("Only the strong may pass"));
        }
    }
    

    I'm trying anything with no luck. God, I can't code worth s**t! :#
  • ZephiriusZephirius Member Posts: 419
    Yeah, It's not working by changing the handler to OnPhysicallyAttacked()
  • ZephiriusZephirius Member Posts: 419
    In that case try this script in the doors OnFailToOpen event
    void main()
    {
    
        object oPC = GetClickingObject();
    
        if(GetIsPC(oPC))
        {
            object oDoor = OBJECT_SELF;
    
            if (GetAbilityScore(oPC, ABILITY_STRENGTH) >= 17)
            {
                SetLocked(oDoor, FALSE);
                ActionOpenDoor(oDoor);
            }
        }
    }
    

    The probable reason why it is currently not working is because GetAbilityScore() only returns the ability score which means that it will always equate to TRUE (only a zero equates to FALSE). Also the third parameter of that function should be either TRUE or FALSE.

    TR

    By changing the event to OnFailToOpen() -
    So do I use object oPC = GetLastOpenedBy()? If so I already tried it with no luck. :(
  • ProlericProleric Member Posts: 1,316
    edited June 2022

    The Lexicon for OnFailToOpen tells us that GetClickingObject() is the function to use.

    The strength test looks OK to me.

    You might want to give feedback in the chat log (or whatever) otherwise the player will never know that their strength opened the door - or that a stronger player could have opened it.
  • ZephiriusZephirius Member Posts: 419
    I don't think there is GetClickingObject on doors -
  • ZephiriusZephirius Member Posts: 419
    I've tried all of the different events: OnAreaTransistionClick, OnOpen, OnDamaged, OnPhysicallyAttacked - none are paying dividends...
  • ZephiriusZephirius Member Posts: 419
    It works calling the function GetLastUsedBy(). Only thing is I have to use a placeable to get the proper event handler being that Bioware forgot to build them into their doors...?
  • TarotRedhandTarotRedhand Member Posts: 1,481
    edited June 2022
    GetClickingObject() is a function. You use the OnFailToOpen event which is common to all doors. Think about it - the door is locked so without a key everyone is going to fail to open it on their first try.

    BTW did you ever bother to look at and grab the things I pointed to in the Tutorial List and Essential Downloads (especially if you are new to scripting) thread from a week or 2 ago?

    TR
  • ZephiriusZephirius Member Posts: 419
    GetClickingObject() is a function. You use the OnFailToOpen event which is common to all doors. Think about it - the door is locked so without a key everyone is going to fail to open it on their first try.

    BTW did you ever bother to look at and grab the things I pointed to in the Tutorial List and Essential Downloads (especially if you are new to scripting) thread from a week or 2 ago?

    TR

    I've downloaded them, that's all so far.

    I changed it to a generic trigger that starts a conversation -
    void main()
    {
    
        object oPC = GetPCSpeaker();
    
        if(!GetIsPC(oPC)) return;
        {
            object oDoor = GetObjectByTag("STRENGTH_DOOR");
    
            if (GetAbilityScore(oPC, ABILITY_STRENGTH) >= 17)
            {
                SetLocked(oDoor, FALSE);
                ActionOpenDoor(oDoor);
                SendMessageToPC(oPC, "With brute force you manage to break the door free...");
                GiveXPToCreature(oPC, 250);
                AssignCommand(oPC, ActionPlayAnimation(ANIMATION_LOOPING_GET_MID, 3.0));
                effect eDamage = EffectDamage(100, DAMAGE_TYPE_BLUDGEONING, DAMAGE_POWER_NORMAL);
                ApplyEffectToObject(DURATION_TYPE_INSTANT, eDamage, oDoor);
            }
            else
            {
                string sString = "Try as you might, the door won't budge!";
                AssignCommand(oPC, ActionSpeakString(sString));
            }
        }
    }
    
    
  • sunxresunxre Member Posts: 23
    sorry this isn't relevant to your post. but how do you post your code in that box, with the keycoloured words?
  • ZephiriusZephirius Member Posts: 419
    edited June 2022
    Use the drop down window right here by the comments section. It looks like a backwards P with a downward arrow next to it. Then select code - copy paste between the brackets.
  • TarotRedhandTarotRedhand Member Posts: 1,481
    I've downloaded them, that's all so far.

    Try reading them. It'll help you. Without doing so you are only hampering yourself by trying to run before you can walk.
    but how do you post your code in that box

    In the controls above the edit box that you type in, starting from 'B' go to the right. You'll see a number of dropdown box controls (upside down triangle). Click on the first one to open a menu with 3 choices including code. What you do is post your code in here, highlight it and select code from that menu.

    TR
  • sunxresunxre Member Posts: 23
    edited June 2022
    Zephirius wrote: »
    Use the drop down window right here by the comments section. It looks like a backwards P with a downward arrow next to it. Then select code - copy paste between the brackets.

    thanks. Edit: nvm. Fixed my op now
    Post edited by sunxre on
  • ZephiriusZephirius Member Posts: 419
    Try reading them. It'll help you. Without doing so you are only hampering yourself by trying to run before you can walk.

    Oh, I can honestly say that I excel at running - and what's this thing you call "walking" - never heard of it. o:)
  • MelkiorMelkior Member Posts: 205
    Just a quick note... I'd use PlayAnimation(ANIMATION_DOOR_OPEN1); instead of using an action. (Or OPEN2 if you want the door to open the other direction)
Sign In or Register to comment.