Aller au contenu

Photo

Persistent Inn System - W.I.P.


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

#1
henesua

henesua
  • Members
  • 3 858 messages

This thread shows my progress as I develop a set of scripts for persistent rental housing (inns/hotels etc...). I saw a few nice systems on the vault, but they weren't exactly what I wanted. To show my work in progress, I have pasted all of the scripts which are part of this project to pastebin. For the most recent code, you'll need to see the most recent posts. I want to track the evolution of the scripts, and thus leave the older posts unedited. (EDIT I broke this rule to activate syntax highlighting)

 

[edit - I've been working on this again and am nearing completion of all the needed features.

the updated code is v2_inc_housing]

Description of the parts:
- Persistency is set up to use NBDE(improved bioware database). But could likely be very quickly adjusted  to use any DB system. I have but 2 or three database calls.
- "aa_rentroom" is the name of the conversation file. It is reusable for any inn, and has dynamic text at every owner's node and every player reponse. Custom tokens are used for everything the player reads.
The conversation "aa_rentroom" is defined by three nodes as follows:

  • (1) show the room types available - up to 5 as defined by the builder. player selects one of the room types
  • (2) show up to 3 duration options  (1 night, 1 week, 1 month) for the room of the type selected by the player along with the cost associated with each duration. Display important info about the room such as how many occupants can fit, cost, services available (does it have a locked door? bath? continental breakfast? laundry?) etc....
  • (3) display for the pc what room they got, and any of the specifics the innkeeper needs to explain (such as check out time, where the room is, how to request services if any, house rules etc...) And if one of the room's services is "private" then give to the player a room key and set it up to work with their room door.

- The most important script in the conversation file is "aa_rentroom_tok". This script is attached to every one of the "owners's"  nodes in "Text appears when"
- Every "text appears when" slot for the player's responses has something like "aa_ck_token100" and an "action taken" script like "aa_conv_branch1". Each node has at most five of these kinds of responses. So there are 5 of each of these files as follows:
aa_ck_token100,aa_ck_token101, aa_ck_token102, aa_ck_token103,  aa_ck_token104, aa_conv_branch1, aa_conv_branch2,  aa_conv_branch3  aa_conv_branch4  aa_conv_branch5

-The script include for the system is "aa_inc_housing" and is called thus far by "aa_rentroom_tok". This contains all the working parts. I have not included my own master which has the utility scripts and the NBDE database system.
- I need one more script that handles garbage collection, and to place it in both the onconversation abort and finish slots. This will be a simple thing that deletes all temporary  local variables set on both the PC and NPC dyuring the course of the conversation. I have not yet written it.


Objects required: 
Perhaps the biggest drawback for the builder are the number of data objects, and local variables that this system requires. Its complicated enough that I may have to make some palette items (waypoints so that they can double as map points) prepopulated with local variables, and documentation of how the system works in the "comments" section. I hate to create items in teh palette and add objects to the module, but without these this system is hard to understand.

These objects include:

  • one or more inn keepers with a conversation that is either composed entirely of "aa_rentroom" or launches that conversation on the innkeeper. Each innkeeper needs a local string that contains the tag of the "inn" waypoint. See below. I think it is better to only have one innkeeper, and to only allow one PC at a time to converse with the innkeeper. But perhaps someone can improve the system to elimnate the problem of one pc quickly renting a room that another PC was just about to rent. (This would break the conversation if it occurred).
  • an "inn" waypoint with a tag unique to the inn. The inn is loaded with a ton of local variables. See the INN struct in "aa_inc_housing"
  • Each room is created by placing a waypoint tagged with the inntag + the number of the room. A number of local vars further define the room see the function InitializeRooms() in aa_inc_housing for more information.
  • A generic "room key" that is retagged, renamed and redescribed (SetDescription) by this system to work with the specific room door.

