Author Topic: Inn Door - Ivodon's Persistent Inn Door Check  (Read 432 times)

Legacy_The Mad Poet

  • Hero Member
  • *****
  • Posts: 715
  • Karma: +0/-0
Inn Door - Ivodon's Persistent Inn Door Check
« on: July 14, 2015, 05:24:11 pm »


               

I've fixed this before with someone else giving me a hand, but unfortunately I lost the bloody code change @_@


 


Here is the code.



#include "ipi_constants"
#include "ipi_defaults"
#include "ipi_datemath_inc"
#include "pf_facade"

void ActionAutoCloseAndLock(object theObject)
{
    if (GetIsOpen(OBJECT_SELF))
        { ActionCloseDoor(OBJECT_SELF); }
    ActionDoCommand (SetLocked (OBJECT_SELF, TRUE));
}

void main()
{
    string sInnTag = GetStringLeft(GetTag(OBJECT_SELF),
        GetStringLength(sPREFIX) + 2);
    object myInn = GetObjectByTag(sInnTag);
    // Complain if we can't find our inn object
    if (myInn == OBJECT_INVALID)
    {
        string msg = "ERROR: Door with tag "+ GetTag(OBJECT_SELF) +
            " can't find inn placeable with tag "+ sInnTag;
        SpeakString(msg);
        WriteTimestampedLogEntry(msg);
        return;
    }
    object thisPC = GetClickingObject();
    string thisPCKey = GetName(thisPC) + GetPCPlayerName(thisPC);
    string sRoomNumber = GetStringRight(GetTag(OBJECT_SELF),3);
    string sTenantVar = "Rm" + sRoomNumber + "Tenant";
    string ownerKey = GetPFCampaignString(sCampaignName, sTenantVar, myInn);
    // DEBUG
    //SpeakString("Your Key = "+ thisPCKey +", OwnerKey = "+ownerKey);
    // Expire this agreement if necessary
    string sExpireVar = "Rm" + sRoomNumber + "Expire";
    string expireDateStr = GetPFCampaignString(sCampaignName, sExpireVar, myInn);
    int daysLeft = 0;
    if (expireDateStr != "")
        daysLeft = DateStrCmp(NewDateString(), expireDateStr);
    if (daysLeft < 0)
    {
        string msg = "Expiring contract for "+ GetName(thisPC) +
            " on room "+ sRoomNumber;
        WriteTimestampedLogEntry(msg);
        DeletePFCampaignVariable(sCampaignName, sTenantVar, myInn);
        DeletePFCampaignVariable(sCampaignName, sExpireVar, myInn);
    }
    else if (thisPCKey == ownerKey)
    {
        int roomNum = StringToInt(sRoomNumber);
        string myName =  "Room "+ IntToString(roomNum);
        if (GetWillSavingThrow(OBJECT_SELF) == USE_ROOM_NAME)
            myName = GetName(OBJECT_SELF);
        string msg = "*" + myName +" opens for "+ GetName(thisPC) +"*";
        ActionOpenDoor(OBJECT_SELF);
        FloatingTextStringOnCreature(msg, thisPC);
        DelayCommand(DOOR_DELAY, ActionAutoCloseAndLock(OBJECT_SELF));
    }
}

Here is the problem: These doors lock for anyone except the person who is assigned to the inn room door. They use it and it pops right open for them. I use persistent location for players. Sometimes players will do something silly and nonsensical like logging out in their inn room. Madness, right? Well if they have their contract expire while they are offline and log back in... they're stuck behind the door and I have to port them out.


 


I'd hate to have to put a placeable 'escape' lever in each room. That's just immersion breaking as can be. I know it can be done because I've had the fix given to me before. I believe it had something to do with collecting the angles behind the door (from like 91 - 269 I think) and checking to see if the player is in that angle and then opening the door. Much as I've messed with it to try and figure it out myself all I've managed to do is mess it up more. The innkeepers are really mad at me for making all the inns free across the city. They've threatened to sue.


 


Anyone come across the same, or at least could help me figure out how to do this?



               
               

               
            

Legacy_meaglyn

  • Hero Member
  • *****
  • Posts: 1451
  • Karma: +0/-0
Inn Door - Ivodon's Persistent Inn Door Check
« Reply #1 on: July 14, 2015, 05:50:29 pm »


               

Yeah, I crossed that bridge. I used this Inn system as a base, it's now heavily mogrified. The way I solved this issue fit in with my rest system.  Each Inn room has a trigger in it saying it's a valid place to rest (and that it's a Inn so you get full rest and don't get penalized fo not having a bedroll etc).  So in the fail to open handler I check if the PC is in such a rest trigger and allow the door to open.  That  way a PC can always open the door from the inside.


 


I didn't like the unlock switches either '<img'>


               
               

               
            

Legacy_The Mad Poet

  • Hero Member
  • *****
  • Posts: 715
  • Karma: +0/-0
Inn Door - Ivodon's Persistent Inn Door Check
« Reply #2 on: July 14, 2015, 05:53:27 pm »


               

