Unable to Run My Scripts


#41

I changed the orbs from cast spell: activate item to cast spell: unique power so I should be able to cast the spell on a companion. From the description above, I would have to right click on the companion 1st, before activating the spell to use

object oTarget = GetPlayerCurrentTarget(GetPCSpeaker());

, is that right?

I’m sorry, I didn’t read everything. If I combined them in one script, I could just use the

 object oTarget = GetItemActivatedTarget();

I am just learning how to use the Dialog Editor, so a lot of this is confusing to me. I’m 67 years old so I don’t learn very quickly if at all. I sure appreciate your help and I will try to absorb it. The only reason I used separate scripts, is because that is the only way I get it to work. Now that I’ve played with it a little bit, it is starting to make sense. I will see what I can do. Thanks again!


#42

not quite that old but old enough to know what you mean.

My last post is just tossing some stuff out there; for example I find GetPlayerCurrentTarget() very useful for debugging and related things like granting items. On the other hand, I’m not so sure how useful GetItemActivatedTarget() would be, since all it can be used for readily is starting the conversation. i mean, sure you could cache it on say the module object and get it in the action-script but there are simpler ways (like using GetPlayerCurrentTarget() in the action-script)

And no i wouldn’t combine the item-activated script with the dialog’s action-script(s) … I was just saying that by using a switch/case in the action-script, all those dialog-scripts could be written in a single file. But go with what you’re comfortable with, and what works – it’s just that you seem to have a natural aptitude, if you want to take things a step further,


#43

Thank you! I appreciate your advice. I have spent several hours yesterday trying to figure how to use switch/case in the action script. I clicked on node and there was no refresh. I looked at all of options on the action tab and did not see anything that looked like it was applicable. So I’m confused! I really like your idea, especially since a lot of the code is duplicated. I guess I just need to know where to pass the iCase value.

Is GetPCSpeaker() always going to be the player? I changed that to OBJECT_SELF in my scripts that are being called from the Orbs, for myself and when given to companions, and they are working correctly, except for OpenInventory(oPC, oPC). That always reverts back to me. I don’t understand that either.

I was thinking of trying:

object oPlayer=GetPCSpeaker();
object oPC=OBJECT_SELF;
OpenInventory(oPC, oPlayer);

Would that work? I have tried GetPrimaryPlayer() and that would compile but nothing would happen.

Thanks again for your help!


#44

the Refresh button (in the dialog editor) should appear after choosing (or typing in) a script for the action-slot, directly to the right of the slot.

dialogeditor_Refeshbtn

// 'gui_trigger_spell_set'
void main(string sSpell)
{
    if (sSpell == "abc")
    {
    }
}

sSpell is an argument that’s passed from the dialog-node to main(). If an int is passed (instead of a string) it can be used by a switch/case – so you could use one script but with a different value specified on each dialog-node

GetPCSpeaker() is usually the player-character, yes. But it is possible to set dialogs/modules/campaigns to allow Companions to do the conversation instead; if so, GetPCSpeaker() would be the Companion. But keeping things simple let’s assume it’s the PC.

OBJECT_SELF is a peculiar concept that takes some getting used to … every script needs to run “on” an object, that object is OBJECT_SELF. It didn’t have to be that way but it’s very convenient.

For scripts that run from a dialog, OBJECT_SELF is the dialog-owner – usually an NPC, but since in your situation the PC is talking to itself, OBJECT_SELF and GetPCSpeaker() are [i believe] the same object. Think of it as coincidence, though, not a necessity.

btw, GetPrimaryPlayer() seems sorta useless in SP:

GetFirstPC(TRUE/FALSE) works instead (aside: i’m sure there are scripters who’d swear by GetPrimaryPlayer() …). anyway, TRUE gets the PC-object, FALSE gets the character currently controlled by the PC-object’s player (either PC or Companion).

It’s hard for me to talk specifics without knowing exactly what you’re doing there. no biggie. But I do think the issues you seem to be having could be solved by using the technique i mentioned previously: use subfunctions that shuffle the owner (ie, OBJECT_SELF) off the PC to the Companion.

that said, I haven’t used OpenInventory() but it looks like a function that might be hampered, having been implemented for Nwn1 – it might work as advertised, but beware that Nwn2 handles party-characters very differently than 1 does. So i’m leary that it might not open a Companion’s inventory at all; or perhaps the player might have to be controlling said Companion for it to work. i don’t know

