Page 1 of 1

Script for all avlis to use if wanting

Posted: Tue Aug 05, 2003 9:04 am
by SlicerDicer
edit: this script now allows you to only charge once per week so the player cant pay over and over. at the end of the week you remove the token from the chest and put it in trashcan and cycle starts over again.

Code: Select all

// Created Tuesday, August 4 2003
// Created by, SlicerDicer
// Code is free to be chopped, hacked, reverse engineered and eaten for breakfast
/* The script makes it so you can check and see if the payslip is in the chest if
it is then it wont charge you again. if its not then it will charge you rent. simple
yet effective.*/


void main()
{

object oRentChest   = GetObjectByTag("OAA_Rent_Chest");  // chest payment goes in
object oPC          = GetPCSpeaker();   // player character ident
int iRent           = 1000;      // rent cost


if (!GetIsPC(oPC)) return;

if (GetItemPossessedBy(oRentChest, "oaa_payslip_001")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_001")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_001",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_002")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_002")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_002",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_003")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_003")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_003",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_004")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_004")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_004",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_005")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_005")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_005",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_006")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_006")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_006",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_007")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_007")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_007",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_008")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_008")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_008",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_009")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_009")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_009",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_010")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_010")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_010",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_011")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_011")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_011",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_012")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_012")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_012",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_013")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_013")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_013",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_014")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_014")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_014",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_015")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_015")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_015",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_016")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_016")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_016",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_017")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_017")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_017",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_018")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_018")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_018",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_019")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_019")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_019",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_020")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_020")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_020",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_021")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_021")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_021",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_022")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_022")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_022",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_023")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_023")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_023",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_024")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_024")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_024",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_025")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_025")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_025",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_026")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_026")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_026",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_027")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_027")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_027",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_028")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_028")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_028",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_029")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_029")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_029",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_030")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_030")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_030",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_031")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_031")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_031",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_032")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_032")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_032",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_033")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_033")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_033",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_034")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_034")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_034",oRentChest);SpeakString("Thank ye for paying yer rent!");}
if (GetItemPossessedBy(oRentChest, "oaa_payslip_035")!= OBJECT_INVALID){SpeakString("Ye already payed yer rent this month!");}
else
if (GetItemPossessedBy(oPC, "oaa_rkey_035")!= OBJECT_INVALID){AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);CreateItemOnObject("oaa_payslip_035",oRentChest);SpeakString("Thank ye for paying yer rent!");}

 }

i will be editing this when i 100% complete it. it is part of what i am working on for a player run inn. what this script does is checks to see what key the oPC has from there it charges the oPC 1000 gp and puts the 1000gp in a chest along with a token that way you know room 1 has payed etc. this is just the first part of the script. modify the tags of the items as needed to create what you want to do. more will come soon promise.

Posted: Tue Aug 05, 2003 9:29 am
by HarveyH
Doesn't NWN scripting allow some kind of loop structure?

It looks kinda silly, 35 'IF' statements with as only difference a number increasing from 1 to 35...

Something like:

Code: Select all

for i in range(25):
   if (GetItemPossessedBy(oPC, "oaa_rkey_"+i)!= OBJECT_INVALID)
      {AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));
      CreateItemOnObject   ("oaa_inn_payment",oRentChest,iRent);
      CreateItemOnObject("oaa_payslip_"+i,oRentChest);
      SpeakString("Thank ye for paying yer rent!");}

Posted: Tue Aug 05, 2003 9:37 am
by Sindol
AAAARGH MY EYES!

I'm not saying I'm the best scripter there is, because I'm not, but this is probably the most unreadable script I've ever encountered, including my own. :o

Posted: Tue Aug 05, 2003 9:44 am
by SlicerDicer
well i am sorry if i cant post it the way it looks in the toolset beacuse of the way the forums work. but yes it is quite unreadable.
also if you want to fix it with the loop function go for it. i tryed to get the loop working tons of times and could not so i just gave up and did a shitload of ifs. sorry btw the above code is modifyed