Keys:
A subsystem that I use alongside this but which is not strictly necessary is my key system (not to be confused with the old public transit system in Alameda County, CA). I have tag scripted keys that can unlock/lock doors that have a matching identifier. This enables all doors in an inn to be accessed by the innkeeper's master key, and yet room keys can open specific room doors. Its a very simple system that anyone can code. One more caveat - I rewrote my tag script activation so that they don't read the whole tag but only a subtag within the tag. GetTagPrefix() is used in that script. so a key could be tagged with key_innroom1 which would launch the do_key script instead of do_key_innroom1. And it functions as a key that looks for a local string on a door of "key_innroom1"

* * *

Issues I've already seen that need to be changed so that the code makes more sense and functions more naturally:

  • In retrospect I wish I had named those token scripts 101-105, instead of 100-104 and may change that later.
  • I should increase all of my indexes by 1, because my roomtype index starts at 0 instead of 1. That was a mistake, and creates a problem with the scripts.
  • Also my use of the Struct is kludgey and clumsy, and can be improved, but I'm not sure how to stream line it yet. Perhaps by making a sub struct for roomtype. Can you put a struct inside of a struct?

* * *

I know this system is no big deal for the real programmers out there, but for the lesser skilled amongst us such as myself I think its good to look at each other's work, share ideas, and thus improve. Thats why I am posting this in progress. Feedback is welcome. Especially that which pushes me to structure my code more effectively and efficiently.  


Modifié par henesua, 27 avril 2014 - 10:01 .


#2
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
I am not sure how inportant resource count is to you, If it is something you are looking at keeping at a as low as possiable, you could use just one script for the PC responce scripts instead of 5 of them. I if you need more information on how just let me know.

#3
henesua

henesua
  • Members
  • 3 858 messages
Yes, how do I use just one pc response script?

#4
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages

henesua wrote...

Yes, how do I use just one pc response script?


*cringe*   Guess I stated that a little off.   It is the TextApearsWhen scripts we can reduce for the starting conditions on the PC responces.  unfortunately there is no way to reduce the Action taken scripts. 

it is basicly done by setting a local on the speaker.  every time a starting condition is ran it increases the local.  This way the script only has to read the Local to know what node it is on.    here is an example. 

http://pastebin.com/DAP07hzH 

#5
henesua

henesua
  • Members
  • 3 858 messages
 Thanks. So here is my new version of aa_ck_token100

This will now be on all "Text Appears When" slots for the PC Responses.
I can see that I will likely need some garbage collection to reset that token value to zero. But your modulus looks like it will help prevent that problem if I always set up five responses.

This is very useful as it eliminates the need for four scripts. I wish there was a way to use only one script in "Actions taken" as well. Let me know if you think of anything.

Modifié par henesua, 03 janvier 2012 - 04:18 .


#6
henesua

henesua
  • Members
  • 3 858 messages
Revised aa_ck_token100

I had discovered a number of errors in the previous script.

Modifié par henesua, 04 janvier 2012 - 05:26 .


#7
henesua

henesua
  • Members
  • 3 858 messages
 Update.
I am at the point of testing the code. Here is what the code looks like before testing:

aa_rentroom_tok
aa_inc_housing

I would like to slim down the scripts more, but have not had the time to sit down and rip all this code apart to get at the absolute essentials. I am seeking advice on how to make these scripts much leaner. Do I need all those functions? Is there a much leaner way to handle all of this? Is there an adjustment to my data structures that I have overlooked which would make this better?

The module resources now required after recent edits (and apparently as slim as I can go without combining aa_inc_housing with aa_rentroom_tok):

conversation
  • aa_rentroom
scripts
  • aa_rentroom_tok
  • aa_inc_housing
  • aa_ck_token100
  • aa_conv_branch1
  • aa_conv_branch2
  • aa_conv_branch3
  • aa_conv_branch4
  • aa_conv_branch5 
Items:
  • aa_rentalkey
Game Objects (placed in toolset):
  • Inn Keeper - Creature object
  • Inn - One Waypoint
  • Rooms - One Waypoint Each


#8
wyldhunt1

wyldhunt1
  • Members
  • 246 messages
