Howdy
1) I want an NPC to buy fnords from players. A player goes off and collects fnords, and when she speaks to the npc again there will be a conversation node "I have fnords to sell". Obviously the script will need to count the fnords in the pcs inventory, delete them and reimburse the pc accordingly. This is pretty Stone Age stuff, but not something I've done before.. Anyone got the relevant scripts I could steal so I don't have to waste 3 days trying to figure out how to do it?
2) Let's say an npc can only cast the Detect Fnord spell twice a day. If I set a local variable that includes the game date that increments each time the spell is cast so that the npc cannot cast the spell when the variable > 2 will that be reset when the mod is restarted? I'm guessing yes, but wanted to check.
Tnd (The Noob DM)
Script Noobery #2
- Teric neDhalir
- Githyanki
- Posts: 1495
- Joined: Mon Jan 05, 2004 10:04 pm
- Location: Manchester UK
Gah! Been too long since I've touched the toolset.
This should do the trick for number 1, where the fnords tag is "fnord" and you are rewarding 3gp per fnord
Regarding number 2, I believe you are right.
This should do the trick for number 1, where the fnords tag is "fnord" and you are rewarding 3gp per fnord
Code: Select all
void main()
{
object oPC = GetPCSpeaker();
int nItems = 0;
object oItem = GetFirstItemInInventory(oPC);
while (GetIsObjectValid(oItem) == TRUE)
{
if (GetTag(oItem) == "fnord")
{
nItems = nItems + GetNumStackedItems(oItem);
DestroyObject(oItem);
oItem = GetNextItemInInventory(oPC);
}
}
int nGold = nItems *3;
GiveGoldToCreature(oPC, nGold);
}
< Signature Free Zone >
- Teric neDhalir
- Githyanki
- Posts: 1495
- Joined: Mon Jan 05, 2004 10:04 pm
- Location: Manchester UK
- ç i p h é r
- Retired
- Posts: 2904
- Joined: Fri Oct 21, 2005 4:12 pm
- Location: US Central (GMT - 6)
Local variables are not persistent across module resets. If you want variables to be persistent, use one of these functions:
http://www.alandfaraway.org/docs/Techni ... ersistence
FYI. This article is linked off the main Wiki tech node (called Data Persistence under the For Scripters heading). There are lots of useful bits of information up there for your perusal so visiting it periodically is something I highly recommend you do as you roll up your sleeves.
p.s. You might want to consider adopting a well designed quest system off the vault (or help us develop ALFA's) to handle these kinds of things. You'll spend more of your time building quests, less on script noobery, and hopefully keep your module free of ill conceived scripts.
p.p.s. If you're trying to learn how to script, I think that's great! As you probably already know, the lexicon is invaluable for learning the ropes and understanding how the scripting engine works. Most of it will only come with time and practice, however.
http://www.alandfaraway.org/docs/Techni ... ersistence
FYI. This article is linked off the main Wiki tech node (called Data Persistence under the For Scripters heading). There are lots of useful bits of information up there for your perusal so visiting it periodically is something I highly recommend you do as you roll up your sleeves.
p.s. You might want to consider adopting a well designed quest system off the vault (or help us develop ALFA's) to handle these kinds of things. You'll spend more of your time building quests, less on script noobery, and hopefully keep your module free of ill conceived scripts.

p.p.s. If you're trying to learn how to script, I think that's great! As you probably already know, the lexicon is invaluable for learning the ropes and understanding how the scripting engine works. Most of it will only come with time and practice, however.
I'd add Lilac Soul's to that list. With that and the lexicon it makes basic scripting relatively simple.ç i p h é r wrote:p.p.s. If you're trying to learn how to script, I think that's great! As you probably already know, the lexicon is invaluable for learning the ropes and understanding how the scripting engine works. Most of it will only come with time and practice, however.
< Signature Free Zone >
- Teric neDhalir
- Githyanki
- Posts: 1495
- Joined: Mon Jan 05, 2004 10:04 pm
- Location: Manchester UK
Rotku,
Sorry, that didn't work
A bit of playing around and invoking Lilac Soul gives me this, which seems to be ok (giving 5 gold and 10XP per fnord):
I find it hard to believe that we can't build a library of such simple functions after all the years people have been working on NWN! Or maybe I'm not looking in the right place.
Teric
Sorry, that didn't work

Same words, different order. God, I hate scripting.// Reward PC for each copy of item with tag "fnord"
// they have in their inventory.
// Fired from conversation node after checking for presence of item
// with gc_check_item and sItem = "fnord"
// Teric neDhalir 060907
void main()
{
object oPC = GetPCSpeaker();
int nItems = 0;
object oItem = GetFirstItemInInventory(oPC);
while (GetIsObjectValid(oItem))
{
if (GetTag(oItem)=="fnord")
{DestroyObject(oItem);
nItems = nItems + 1;}
oItem = GetNextItemInInventory(oPC);
}
int nGold = nItems*5;
int iXP = nItems*10;
GiveGoldToCreature(oPC, nGold);
GiveXPToCreature(oPC, iXP);
}
I find it hard to believe that we can't build a library of such simple functions after all the years people have been working on NWN! Or maybe I'm not looking in the right place.
Teric
- ç i p h é r
- Retired
- Posts: 2904
- Joined: Fri Oct 21, 2005 4:12 pm
- Location: US Central (GMT - 6)
I'm sure you'll find code you can scavenge from NWN1 mods, but there hasn't been a concerted effort to construct a library of scripts. We've got a spot for them in our repository though [if you wish to contribute].
IMPORTANT NOTE: If you intend to grant XP via custom scripts, be advised that you can only use the following function to do it. Anything else will result in an error or retraction of the XP given:
You will also need the following line at/near the top of your script.
Just a heads up.
p.s. I just added this to the Wiki "rewarding experience" script article so we have something in there.
IMPORTANT NOTE: If you intend to grant XP via custom scripts, be advised that you can only use the following function to do it. Anything else will result in an error or retraction of the XP given:
Code: Select all
void ACR_GiveXPToPC(object oPC, int nXpAmount);
Code: Select all
#include "acr_xp_i"
p.s. I just added this to the Wiki "rewarding experience" script article so we have something in there.