Posted: Tue Aug 05, 2003 9:47 am
by Vlad Bogdanov
If you post the version with the loop that's not working, we can all stare at it and try to fix it. I assume you have been using IntToString() and string concatenation with "+" right?

Totally pulling this out of my behind:

Code: Select all

int i;
string sI;

for (i=1; i<36; i++)
{

  sI = IntToString(i);
  if (GetItemPossessedBy(oRentChest, "oaa_payslip_"+sI)!= OBJECT_INVALID)
  {
    SpeakString("Ye already payed yer rent this month!");
  }
  else
  if (GetItemPossessedBy(oPC, "oaa_rkey_"+sI)!= OBJECT_INVALID)
  {
    AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));
    CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);
    CreateItemOnObject("oaa_payslip_"+sI,oRentChest);
    SpeakString("Thank ye for paying yer rent!");
  }
}

Note that this strips the leading zeroes. If it's a problem you can but them back in, but it should work regardless if you keep doing it in the same way everywhere.

EDIT: To Neve

Hey Dutchie! Looks like you missed an IntToString on the second CreateItemOnObject :D

Posted: Tue Aug 05, 2003 9:49 am
by Neve
Harvey : That could work, just don't forget to convert the "i" to a string :)

Code: Select all

const number = 25;
object oPC =<???>;
int i = 1;

while(i<=number){
      GetItemPossessedBy(oPC, "oaa_rkey_" + IntToString(i))
      AssignCommand(oPC, TakeGoldFromCreature(iRent, oPC, TRUE));
      CreateItemOnObject("oaa_inn_payment", oRentChest, iRent);
      CreateItemOnObject("oaa_payslip_"+i, oRentChest);
      SpeakString("Thank ye for paying yer rent!");
      i++;
}

Posted: Tue Aug 05, 2003 9:58 am
by SlicerDicer
thanks neve i thought about contacting you but you have no msger :)

Posted: Tue Aug 05, 2003 10:02 am
by HarveyH
*shakes head*
Didn't I tell them to base this NWN scripting thing on python? Yes I did. But did they listen? No they didn't. The fekkers.

Posted: Tue Aug 05, 2003 10:09 am
by KinX
bah, python.

Posted: Tue Aug 05, 2003 10:44 am
by SlicerDicer
when i get this code completed properly i would like to talk to all interested partys who are wanting to create player run rental rooms. if you want to contact me and work with me on this you can i sure could use the help.

Posted: Tue Aug 05, 2003 2:18 pm
by Silk
Holy shit... I think my brain just exploded. :shock:
I think you need to "optimize" your code there...

Posted: Tue Aug 05, 2003 2:42 pm
by Manuel the White
Does NWScript have a switch/select case control structure?

Posted: Tue Aug 05, 2003 2:44 pm
by Neve

Code: Select all

switch( ... ){
   case 1 : ...; break;
   case 2 : ...; break;
}
;)

Posted: Tue Aug 05, 2003 7:41 pm
by SlicerDicer
Silk wrote:Holy shit... I think my brain just exploded. :shock:
I think you need to "optimize" your code there...
i am workin on it as i said before i posted the code so i could get help beacuse i could not get the while function working

i think i just realised why my code was not working :) hehe

Code: Select all