Looks promising.
It looks like no one has answered your question about structs inside of structs yet.
Here is how you can nest structs. This appears to be legal in NWN Aurora:

struct Stats
{
    int nFirst;
    string sOther;
    string sMeh;
};

struct Info
{
    string sStuff;
    int nThing;
    struct Stats Test;
};

struct Info GetInfo()
{
    struct Info Garble;
    Garble.sStuff = "MyStuff";
    Garble.Test.sOther = "Klergh";
    return Garble;
}

void main()

    struct Info MyStruct = GetInfo();
    MyStruct.Test.sMeh = "Blah";
    WriteTimestampedLogEntry(MyStruct.Test.sMeh);
    WriteTimestampedLogEntry(MyStruct.Test.sOther);
}


Modifié par wyldhunt1, 05 janvier 2012 - 07:07 .


#9
henesua

henesua
  • Members
  • 3 858 messages
I have yet to test nested structs myself. Thanks for looking into it for me!

While getting off the bus on the way to work this morning I realized that I have only begun to develop this system. I have yet to work out a number of things that are important:

How does one kick a PC out of a room that they are no longer paying for?
What happens if a PC keeps a key rather than returns it?
How does a PC request an extension of their stay?
How does a PC tell the innkeeper that other PCs will be sharing their room?

So I have more work to do!

#10
wyldhunt1

wyldhunt1
  • Members
  • 246 messages

henesua wrote...

I have yet to test nested structs myself. Thanks for looking into it for me!

While getting off the bus on the way to work this morning I realized that I have only begun to develop this system. I have yet to work out a number of things that are important:

How does one kick a PC out of a room that they are no longer paying for?
What happens if a PC keeps a key rather than returns it?
How does a PC request an extension of their stay?
How does a PC tell the innkeeper that other PCs will be sharing their room?

So I have more work to do!


I updated my example above to demonstrate a bit more with structs.

These systems can be very complex.
Here's my thoughts on it:
You can't kick a PC out of a room when time runs out unless you're running a HB script.
Add a check to the OnActivate script to ensure that their time isn't up. If it is, delete the key and don't unlock the door.
In the conversation, you may want one more branch. Check to see if the PC already has a room. If they do, offer to extend it. Depending on how nice you are, you can either reset the time based on the current time, or add their existing time to the new time.
I was curious how you were going to handle shared rooms myself. Unless there's a trigger in every room to count the players entering, this'll be hard to track.
If you do use a trigger, that could also be used to check how much time they have left and call a "RemovePC()" function when the time is up unless they've left the trigger.

Pastebin is down at the moment, so I used Google...
Here is an include that we use to help with time functions. It requires APS for persistence, so you may need to modify it for the default database.
https://docs.google....fchSPYYJxU/edit

Modifié par wyldhunt1, 05 janvier 2012 - 07:01 .


#11
henesua

henesua
  • Members
  • 3 858 messages
Actually I have a checkin and checkout time for each inn, an int which indicates the hour. Couldn't I have the module's heartbeat event "tell" the inn what hour it is. By "tell" I mean call a function which iterates through all "Inns" in the module, and queries each to start a "checkin" or "checkout" process?

#12
henesua

henesua
  • Members
  • 3 858 messages
A question:
are there any dynamic conversation frameworks out there for use? Perhaps I am wasting my time creating a new one. Please let me know. Thanks.

While bug testing I realized that I am working on two systems here. One is a framework for a dynamic conversation and the other is the persistent inn system.

The scripts for the dynamic conversation framework are:
  • aa_ck_token100
  • aa_conv_branch1
  • aa_conv_branch2
  • aa_conv_branch3
  • aa_conv_branch4
  • aa_conv_branch5
  • aa_conv_end
Which means that the persistent inn system for some users could be leaner, although use of this system with a dynamic conversation depends upon these 7 files. Anyway, I am just thinking outloud about how this system can be used, and about how I should package it for use.

Note:
I am not done bug testing yet. Fixed many problems thoughout the package. When finished, I'll upload the changes to pastebin and if I have time explain the differences.

