logo logo

 Back to main page

The NWNX Community Forum

 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
having trouble with getting a script to work in conversation

 
Post new topic   Reply to topic    nwnx.org Forum Index -> Scripts and Modules
View previous topic :: View next topic  
Author Message
ironhorse



Joined: 02 May 2005
Posts: 13
Location: uk

PostPosted: Thu Jun 16, 2011 23:10    Post subject: having trouble with getting a script to work in conversation Reply with quote

Hi all,

I am trying to get an NPC to tell the PC taking to them how much rent they have left on their house.

I have tried to use this to get the info and set the custom token but when i click it it just ends the conversation. If I remove the script it continues through.

Code:
#include "aps_include"
void main()
{
object oPC = GetPCSpeaker();
object oItem = GetFirstItemInInventory(oPC);
while (oItem != OBJECT_INVALID)
    {
    string sKey = GetTag(oItem);
    string sHouseKey = GetStringLeft(sKey, 3);
    if ((sHouseKey) == "KEY")
        {
        string sSign = GetLocalString (oItem, "HOUSE_TAG");
        object oSign = GetObjectByTag (""+sSign+"");
        int iRent = GetPersistentInt (oSign, "House_Rent", "housing");
        string sRent = IntToString (iRent);
        SetCustomToken(11, sRent);

        }
    oItem = GetNextItemInInventory(oPC);
    }

}


can anyone help me with why this isn't working please? On NWN1 with NWNX2.

Thanks,

Ironhorse
Back to top
View user's profile Send private message Visit poster's website
Lokey



Joined: 02 Jan 2005
Posts: 158

PostPosted: Sat Jun 18, 2011 1:23    Post subject: Reply with quote

int somecondition = TRUE:
while(GetIsObjectValid(oItem) && somecondition)

somecondition = FALSE when you've found the item you want.

Comparing to X_INVALID has a few problems, use the GetIsValid functions. Rest looks like it shouldn't explode, but can't comment on aps.
_________________
Neversummer PW NWNx powered mayhem Wink
Back to top
View user's profile Send private message
Fireboar



Joined: 17 Feb 2008
Posts: 323

PostPosted: Sun Jun 19, 2011 15:43    Post subject: Reply with quote

Or you could use the "break" or "return" statement, which is probably cleaner. I'd suggest the following:

Code:
#include "aps_include"
void main()
{
  object oPC = GetPCSpeaker();
  object oItem = GetFirstItemInInventory(oPC);
  while (GetIsObjectValid(oItem))
  {
    if (GetStringLeft(GetTag(oItem), 3) == "KEY")
    {
      object oSign = GetObjectByTag(GetLocalString(oItem, "HOUSE_TAG"));
      int iRent = GetPersistentInt(oSign, "House_Rent", "housing");
      SetCustomToken(11, IntToString(iRent));
      return;
    }
    oItem = GetNextItemInInventory(oPC);
  }
}


However, I don't know if this will persist over resets properly. If not, try using the sign's tag as part of the persistent variable name, and setting it on a PC or the module.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    nwnx.org Forum Index -> Scripts and Modules All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group