Jump to content

Home

Script help: create & equip weapon on NPC based on PC's alignment


Achilles

Recommended Posts

I tried digging around for my own answer but I just ended up more confused.

 

I'm trying to set up a scenario by which I can create and equip a weapon on Visas after your first encounter. To further complicate the matter, the item created would depend on the alignment of my PC.

 

Specifically, if my PC is LS, Visas would have a green lightsaber when joining my party or a red lightsaber if my PC is DS.

 

I could easily use simpler scripts (such as those found in the scripting forum) to add the respective weapon to my inventory based on dialog choices selected in visasmarr.dlg, but it wouldn't quite be the same.

 

If someone would be willing to take this on or offer some helpful hints, it would be greatly appreciated.

 

TIA

Link to comment
Share on other sites

Something like this maybe:

 

   //NPC to give item to
   object oNPC = GetObjectByTag("npc_tag");
   object oPC = GetFirstPC(); //Player

   //PC's alignment must be 70 or greater
   if(GetGoodEvilValue(oPC) >= 70)
   {
       //Give new item to NPC
       object newItem = CreateItemOnObject("your_uti", oNPC);
       ActionEquipItem(newItem, INVENTORY_SLOT_RIGHTWEAPON, TRUE);
   }
   // PC's alignment must be 30 or less
   else if(GetGoodEvilValue(oPC) <= 30)
   {
       //Give new item to NPC
       object newItem = CreateItemOnObject("your_uti", oNPC);
       ActionEquipItem(newItem, INVENTORY_SLOT_RIGHTWEAPON, TRUE);
   }
   else
   {
       //if none are true do this;
   }

Link to comment
Share on other sites

A good place to do this would be when the real Visas first is spawned into the game (and not the cutscene dummy you fight on the Hawk). This is done in the script a_next_scene. This version has been minimally altered to run a script called "003_equip_visas" when Visas is first spawned.

 

If you recompile the source at the link above and name envida's script "003_equip_visas.ncs" it should work.

 

I am using this technique to replace her awful standard robes with custom ones I've made and it works fine. Though if you use this, replace oNPC with OBJECT_SELF in envida's script, since it it the Visas object that runs the 003_equip_visas script.

 

This is how I do that as comparison, not quite as clean as the one posted above, but it works for me :)

 

// ST: 003_equip_visas.nss

void main() {
   // Force Sensitive, since all the neophytes get it
   GrantFeat(116, OBJECT_SELF);
   // Force Sight... (doh)
   GrantSpell(176, OBJECT_SELF);   

   int nAlign = GetGoodEvilValue(GetFirstPC());
   object oRobe = CreateItemOnObject((nAlign < 50 ? "st_visasrobe02" : "st_visasrobe01"), OBJECT_SELF, 1, TRUE);
   object oSab =  CreateItemOnObject((nAlign < 50 ? "g_w_dblsbr002" : "g_w_dblsbr005"), OBJECT_SELF, 1, TRUE);

   DelayCommand(0.5, ActionEquipItem( oRobe, INVENTORY_SLOT_BODY ));
   DelayCommand(0.5, ActionEquipItem( oSab, INVENTORY_SLOT_RIGHTWEAPON ));
}

Link to comment
Share on other sites

I seem to recall having trouble with 'else if' and 'else' statements when scripting, by which I mean they didn't work. Have you tested that bit of code envida? Logically it looks fine to me, but for some reason I remember my else statements and else if statements not working. Or maybe I forgot a semicolon somewhere and just *thought* it was the else statements...

Link to comment
Share on other sites

I use a a similar one to the one I posted and it is working. I actually have alot of else if/else statements in my current wip mod and they are working fine.

 

If they didnt work for you it is probably as you said some code missing or something along those lines ;)

Link to comment
Share on other sites

Originally posted by stoffe -mkb-

A good place to do this would be when the real Visas first is spawned into the game (and not the cutscene dummy you fight on the Hawk). This is done in the script a_next_scene. This version has been minimally altered to run a script called "003_equip_visas" when Visas is first spawned.

 

If you recompile the source at the link above and name envida's script "003_equip_visas.ncs" it should work.

That is an elegant solution. :thumbsup:

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...