Modifié par henesua, 06 janvier 2012 - 01:49 .


#13
henesua

henesua
  • Members
  • 3 858 messages
Debugging finished. Rental of a room and marking of the room as rented all appear to work. The correct key is also given to the PC.

Here are the latest versions of changed files (i left in my DEBUG checks. these will be removed later):
aa_rentroom_tok
aa_inc_housing
aa_conv_lastbranch1

New Files:
aa_conv_end
aa_conv_nodeprev


The first  problem I encountered was my use of GetLastSpeaker to get the NPC speaker. I changed this to OBJECT_SELF.
The next problem were a few instances where I had removed too much from the code when i had earlier tried to slim it down. Example: Room Type needs to be included in the persistant room data string because it is used to sort through room data.
A few other typos were found which created big problems and took a long time to locate.

#14
wyldhunt1

wyldhunt1
  • Members
  • 246 messages
I've never used it, but here is the conversation editor that I've heard the most about:
http://nwvault.ign.c....Detail&id=2985

EDIT:
I found another one as well:
http://nwvault.ign.c....Detail&id=3495

Modifié par wyldhunt1, 06 janvier 2012 - 06:14 .


#15
henesua

henesua
  • Members
  • 3 858 messages
Interesting. Those look heavier than I expected. I'll take a look at those to figure out what use they may be for me.

My thinking is that this persistent inn system should be adaptable to any of these kinds of conversation systems. I intend to strip out my dynamic conversation stuff, and only provide it as an add on or separate package. If this zz dialog works for me, we'll see how I can make this system work with it.

#16
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
From the little bit that I have looked at zz-dialog,  I do not like it much.  I guess O should not even say that since I have not looked into that deep yet.   You my however be interested in Kato's thread. 
On the road to a debugged dynamic convo system for Windows


How does one kick a PC out of a room that they are no longer paying for?
What happens if a PC keeps a key rather than returns it?
How does a PC request an extension of their stay?
How does a PC tell the innkeeper that other PCs will be sharing their room?


I have not looked at your system fully yet either,  But here is how i would handle it. 

To make sure that PC leave the key,  Hmm, Well since the did not pay with a credit card,  You make them leave a deposit.   The deposit should be enough to cover the calling of a lock smith to change the lock and a little extra for the hassle.   The Key should also be returned before the lease on the room expires to get the deposit back.   Of cource if you have a reputation system in the module you could wave the deposit for VIP's. 

Scripting wize I would handle it by never giving the same Key twice.  If the tag of your door was say BarRoom1 the first key given to a renter would be.  BarRoom1_K1 and the the Key needed to unlock to that on the door.   when the room is rented by another player increase the key number to 2.   once that is in place every thing else fall into place easer. 

For kicking the player out. you simply change the Key number. 
For extention of stay you increase the time Stamp for when there stay is up. 
For shairing a room you let them request an extra Key. (All keys need to be returned or no refund of deposit) 

  

 I have head the sugestion for a HB script.  I think that is a little over the top, even if you wanted to go that rout a pseduo HB  that ran just once a day would do the trick,  at the standard 11:00am check out time or so.   still not really needed.   The only time a PC could use the room is when they are in the area, an area OnEnter script to adjust the doors to the correct keys needed would do the trick.

#17
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
I guess I just feel like babeling some more.   

In the System I see no need to have a time stamp that is any more acurate the per hour.  say something like.

int StampGetCurentTime()
{
  return GetTimeHour()
         +GetCalendarDay()*24
         +GetCalendarMonth()*672
         +GetCalendarYear() * 8064;
}


to adjust the time stamp to 11:00an on the current day would be a simple as:

 nStamp = (StampGetCurentTime()/24) * 24 + 11;

 Then just add 24 to it for how ever many days they rent the room for.    in the On AreaEnter  you check the TimeStamp for any rooms that are rented vs the currentTime time stamp.   If current time is greater change the Key.  

