Page 1 of 1

Collecting rents

Posted: Fri Aug 13, 2004 1:15 pm
by Albion
If a player buys an Inn. What script is used to give your character the money that is payed in rent for the rooms.

Posted: Fri Aug 13, 2004 1:32 pm
by Tharliss
I'd be interested in this answer as well.

Zach owns the Second Solace and has a couple others on the way. However, he seems to get a fraction in revenue from what it should be.

I've placed a bug report, thinking that the current script does not work properly.

Posted: Sat Aug 14, 2004 9:51 pm
by Mistcaller
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.

Posted: Mon Aug 16, 2004 9:56 pm
by Mistcaller
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);
   }
}

Posted: Tue Aug 17, 2004 12:39 am
by Tharliss
Mistcaller wrote:This is the function I use. If you find any bugs please let me know.. it would help.. :) :
*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.*

(Bump.) :wink:

Posted: Tue Aug 17, 2004 12:47 am
by srn
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 :)

Posted: Tue Aug 17, 2004 12:51 am
by Psyco
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.

Posted: Tue Aug 17, 2004 7:06 am
by JollyOrc
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 :-)

Posted: Tue Aug 17, 2004 11:21 pm
by Mistcaller
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 :)
Could you test your suggestions please and let me know? :mrgreen:

Posted: Tue Aug 17, 2004 11:53 pm
by Lafferty
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?

Posted: Wed Aug 18, 2004 2:00 am
by Mistcaller
Lafferty wrote: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?
It is checked in another script which acts as a starting conditional.

Posted: Wed Feb 02, 2005 10:16 pm
by DorianHawkwind
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)

Posted: Wed Feb 02, 2005 10:17 pm
by DorianHawkwind
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)

Posted: Wed Feb 02, 2005 10:30 pm
by Mistcaller
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.