Using a variable in a conversation

So I think this could be solved through custom tokens, but I’m not sure how to do it.

What I want is to print a changing variable in a conversation. I’ve made an NPC skill trainer that charges 10000 GP the first time he’s used, 20000 GP the second time, 30000 GP the third time, and so on. All I want to do is have the current cost of his services show in his dialogue, so players won’t just lose money without an explanation.

I’m currently implementing this by using the following bit of script, with ‘costcheck’ starting at 0:

// Set a local integer.
nValue = GetLocalInt(oPC, "costcheck") + 1;
SetLocalInt(oPC, "costcheck", nValue);

// Take int x 10000 gold from the PC.
TakeGoldFromCreature((nValue * 10000), oPC, TRUE);

How should I go about doing this?

Here’s a tutorial.

Sadly, I am too dim to easily follow that. :frowning:

I’ve already tried several implementations based on that page and none of them worked, so I think I’m just not getting it. Thank you for trying to help, though! I appreciate it.

The script you shared is the ActionsTaken script for the conversation?
However, you need to declare the Custom Token in the TextAppearsWhen script slot.

[code]
// Set a local integer.
nValue = GetLocalInt(oPC, “costcheck”) + 1;

 // Take int x 10000 gold from the PC.
 int nAmount = (nValue * 10000)
 //turn it into a string
 string sAmount = IntToString(nAmount);
 //Set Token - lets us 9999, but replace with whatever number 
 //you are putting in the conversation
 SetCustomToken(9999, sAmount);
 ----------------[/code]

Then in the line of conversation you have the trainer say “I will charge you .”
edited repeatedly because I have no idea how to format this correctly - sorry

2 Likes

You can format using bbcode. For example, you’d use code… /code around each block of nwscript (with square brackets) to separate it from the narrative text of your reply.

Alternatively hightlight your code and press the </> button at the top of the editing window. That is for
pre-formatted text. It’s one of the things I mentioned in the pinned short tour thread.

TR

The bbcode method offers more sophisticated formatting for nwscript.

Using pre-formatting </>

  if (nStep < HIGH)
    SetLocalInt(GetModule(), "DanceStep", nStep + 1);

  switch (nStep)
    {
        case 0:   // Initial setup
                  GestaltInvisibility(fTimer, oPC);
                  SetLocalString(oPC, "DialogControl", "FaywoodDialog");
                  bhJumpCamera("WP_FaywoodPC");
                  AssignCommand(oPC, GestaltCameraCrane(1.0, GetFacing(GetObjectByTag("WP_FaywoodPC")), 0.0, fPitch, 1.5,
                                                             GetFacing(GetObjectByTag("WP_FaywoodPC")), 0.0, fPitch, 1.5,
                                                             1., 30., oPC, 1));
                  fDelay = 3.0;
                  break;

Using bbcode

  if (nStep < HIGH)
    SetLocalInt(GetModule(), "DanceStep", nStep + 1);

  switch (nStep)
    {
        case 0:   // Initial setup
                  GestaltInvisibility(fTimer, oPC);
                  SetLocalString(oPC, "DialogControl", "FaywoodDialog");
                  bhJumpCamera("WP_FaywoodPC");
                  AssignCommand(oPC, GestaltCameraCrane(1.0, GetFacing(GetObjectByTag("WP_FaywoodPC")), 0.0, fPitch, 1.5,
                                                             GetFacing(GetObjectByTag("WP_FaywoodPC")), 0.0, fPitch, 1.5,
                                                             1., 30., oPC, 1));
                  fDelay = 3.0;
                  break;

Here is a list of which bbcode is supposed to work. Tried to get the markdown equivalent to [code][/code] to work but it doesn’t seem to. Couple of things mentioned in this thread that would be nice to have but they involve plug-ins we apparently don’t have installed.

TR

Markdown code syntax works fine. Just make sure you put the ``` on separate lines before and after.

Thank you so much! This fixed my issue, which was that I wasn’t converting the integer into a string.

1 Like