Server Totals
M'Chek - (1)
Wilderness - (1)
Ferrell - (0)
Elysia - (0)
Le'Or - (0)
Deglos - (0)
Visimontium - (0)
Underdark - (0)
Mikona - (0)
Total players: 2
  • MChek 0026
    Album name: DM Events
    Uploaded by: Olisa
    Uploaded: Fri Jun 22, 2018 9:30 pm

Links Menu

Door Rent Collection Script, tell me if you see obvious bugs

Moderators: Nighthawk4, Dungeon Masters

Door Rent Collection Script, tell me if you see obvious bugs

PostAuthor: Orleron » Sat Nov 23, 2002 1:55 am

I've written this script to put on doors of rooms people rent. It's designed to collect rent every 7 days from the time they've first opened the door with their key:

// Rent collection script that goes in the OnOpen for player's door

#include "datetime"

void main()

object oPC = GetLastOpenedBy();
object oKey = GetFirstItemInInventory(oPC);

int bAlreadyOpened = GetPersistantDynamicInt(oKey, "Rent Collection On");

string sNextPayment;
string sKeyTag;
string sDoorTagOwner = GetStringLeft(GetTag(OBJECT_SELF), 4);

struct DateTime sNow = getCurrentDateTime();
struct DateTime sRentCollectionTime =
addDateTime(GetPersistantDateTime(oKey, "Rent Start Time"), newDateTime(0,0,7,0));

// Check if the PC has the door's key
while (GetIsObjectValid(oKey))

// Check if sDoorTagOwner is the same as the first 4 letters of sKeyTag
// Key tag names are usually of the format <Character Name>Key, and door
// tag names for renters are usually of the format <Character Name>Door.

sKeyTag = GetStringLeft(GetTag(oKey),4);

if (TestStringAgainstPattern(sKeyTag, sDoorTagOwner))

// if this object is in fact the door key, check to see if this is
// the first time the door is being opened by the player. If it is,
// start the rent clock ticking. Collect rent every 7 days.

if (!bAlreadyOpened)
// Set key to Rent Collection Status ON
SetPersistantInt(oKey, "Rent Collection On", TRUE, 60, SCRIPTNAME_GENERAL);
// Set Rent Start time to Current Time
SetPersistantDateTime(oKey, "Rent Start Time", sNow);

// if the door has already been opened before, check the time on the key
// to see if 7 days have passed since the last Rent Start Time
// if more than 7 days have passed, collect the rent and reset the rent
// start time

else if (bAlreadyOpened
&& compareDateTime(sNow, sRentCollectionTime) >= 7
&& GetGold(oPC) >= 1000)
TakeGoldFromCreature(1000, oPC, TRUE);
SendMessageToPC(oPC, "1000 gold has been taken for your rent.");
SetPersistantDateTime(oKey, "Rent Start Time", sNow);
// if the player doesn't have enough gold after 7 days, destroy their key

else if (bAlreadyOpened
&& compareDateTime(sNow, sRentCollectionTime) >= 7
&& GetGold(oPC) <= 1000)
SendMessageToPC(oPC, "You do not have enough money to meet your rent!");
SendMessageToPC(oPC, "Your key has been destroyed. You will have to see a real estate agent.");


oKey = GetNextItemInInventory();

"Truth has no form."
--Idries Shah

World of Avlis Page

Avlis Project FAQ

World Advisor, Co-founder
World Advisor, Co-founder
Posts: 15040
Joined: Fri Sep 14, 2001 9:48 pm
Timezone: GMT-5

PostAuthor: OloEopia » Mon Jan 27, 2003 1:15 am

Nothing I can see from here, although I do not know the contents of "datetime," and I am guessing the SetPersistentDynamic functions are unique to your internal SQL database system.

Keep up the good work.

Posts: 3
Joined: Mon Jan 27, 2003 1:07 am

PostAuthor: Papillon » Mon Jan 27, 2003 9:18 am

Looks fine. Only thing is rent will be collected multiple times if the player happens to have more than one key.

If I understand that correctly, you're planning to hardcode (=set in the toolset) the tags of the keys and doors, right ? Have you considered assigning numbers from 0000 - 9999 and use a database table that associates the number with the character (e.g. 0123 = 'Joe') ? May be easier to maintain in the long run.

Team Member; Retired with Honors
Posts: 3155
Joined: Thu Jul 18, 2002 11:17 pm

Return to NWN Scripting

Who is online

Registered users: Bing [Bot], Blackravenfeather, Google [Bot], Jazz, Zayna