feel free to post a complete example script & i/we’ll have a look …

not a problem, i enjoy this stuff


#45

This is aces_snakebite.nss and is used in my Equip Ace’s Items Orb (Equips Armor, Archery Weapons, Melee Weapons) and my Equip Melee Weapons Orb. I wanted Neeshka to have the Ace’s Snake Bite Katanas so I passed the Equip Ace’s Items Orb to her.

/******************************

Created by dwharper34 aka AcesHigh

        November 18, 2018

Equips Ace's Snake Bite Katanas on NPC

aces_ka_007      Ace's Snake Bite Katana

     aces_snakebite

******************************/

int CheckItem(string sItemTag, object oPC)
{
 object oCurrentItem;
 int nEquipped;

 //  1st check Equipped Items 

 for(nEquipped=0; nEquipped <= 10; nEquipped++)
 {
  oCurrentItem=GetItemInSlot(nEquipped,oPC);
  {
   if(GetIsObjectValid(oCurrentItem) && sItemTag==GetTag(oCurrentItem))
   {
    return TRUE;
   }
  }
 }

 //  2nd check Inventory Items

 oCurrentItem=GetFirstItemInInventory(oPC);
 while (oCurrentItem != OBJECT_INVALID)
 {
  if (sItemTag==GetTag(oCurrentItem))
  {
   return TRUE;
  }
  oCurrentItem=GetNextItemInInventory(oPC);
 }
 return FALSE;
}

int CreateNewItems(string sItemTag, object oPC, int nQty, int nStackSz)
{
 int nNumMade;
 if (CheckItem(sItemTag, oPC))
 {
  nNumMade=128;
  return nNumMade;
 } 
 else
 {
  if(nQty==0)
  {
   nQty=1;
  }
  nNumMade=0;
  int nIndex;
  for (nIndex=1; nIndex <= nQty; nIndex++)
  {
   object oNewItem=CreateItemOnObject(sItemTag, oPC, nStackSz);
   {
   if(oNewItem==OBJECT_INVALID)
    {
     return FALSE;
    }
    else
    {
     nNumMade++;
    }
   }
  }
  return nNumMade;
 }
}

void AddItems(string sItemTag, string sItemType, int nItemCnt, int nStackSz, object oPC)
{

 object oInvItem;
 object oNewItem=GetObjectByTag(sItemTag,0);
 string sMsg;

 int nCreated=CreateNewItems(sItemTag, oPC, nItemCnt, nStackSz);
 {
  if(nCreated == 128)
  {
   sMsg="Item " + GetName(oNewItem) + " is already Present!";
   DelayCommand(1.0f, FloatingTextStringOnCreature(sMsg, oPC));
  }
  else if(nCreated)
  {
   sMsg=IntToString(nCreated) + sItemType + "Items Added!";
   FloatingTextStringOnCreature(sMsg, oPC);
  }
  else
  {
   FloatingTextStringOnCreature(sItemTag, oPC);
   sMsg="Error . . . No" + sItemType + "Items Added!";
   FloatingTextStringOnCreature(sMsg, oPC);
  }
 }
}

void EquipWeapons(object oPC)
{
 string sAKA7="aces_ka_007";
 ActionUnequipItem(GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oPC));
 ActionUnequipItem(GetItemInSlot(INVENTORY_SLOT_RIGHTHAND, oPC));
 object oItem1=GetObjectByTag(sAKA7,0);
 AssignCommand(oPC, ActionEquipItem(oItem1, INVENTORY_SLOT_RIGHTHAND));
 object oItem2=GetObjectByTag(sAKA7,1);
 AssignCommand(oPC, ActionEquipItem(oItem2, INVENTORY_SLOT_LEFTHAND));
}

void GiveItem(string sOrb, object oPC, object oPlayer)
{
 object oOrb=GetObjectByTag(sOrb,0);
 if (oOrb != OBJECT_INVALID)
 {
  AssignCommand(oPC, ActionGiveItem(oOrb, oPlayer));
 }
}

