Collecting rents
Moderator: Event DM
Collecting rents
If a player buys an Inn. What script is used to give your character the money that is payed in rent for the rooms.
Only two things in the world are infinite, the universe and human stupidity; and I'm not quite sure about the former." -Albert Einstein
- Mistcaller
- Team Member; Retired with Honors
- Posts: 5477
- Joined: Sun Feb 09, 2003 3:42 pm
- Location: Athens, Greece (GMT +2)
The script we use takes the gold from the PC and stores a fraction of it to the private chest of the innkeeper.
Its true, though, that handling gold is not easy inside NWN containers, especially if they are persistent.
I'll dig up the part of the script and post it here if you like, while I'm working on a fix for it.
Its true, though, that handling gold is not easy inside NWN containers, especially if they are persistent.
I'll dig up the part of the script and post it here if you like, while I'm working on a fix for it.
- Mistcaller
- Team Member; Retired with Honors
- Posts: 5477
- Joined: Sun Feb 09, 2003 3:42 pm
- Location: Athens, Greece (GMT +2)
This is the function I use. If you find any bugs please let me know.. it would help..
:

Code: Select all
void TakeGoldAndStore( object oPC, object oOwner, int iPrice, float fProfit=1.0)
{
//Chest related variables
string sContainerTag = GetTag(oOwner)+"PrChest";
object oChest = GetObjectByTag(sContainerTag);
object oGold;
object oGoldNew;
string sItemTag = "NW_IT_GOLD001";
int iAmount;
int iTakeGold = iPrice;
TakeGoldFromCreature(iTakeGold, oPC, TRUE);
// Add the amount (price * %profit) to the owner's chest
if (GetIsObjectValid(oChest))
{
float fProduct = fProfit*iTakeGold;
int iTotal;
oGold = GetFirstItemInInventory();
while (GetIsObjectValid(oGold))
{
if (GetTag(oGold) == sItemTag)
iAmount += GetNumStackedItems(oGold);
oGold = GetNextItemInInventory();
}
if (iAmount > 50000)
PrintString ("Possible Gold overflow");
iTotal = iAmount + FloatToInt(fProduct);
// Check if total is greater than 50k. if it is create a new stack
if (iTotal>50000)
{
oGoldNew = CreateItemOnObject("nw_it_gold001",oChest, iTotal-50000);
SetItemStackSize(oGold, 50000 );
SetItemStackSize(oGoldNew, iTotal-50000 );
}
else
SetItemStackSize(oGold, iTotal );
string sSQL;
// store new gold amount in database
sSQL = "SELECT * FROM containers WHERE container='" + sContainerTag +
"' AND item='" + sItemTag + "'";
SQLExecDirect(sSQL);
if (SQLFetch() == SQL_SUCCESS)
sSQL = "UPDATE containers SET count=" + IntToString(iTotal) +
" WHERE container='" + sContainerTag + "' AND item='" + sItemTag + "'";
else
sSQL = "INSERT INTO containers (container,item,count,identified) VALUES " +
"('" + sContainerTag + "','" + sItemTag + "'," + IntToString(iTotal) + ",1)";
SQLExecDirect(sSQL);
}
}
- Tharliss
- Elder Sage
- Posts: 3251
- Joined: Fri May 16, 2003 8:00 pm
- Timezone: PST
- Location: Reno, NV (GMT -8)
*Looks at the Code from beginning to End, then from End to beginning. Meditates throughout the evening, praying to Berynn, Dru'El, and Vorin for guidance. Realizes he has no idea what the Code says. Hopes that someone can help out MistCaller.*Mistcaller wrote:This is the function I use. If you find any bugs please let me know.. it would help..:
(Bump.)

-
- Apprentice Scholar
- Posts: 890
- Joined: Thu Jan 29, 2004 10:58 pm
- Location: Sydney, Australia GMT+10
- Contact:
Well, the second SetItemStackSize call seems to be redundant - the CreateItemOnObject will already do that.
What if you're adding, say 50002 gold to a thing with 49999 already? This will just create one additional stack at most - the if (iTotal > 50000) really wants to be a while, and you decrement iTotal inside the body...
Oh, and SELECT * is always a bad idea
What if you're adding, say 50002 gold to a thing with 49999 already? This will just create one additional stack at most - the if (iTotal > 50000) really wants to be a while, and you decrement iTotal inside the body...
Oh, and SELECT * is always a bad idea

