View previous topic :: View next topic |
Author |
Message |
ironhorse
Joined: 02 May 2005 Posts: 13 Location: uk
|
Posted: Thu Jun 16, 2011 23:10 Post subject: having trouble with getting a script to work in conversation |
|
|
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 |
|
|
Lokey
Joined: 02 Jan 2005 Posts: 158
|
Posted: Sat Jun 18, 2011 1:23 Post subject: |
|
|
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 |
|
Back to top |
|
|
Fireboar
Joined: 17 Feb 2008 Posts: 323
|
Posted: Sun Jun 19, 2011 15:43 Post subject: |
|
|
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 |
|
|
|
|
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
|