void main()
{
 object oPC=OBJECT_SELF;
 object oPlayer=GetPCSpeaker();
 string sType;
 int nStackSz;
 string sAKA7="aces_ka_007";
 string sORB1="equipitemsorb";
 string sORB2="equipweaponsorb";

 sType=" Melee ";
 nStackSz=1;
 AddItems(sAKA7, sType, 2, nStackSz, oPC);

 EquipWeapons(oPC);

 GiveItem(sORB1, oPC, oPlayer);
 GiveItem(sORB2, oPC, oPlayer);
 
 OpenInventory(oPC, oPlayer);
}

Everything went as expected and the Orb was given back to me when she was done. The only thing that wasn’t right was my Inventory was opened, not hers. I also tried it on myself and it equipped the weapons correctly, but it changed the Orb position in my inventory like it passed it to me. Not a problem though.

So from what I can tell, it is setting the correct objects until the open inventory. I wonder if this would work:

 AssignCommand(oPC, OpenInventory(oPC, oPlayer));

That’s the only thing I can think of.

Also to keep from passing the Orb to myself, I could try:

void GiveItem(string sOrb, object oPC, object oPlayer)
{
 if (oPC != oPlayer)
 {
  object oOrb=GetObjectByTag(sOrb,0);
  if (oOrb != OBJECT_INVALID)
  {
   AssignCommand(oPC, ActionGiveItem(oOrb, oPlayer));
  }
 }
}

That should prevent it from moving around in my inventory. Anyway, what do you think?


#46

robust scripting, but i think it’s over-complicated for creating and equipping a couple of items.

 
it turns out the engine clears player’s current target when a dialog starts. So here’s what i did

  • create an Orb
  • Unique Power (unlimited uses)
  • plot
  • cursed
  • tag: “ah_orb”
// 'i_ah_orb_ac'
void main()
{
    object oTarget = GetItemActivatedTarget();
    if (GetIsObjectValid(oTarget) && GetObjectType(oTarget) == OBJECT_TYPE_CREATURE)
    {
        object oPc = GetItemActivator();
        if (GetFactionEqual(oPc, oTarget))
        {
            SetLocalObject(GetModule(), "ah_orb_target", oTarget);
            AssignCommand(oPc, ActionStartConversation(oPc, "ah_orb", TRUE, FALSE, TRUE, TRUE));
        }
    }
}
  • create a dialog ‘ah_orb’
  • Neverwinter Nights 1-style Dialog
  • Abort Conversation Script: ‘ah_orb_end’
  • End Conversation Script: ‘ah_orb_end’
    NPC Greeting: do Orb operation
    PC response: equip sickle and shield [ActionScript: ah_orb(0)]
// 'ah_orb'
string _Rh, _Lh; // resrefs

void doTwo();

// ______
// MAIN
void main(int iCase)
{
    object oTarget = GetLocalObject(GetModule(), "ah_orb_target");
    switch (iCase)
    {
        case 0:
            _Rh = "nw_wspsc001"; // sickle
            _Lh = "nw_ashsw001"; // light shield
            AssignCommand(oTarget, doTwo());
            break;
    }
}

//
void doTwo()
{
    ClearAllActions(TRUE);

    object o = CreateItemOnObject(_Rh);
    ActionEquipItem(o, INVENTORY_SLOT_RIGHTHAND);

    o = CreateItemOnObject(_Lh);
    ActionEquipItem(o, INVENTORY_SLOT_LEFTHAND);
}
// 'ah_orb_end'
// clears the local_object
void main()
{
    DeleteLocalObject(GetModule(), "ah_orb_target");
}

It worked on my PC as well as a Companion,

i mean… if you want to keep the fancy stuff regarding whether target already has the items, stacksize, messages and whatnot, you may have reasons for it. I’m just saying the above layout worked for me, to create and equip two items (on party-member(s) with the required proficiencies).


but i didn’t investigate the OpenInventory() thing …
and to be honest I don’t get why you’re passing Orbs around: basically, if you do it similar to above, just target Neeshka and tell her to create and equip a couple of katanas …


#47

I am trying to understand, but it may take some time. The reason I have item checks is because I switch Armor a lot, and I want to use this to equip it, but not duplicate it. It will add it if I don’t have it though, but items such as jewelry and some items like cloaks are duplicated in all of the armor sets.