Hunh... interesting approach. I pretty much have the same setup. I'd have to redraw all my rest triggers because they aren't room encompassing, but that very well might work.



               
               

               
            

Legacy_henesua

  • Hero Member
  • *****
  • Posts: 6519
  • Karma: +0/-0
Inn Door - Ivodon's Persistent Inn Door Check
« Reply #3 on: July 14, 2015, 06:09:04 pm »


               

+1 for meaglyn's solution to this problem.



               
               

               
            

Legacy_Thayan

  • Sr. Member
  • ****
  • Posts: 435
  • Karma: +0/-0
Inn Door - Ivodon's Persistent Inn Door Check
« Reply #4 on: July 14, 2015, 06:47:32 pm »


               

I assume I'm 'the someone else giving you a hand'? If so, here's the e-mail reply with my solution to this which I sent you when you asked a few years ago. Don't think I heard back from you so I'm not sure if you tried it or ir worked for you or not though -


 



The key is to make sure that all the inn doors are painted down in the toolset facing out of the room (so the arrow is facing away from the interior of the room). Then modify the mid-lower section of the ipi_door_check script to look something like this by adding the chunk of code I added at the top of this snippet and then put || iGetIsInside in the 'else if' statement below it:

 

    //Thayan 2/12/08 - Check if the PC is inside the room trying to get out (within a 90 degree facing angle)

    int iGetIsInside = FALSE;

    float fDoorFacing = GetFacing(OBJECT_SELF);

    float fPCFacing = GetFacing(thisPC);

    if (fDoorFacing == 270.0 && (fPCFacing >= 45.0 && fPCFacing <= 135.0)) iGetIsInside = TRUE;

    else if (fDoorFacing == 0.0 && (fPCFacing >= 135.0 && fPCFacing <= 225.0)) iGetIsInside = TRUE;

    else if (fDoorFacing == 90.0 && (fPCFacing >= 225.0 && fPCFacing <= 315.0)) iGetIsInside = TRUE;

    else if (fDoorFacing == 180.0 && ((fPCFacing >= 0.0 && fPCFacing <= 45.0) || fPCFacing >= 315.0)) iGetIsInside = TRUE;

    //SendMessageToPC(thisPC, "You're facing: "+FloatToString(GetFacing(thisPC), 3, 3)+" /Door facing: "+FloatToString(GetFacing(OBJECT_SELF), 3, 3));

 

    if (expireDateStr != "")

        daysLeft = DateStrCmp(NewDateString(), expireDateStr);

    if (daysLeft < 0)

    {

        string msg = "Expiring contract for "+ GetName(thisPC) +

            " on room "+ sRoomNumber;

        //WriteTimestampedLogEntry(msg);

        NBDE_DeleteCampaignString(sCampaignName, sTenantVar, myInn);

        NBDE_DeleteCampaignString(sCampaignName, sExpireVar, myInn);

        NBDE_FlushCampaignDatabase(sCampaignName);

    }

    else if (thisPCKey == ownerKey || iGetIsInside) //Modified by Thayan

    {

        int roomNum = StringToInt(sRoomNumber);

        string myName =  "Room "+ IntToString(roomNum);

        if (GetWillSavingThrow(OBJECT_SELF) == USE_ROOM_NAME)

            myName = GetName(OBJECT_SELF);

        string msg = "*" + myName +" opens for "+ GetName(thisPC) +"*";

        ActionOpenDoor(OBJECT_SELF);

        FloatingTextStringOnCreature(msg, thisPC);

        //DelayCommand(DOOR_DELAY, ActionAutoCloseAndLock(OBJECT_SELF)); //Removed by Thayan

    }

 

 

Hope this helps.

-Thayan



 



               
               

               
            

Legacy_The Mad Poet

  • Hero Member
  • *****
  • Posts: 715
  • Karma: +0/-0
Inn Door - Ivodon's Persistent Inn Door Check
« Reply #5 on: July 14, 2015, 06:52:48 pm »


               

You're a chap, Thayan. I'm glad you are so much better than I am at record keeping. I honestly forgot who it was that gave me a hand.


 


If I didn't reply I apologize. Was a couple years ago so TBH so I can't remember.



               
               

               
            

Legacy_Thayan

  • Sr. Member
  • ****
  • Posts: 435
  • Karma: +0/-0
Inn Door - Ivodon's Persistent Inn Door Check
« Reply #6 on: July 14, 2015, 07:08:41 pm »


               

No worries. Just wasn't sure if that was what you were looking to get. That solution has worked well for my PW, but mileage may vary.



               
               

               
            

Legacy_The Mad Poet

  • Hero Member
  • *****
  • Posts: 715
  • Karma: +0/-0
Inn Door - Ivodon's Persistent Inn Door Check
« Reply #7 on: July 14, 2015, 07:28:48 pm »


               

Originally I used it in what is now the predecessor to Avernostra. The experience of working on that module helped a lot. Also taught me to keep backups of my backups backups '<img'>