An even better question then the ones you have asked is:  What happens to any items the PC happens to leave in the room.   The last time I had that conversation it was anything from selling them off a little at a time to extend the rent on the room.   To treating them more like a storage unit today. ( Not removing the ownership of the room right away,  After X amount of time on the room not being paid for auctioning off the rooms contents in bulk.  Selling then to the local pawn,  Having the cleaning staff claim them( Placing them into there invemtories, with the posiablity of them selling them to PC's)  to just wipping them from the server.   

There really are a lot of things to think about once you start a project like this.  

#18
henesua

henesua
  • Members
  • 3 858 messages
 You've given me much to think about, Lightfoot8. And I think many of your suggestions would work, but I do not think that every Inn or Apartment will handle it the same way. What this means is that the first challenge is creating a framework that all these methods can plug into.
The lock changing idea for example is very good. My system is not yet set up for that, but I can write a function that generates key tags AND adjusts the door's matching variable to match the key tag. The next thing I need is a means for the Innkeeper to know when a key is missing - key memory. With all of that in place, the Inn will be able to decide when to call a locksmith to change the locks.
But not every place is going to change the locks at the same time, or have the resources to do it every time the room changes. Its not like these are electronic keys. So my intention is to leave it up to the Inn to DECIDE to do so.
That is the trick.
From the big picture standpoint I need the following:
  • Tracking who is staying at the inn, and when their time is up: I have done this already with the rooms database
  • Detection of when "times up" at the Inn: Your time stamp is the right idea, and it works with the "checkout" variable I have allowed each inn to set. I'll think more about the OnEnter detection of this, BUT I think I need a time based stimulus rather than an OnEnter stimulus - otherwise it is possible for a PC to sit around in their room beyond checkout time and then leave without dealing with the consequences.
  • Response hook for "times up": After some thought I think the best way to handle this is to have a "times up" function that decides between default behavior, and custom script. If the string identifier for a custom script is missing, default behavior happens.
  • Memory: The Inn needs to remember who their customers have been over time so that the inn can track debts, damages, or other special circumstances. This was the idea behind my "Patrons" database which is currently commented out since I am not sure how to set up the data string yet, and whether I want to key this data specifically to the PC object. The problem with keying to the PC object is that the Bioware database doesn't seem to be able to handle that when the PC is offline - and so that is why I have a long "Patrons" string keyed to the Inn.
And again my thinking is that I want each Inn to be able to respond in their own unique way. The "aa_inc_housing" script will contain the functions that can be used to respond to various situations, but the builder and DM should be able to decide what an inns actual response is in a given situation. i haven' mentioned DMs yet, but I think they need an Inn tool to interact with this system too.

Will I code all of this? Probably not down to every detail. I only  need to get a basic framework in place so that I can add to it later, and move on other aspects of my module in the meantime. The bullet points above are my target right now. But they will be coded as a framework which custom repsonses can be plugged into.

#19
henesua

henesua
  • Members
  • 3 858 messages
Adjusted my time functions to work with this system, (and also needed to adjust time functions throughout my module that can take advantage of the change).

Now I can specifiy whether I want to return the Game Second, Minute, Hour or Day (relative to the campaign's starting time) in the GetCurrentGameTime function.

Both game hour and game day appear that they will be useful for the inn system. I will be including my time functions for this system when posting to the vault. Here they are:

aa_inc_time

I'll strip out extraneous functions when the time comes.

Modifié par henesua, 07 janvier 2012 - 05:40 .


#20
Rolo Kipp

Rolo Kipp
  • Members
  • 2 788 messages
<rifling through...>

A couple thoughts that are probably irrelevant and certainly irreverent:

First, Why check *anything* at checkout time? Would a real clerk go pounding on all the delinquent doors at exactly 11:01am? I'm not a fan of HB :-P
Heh, The time stamp is good to know when the rental window is closed, but just use a simple compare when a) they try to unlock the door, B) the maid (if the inn is classy enough) goes to clean the room or c) you need to find an available room to rent. Imagine the PCs surprise (if they attempt to squat in the room as you outlined above) when Palemaster Zog the Unforgiving unlocks his newly rented room and his 12 13 Doom Entourage start piling into the room... ;-)