void main()
{
object oPC = GetPCSpeaker();
object oRentChest = GetObjectByTag("OAA_Rent_Chest");
object oRentKey = OBJECT_INVALID;
int iPCgold;
int iRent = 1000;               // this is how much is payed to the Guild per rent time
string sKeyName = "OOA_rkey_";  // this is the base name of all the room keys
int iIter = 1;                  // this is the variable that counts through the iterations
int irun = TRUE;                // this keeps the while loop running
int iLimit = 35;                // total number of rooms

while (irun)
    {
    if ((iIter&&10)>=1)
        {
         oRentKey = GetItemPossessedBy(oPC,sKeyName + "0" + IntToString(iIter));
        }
        {
         oRentKey = GetItemPossessedBy(oPC,sKeyName + "00" + IntToString(iIter));
        }
    iIter++;
    if (iIter>iLimit) { irun = FALSE; }
    if (oRentKey != OBJECT_INVALID) { irun = FALSE; }
    }

if (oRentKey == OBJECT_INVALID)
    {
        SpeakString("you fool dont try to pay if you dont have a key !");
    }
    {
    if(GetGold(oPC) > iRent)
        {
            TakeGoldFromCreature(1000, oPC, 1);
            CreateItemOnObject("ooa_payslip_"+ GetStringRight(GetTag(oRentKey),3),oRentChest, 1);
            CreateItemOnObject("oaa_inn_payment",oRentChest,iRent);
        }
        {
            SpeakString("Thank ye for paying yer rent.");
        }
    }
}
ok the code here is kinda sorta working it takes the gold and puts the gold in the chest. problem being is it is not putting in the payslip... any ideas? also i still need to write the rest with the if/else so it wont allow to pay once but that is not may major worry right now

Posted: Thu Aug 07, 2003 12:26 pm
by Neve

Code: Select all

if ((iIter&&10)>=1)
This is weird... What are you checking for >= 1 here ? '&&' is read as "AND", maybe you mean '+' instead of '&&' ?

The way I read it is iIter>=1 && 10>=1 . You assign a 1 to iIter, so this check is always true.

What does this do ?
string sKeyName = "OOA_rkey_";
GetItemPossessedBy(GetPCSpeaker(),sKeyName + "0" + IntToString(iIter));

How about :
GetItemPossessedBy(GetPCSpeaker(), "OOA_rkey_0" + IntToString(iIter));

Also, don't use { and } so much =P
If(true) blah; can be done without { }
If(true) {blah; blah;} needs compounds

Code: Select all

void main(){
    object oRentKey   = OBJECT_INVALID;
    int    iRent      = 1000;
    int    iIter      = 1;
    int    irun       = TRUE;
    int    iLimit     = 35;

    while(irun){
        if((iIter&&10) >= 1){
            oRentKey = GetItemPossessedBy(GetPCSpeaker(), "OOA_rkey_0"  + IntToString(iIter));
            oRentKey = GetItemPossessedBy(GetPCSpeaker(), "OOA_rkey_00" + IntToString(iIter));
            iIter++;
        }

       if((iIter > iLimit) || (oRentKey != OBJECT_INVALID)) irun = FALSE;
       else SpeakString("you fool dont try to pay if you dont have a key !");

        if(GetGold(GetPCSpeaker()) > iRent){
            TakeGoldFromCreature(1000, GetPCSpeaker(), TRUE);
            CreateItemOnObject("ooa_payslip_" + GetStringRight(GetTag(oRentKey), 3), GetObjectByTag("OAA_Rent_Chest"), 1);
            CreateItemOnObject("oaa_inn_payment", GetObjectByTag("OAA_Rent_Chest"), iRent);
            SpeakString("Thank ye for paying yer rent.");
        }
    }
}

Posted: Thu Aug 07, 2003 1:14 pm
by Brannor
Silk wrote:Holy shit... I think my brain just exploded. :shock:
I think you need to "optimize" your code there...
Well actually unrolling loops is better for performance.
But a loop is a LOT better to read.

Posted: Mon Aug 11, 2003 8:35 am
by SlicerDicer
Brannor wrote:
Silk wrote:Holy shit... I think my brain just exploded. :shock:
I think you need to "optimize" your code there...
Well actually unrolling loops is better for performance.
But a loop is a LOT better to read.
hehe well that is a shitload of unrolling!

Posted: Mon Aug 11, 2003 10:45 pm
by Alexandru Stanicu
Hey Slicer... what if you put a box the rent chest for each room (and name it according to room number) and have the gold placed in that box... would that work?

-Alex