- Psyco
- Elder Sage
- Posts: 3288
- Joined: Mon Jun 30, 2003 10:05 pm
- Location: New Zealand (NZDT, +12 GMT)
- Contact:
This could be made a little easier if it is cobbled together with the generic donation chest thing i am putting together (or is sitting on my list waiting for me to get around to it)
I will talk to you about it next time i see you online when i am at home Mistcaller.
Tharliss: that script takes some gold, rearranges the stacks (cannot have more than 50k per stack, bioware limitation) then stores the new stack count info in the database.
I will talk to you about it next time i see you online when i am at home Mistcaller.
Tharliss: that script takes some gold, rearranges the stacks (cannot have more than 50k per stack, bioware limitation) then stores the new stack count info in the database.
- JollyOrc
- Elder Sage
- Posts: 3984
- Joined: Fri Jan 17, 2003 11:41 am
- Timezone: Europe, CE(S)T
- Location: Germany
- Contact:
Perhaps we should simply implement a "gold only" chest.
Which is simply a db table that stores one line per "chest", denoting the chest in question, and the amount of gold in there
Then you would have to add some sort of retrieval script to allow withdrawing gold, or to add some more manually.
I assume that would also lessen lag quite a bit
Which is simply a db table that stores one line per "chest", denoting the chest in question, and the amount of gold in there
Then you would have to add some sort of retrieval script to allow withdrawing gold, or to add some more manually.
I assume that would also lessen lag quite a bit

- Mistcaller
- Team Member; Retired with Honors
- Posts: 5477
- Joined: Sun Feb 09, 2003 3:42 pm
- Location: Athens, Greece (GMT +2)
Could you test your suggestions please and let me know?srn wrote:Well, the second SetItemStackSize call seems to be redundant - the CreateItemOnObject will already do that.
What if you're adding, say 50002 gold to a thing with 49999 already? This will just create one additional stack at most - the if (iTotal > 50000) really wants to be a while, and you decrement iTotal inside the body...
Oh, and SELECT * is always a bad idea

- Lafferty
- Scholar
- Posts: 1129
- Joined: Tue Feb 11, 2003 5:08 pm
- Location: look at my hands... they are HUGE. And they cant touch themselves...
- Contact:
what happens when the person the gold gets taken from doesnt have enough?
Will it just silently skip? or is this checked in another script?
Will it just silently skip? or is this checked in another script?
Tool for crafters Do you want some human to your salt? nomanisanisland.monolar.de
- Mistcaller
- Team Member; Retired with Honors
- Posts: 5477
- Joined: Sun Feb 09, 2003 3:42 pm
- Location: Athens, Greece (GMT +2)
- DorianHawkwind
- Prince of Bloated Discourse
- Posts: 279
- Joined: Sat Sep 11, 2004 10:41 pm
- Location: Texas
- Contact:
I'm not so sure about that, because my character went to his room in the Half-Moon Inn....and lo-and-behold he did not have enough money for his room. The script said that his key was destroyed and that when he had the money he should talk to the Innkeeper within 3 days Real Time(?) or he would lose the room. I went to the Innkeeper within the 3 days time and he said that he had no rooms for sale and he no longer recognized my character. In the meantime...I lost all of my stuff in the permanent chest that I had been storing for safe-keeping. I couldn't get into my room...and I have basically had to "write-it off" as a very bad experience. I tried to contact DM's and even sent a PM to Mistcaller (?) and got no reply. At this point it has been about 5-6 days after the event and I'm sure that the items and my room are permanently gone.
Respectfully,
Dorian Hawkwind (aka Calatin the Mad)
Respectfully,
Dorian Hawkwind (aka Calatin the Mad)
"I didn't mean to scare him to death. I just wanted him to envision what I see"
- DorianHawkwind
- Prince of Bloated Discourse
- Posts: 279
- Joined: Sat Sep 11, 2004 10:41 pm
- Location: Texas
- Contact:
I'm not so sure about that information, because my character went to his room in the Half-Moon Inn....and lo-and-behold he did not have enough money for his room. The script said that his key was destroyed and that when he had the money he should talk to the Innkeeper within 3 days Real Time(?) or he would lose the room. I went to the Innkeeper within the 3 days time and he said that he had no rooms for sale and he no longer recognized my character. In the meantime...I lost all of my stuff in the permanent chest that I had been storing for safe-keeping. I couldn't get into my room...and I have basically had to "write-it off" as a very bad experience. I tried to contact DM's and even sent a PM to Mistcaller (?) and got no reply. At this point it has been about 5-6 days after the event and I'm sure that the items and my room are permanently gone.
Respectfully,
Dorian Hawkwind (aka Calatin the Mad)
Respectfully,
Dorian Hawkwind (aka Calatin the Mad)
"I didn't mean to scare him to death. I just wanted him to envision what I see"
- Mistcaller
- Team Member; Retired with Honors
- Posts: 5477
- Joined: Sun Feb 09, 2003 3:42 pm
- Location: Athens, Greece (GMT +2)
I tried to contact you last night when I saw you in Ferrell, but you didnt respond. So I decided to run a small event for your group instead. 
FYI, I do not have the luxury of time to pursue each one of you that lost his room for one reason or another. I'm sorry...
I can tell you though, that the renting system is being re-worked, so that we can eliminate such occurances. Its not of the highest priority things to do though.

FYI, I do not have the luxury of time to pursue each one of you that lost his room for one reason or another. I'm sorry...
I can tell you though, that the renting system is being re-worked, so that we can eliminate such occurances. Its not of the highest priority things to do though.