The Patrons db is a good idea, as I think *anything* that keeps PCs in NPCs memory is a good idea in general. But signing the register doesn't mean *only* those patrons have keys... and if you use the incremental key idea *and* if some of the inns are a bit laggardly (perhaps even on *purpose*), there's the possibility of unauthorized people gaining access to the key, and the room.

One of the moments in A Dance With Rogues that bumped a "friend's" involvement meter was returning to *her* apartment to find a burglar... She was instantly outraged and slaughtered the fool. It was a minor thing and a very short encounter, but it made her feel quite possessive.

Imagine if the inn in question was questionable (a fact the PCs *should* have discovered from talk in the tavern, but ignored) and they regularly burgled or set upon patrons... We have all heard the phrase "disreputable" before. Wouldn't it be neat if it *meant* something? And "Shanghai-ing" could be a perfect hook for an adventure.

For what it's worth, I'm quite enjoying your thread :-)
Um, do you carry your house key in the left pouch or the right...?

<...Henesua's pouches>

Modifié par Rolo Kipp, 07 janvier 2012 - 06:16 .


#21
henesua

henesua
  • Members
  • 3 858 messages

Rolo Kipp wrote...
First, Why check *anything* at checkout time? Would a real clerk go pounding on all the delinquent doors at exactly 11:01am? I'm not a fan of HB :-P

 

Not necessarily. It depends on the Inn. Hence my post above about making this system a framework that other builders can plug into. So the system enables a custom script call on checkout time, but if nothing is set, only default scripts will run. What those default scripts do... is the real question. I have not decided yet but I'll most likely leave a variable that will enable a builder to TURN OFF the default responses. Default responses however are good for those that just want an inn to work without digging in and customizing stuff.

Rolo Kipp wrote... 
Heh, The time stamp is good to know when the rental window is closed, but just use a simple compare when a) they try to unlock the door, B) the maid (if the inn is classy enough) goes to clean the room or c) you need to find an available room to rent. Imagine the PCs surprise (if they attempt to squat in the room as you outlined above) when Palemaster Zog the Unforgiving unlocks his newly rented room and his 12 13 Doom Entourage start piling into the room... ;-)


I agree that all of that works. But I think it depends upon the Inn. For example: a "house of ill repute" would probably have the enforcer come around at a particular time to extract money out of the patron before kicking them to the street. So I want to enable each Inn to respond in different ways within the framework.

Rolo Kipp wrote...  
The Patrons db is a good idea, as I think *anything* that keeps PCs in NPCs memory is a good idea in general. But signing the register doesn't mean *only* those patrons have keys... and if you use the incremental key idea *and* if some of the inns are a bit laggardly (perhaps even on *purpose*), there's the possibility of unauthorized people gaining access to the key, and the room.


Of course. I still have not worked out exactly how to determine the WHEN or IF of lock changing. Working on that now. I think part of this is tracking who has the room key in the ROOMS DB, and providing the ability for an inn keeper to be "forgetful".

Rolo Kipp wrote...   
Imagine if the inn in question was questionable (a fact the PCs *should* have discovered from talk in the tavern, but ignored) and they regularly burgled or set upon patrons... We have all heard the phrase "disreputable" before. Wouldn't it be neat if it *meant* something? And "Shanghai-ing" could be a perfect hook for an adventure.


I definitely want the system to work with these options. And I think the "key" to that is to provide hooks that DMs and Builders can latch onto.

But this can get ridiculously complicated. I need to wrap up version one of this soon and get back to building my module. At this point its all going to be about planning ahead, and providing paths for future development. I just need the base functionality for the Inn I am currently building, and then tie this one off for later work.

#22
henesua

henesua
  • Members
  • 3 858 messages
 One of the issues related to changing the key tag on these rental doors is that I have to ensure that the doors are always updated to the latest key tag. Especially after a server boots.