I am having a problem though. I want my dialog to work correctly, so I can set up a tree to be able to set variables before I change it a switch method. My problem is I have set up branches, but they are not being accessed. On the picture below all of the options are available:

Now on the picture below, I have several problems:

Under “Miscellaneous”, I have added some cheats, but only the first option, “Find a new Ore Vein!”, will be visible in the game and when I click it, it will run “Click Here to Find New Ore Deposits!” automatically without even clicking that. I am probably having the same problem with the other items on that branch, but haven’t been able to check them yet. I added gc_node(0) to “Miscellaneous” without really knowing what it does and decided it would be better to ask you for help. Help!

Under “Unequip and Remove Items” / “Which Items would you like to Remove?”, when I choose “Equip and Removal Orbs”, it automatically runs “Remove All Orbs” without giving me the other options. I thought that everything on a branch would act like a question, but I was wrong. Is it automatically running because of the “/Start” option. I thought it needed that to let it know I was finished.

What am I doing wrong? I have looked at several tutorials, but they don’t explain themselves well enough for me to understand. As always, any help would be appreciated!


#48

k. The red nodes are NPC-nodes and the blue nodes are Player-nodes.

Starting at the top of the tree, things run in sequence, one node to the next, delayed only by waiting for the player to click a blue node.

so the engine automatically chooses the first red node at each level of the tree. Then waits for the player to select a blue node.

Which means that an action-script on a red node runs automatically, while an action-script on a blue node runs only after player selects that node.

(advanced: Conditional scripts can be used to bypass a first red NPC node and try the second, third, etc. [think, fallthrough])

So basically you want your scripts only on blue nodes. The red NPC nodes should be used only for guidance throughout the conversation. The actions ought happen only when player clicks a blue node. (This is not strictly true, but it’s certainly the way I’d set it up.)

ps. “</Start>” strikes me as entirely unnecessary.
pps. gc_node() is a specialty script for use with speak-triggers and is also unnecessary.

 
For example, under Miscellaneous, things should rather look like this:

(blue)Miscellaneous
(red)What sort of miscellaneous?
(blue)Find a new ore deposit
(blue)raise party limit
(blue)50000 gold!
(blue)show roster screen
(blue)I need to talk to the DM.

and the same idea should happen under Unequip and Remove Items …


#49

Thanks. I think I just figured it out. I rearranged some items in the picture below:

Does that look better? I was just about to give it a try. You just confirmed what I had guessed! Thank you!


#50

looks good  :)

 
 
edit but What is </Start> for


#51

OK. I’ve removed gc_node() and all of the “/Starts”. By the way, when I used the brackets /Start disappeared even with the quotes. How did you get it to display?


#52

\</Start>


#53

Thanks. By the way, I don’t know if you noticed my NOTE earlier about my scripts running now. They seemed to start when I first started using the orbs. I haven’t played with them much because they seem to undependable, even though they are the same scripts I’m using with the Orbs. You mentioned some time ago about possibly having to use runscript instead of rs and I have found that sometimes I have to do that, but not always. I wonder why they just started working.

I had just completed the Dragon Plate Armor Orb and before I ran it, I tried running the script. It said it was unsuccessful. But when I went to run the Orb, I was wearing the Dragon Plate Armor and when I looked at the screen it said the script was successful. I wasn’t sure what had happened and I still don’t. Something is strange. Sometimes they will run and other times they won’t. Anyway … Talk to you later!


#54

Happy Thanksgiving!

Do you see any reason why I can’t target an orb on an NPC, like Bishop, and remove any armor I gave them, before they betray me?


#55

… if the orb works only on party-members, you’d have to remove the stuff before they leave the party


#56

I thought you could select an NPC or item with the spell “Activate Item (Long Range)”.


#57

Are you saying you can’t target an NPC …

or that you can, but the script fails?


#58

No, Assuming that if I can target an NPC, would I be able to take the items from them if they were no longer in my party or does their inventory become locked somehow?


#59

there’s no locking that I’m aware of.

edit: You might have to be wary of whether your target becomes hostile/non-hostile (since spells tend to target one OR the other) … but i can’t say offhand if/how this may relate to an Orb (and its targeting behavior)

tests req’d


#60

I always take the equipment I gave Bishop right after the Circle of the Mere Mission. I do give him his original equipment though. It doesn’t require a script.