So I created a function which will intialize all of an inn's rental room doors. At present this function merely adds a local string to each door of each room which matches the rental key for the room.

void InitializeDoors(string sInnTag)
{
  object oRoom, oDoor;
  int nIt, nRoom;
  string sRoomKey;

  nRoom   = 1;
  oRoom   = GetRoom(sInnTag, nRoom);
  while(GetIsObjectValid(oRoom))
  {
    sRoomKey    = GetRentalKey(sInnTag, nRoom);
    nIt   = 0;
    oDoor = GetRoomDoor(oRoom, nIt);
    do
    {
      SetLocalString(oDoor, ROOM_KEY, sRoomKey);
      oDoor = GetRoomDoor(oRoom, ++nIt);
    } while(GetIsObjectValid(oDoor));

    oRoom   = GetRoom(sInnTag, ++nRoom);
  }
}


GetRentalKey - returns the key tag from the inn's room database
GetRoomDoor - iterates through the doors associated with a room

The question I have is how do{}while will work for me here. Does it evaluate itself after executing all of the code inside the curly brackets?

The reason why I ask is that it is possible that Door 0 does not exist. And if it doesn't there are either no locked doors (and thus no key) or there are multiple doors (the situation I want to catch). This enables Rental Rooms to have a pair of doors which transition between areas or other combinations of doors, and all will respond to the same room key. So to wrap up I don't want the loop to cease if Door 0 is invalid. I want it to also look for Door 1.

So will this do{}while work the way I want it to? This is the first time I have found a use for do..while that is more graceful than using while would have been - so I'm uncertain that I am on the right track.

Modifié par henesua, 09 janvier 2012 - 12:03 .


#23
Lightfoot8

Lightfoot8
  • Members
  • 2 535 messages
Yes, that would work as you expect,  I however do not like it.   The reason is that you are still trying to set the local int on the nonexistant door 0, When it does not exist.   I think this would be better.

void InitializeDoors(string sInnTag)
{
  object oRoom, oDoor;
  int nIt, nRoom;
  string sRoomKey;
  
  nRoom   = 1;
  oRoom   = GetRoom(sInnTag, nRoom);
  while(GetIsObjectValid(oRoom))
  {
    sRoomKey    = GetRentalKey(sInnTag, nRoom);
    nIt   = 0;
    oDoor = GetRoomDoor(oRoom, nIt);
    if (!GetIsObjectValid(oDoor))  oDoor = GetRoomDoor(oRoom, ++nIt);
    while(GetIsObjectValid(oDoor))
    {
      SetLocalString(oDoor, ROOM_KEY, sRoomKey);
      oDoor = GetRoomDoor(oRoom, ++nIt);
    }

    oRoom   = GetRoom(sInnTag, ++nRoom);
  }
}

The question I have is why are you setting the local on the door?
would not
SetLockKeyTag(oDoor, sRoomKey);
work better?

Modifié par Lightfoot8, 09 janvier 2012 - 12:59 .


#24
henesua

henesua
  • Members
  • 3 858 messages
ah, nicely done. I should have thought of that. Thank you.

And to answer your question:
all of the doors are opened by a master inn key which is what I have set in the LockKeyTag field. I did this so that NPCs (carrying the master inn key) can enter any room in the Inn.
That left the need to also enable specific keys to only open a single room.door in the inn. A door script checks for a match between the local string "KEY" and the tag of the door, and if there is a match the door (if locked) is unlocked

Modifié par henesua, 09 janvier 2012 - 02:14 .


#25
henesua

henesua
  • Members
  • 3 858 messages
 I've come across a bug.

In the Inn Room database I have stored PCs as a combination of player name and character name, yet I am using data delimiters that could be entered by a player when typing in their name.

The delimiters I am currently using:
* . _ :

So I hope that there are some other string characters that I can use as delimiters which a player will not be able to enter into their name fields. I am considering using unusual characters like:
© ` ‡ † ¤ §

Are any of these enterable by a player? I tried with my keyboard but was unable to find the keystrokes that would create them.