Note: LucasForums Archive Project
The content here was reconstructed by scraping the Wayback Machine in an effort to restore some of what was lost when LF went down. The LucasForums Archive Project claims no ownership over the content or assets that were archived on archive.org.

This project is meant for research purposes only.

Scripts to Remove Items/ Unequip NPCs

Page: 1 of 1
 Darkkender
11-29-2004, 1:30 AM
#1
Ok new question. would I use a script similiar to the give/take gold command to have items removed from an inventory slot. example would be when your in the sandpeople enclave and they take away the sandpeople robes the item gets taken right out of your inventory slot. I realize it's a disguise however unlike the spacesuit and underwater pressuresuit you actually have to put the disguise on. Now I'm assuming it makes a call to the specific spot on your body where clothes are at I'm also curious what the other body part numbers are so items can have a scripted removal from there as well?
 Darth333
11-29-2004, 4:14 AM
#2
I splitted the thread. When starting a new subject, please make a different thread, otherwise it gets too messy.

Now, I am not sure of what you want to do. Do you want to remove a disguise effect, simply unequip a npc or also remove the item from inventory?

Here is a script to simply unequip a NPC.

void main ()
{

object oNPC = GetObjectByTag("my_npc");
object oArmor = GetItemInSlot(INVENTORY_SLOT_BODY,oNPC);
AssignCommand(oNPC, ActionUnequipItem(oArmor, TRUE));
}


Other body slots:

int INVENTORY_SLOT_HEAD = 0;
int INVENTORY_SLOT_BODY = 1;
int INVENTORY_SLOT_HANDS = 3;
int INVENTORY_SLOT_RIGHTWEAPON = 4;
int INVENTORY_SLOT_LEFTWEAPON = 5;
int INVENTORY_SLOT_LEFTARM = 7;
int INVENTORY_SLOT_RIGHTARM = 8;
int INVENTORY_SLOT_IMPLANT = 9;
int INVENTORY_SLOT_BELT = 10;
int INVENTORY_SLOT_CWEAPON_L = 14;
int INVENTORY_SLOT_CWEAPON_R = 15;
int INVENTORY_SLOT_CWEAPON_B = 16;
int INVENTORY_SLOT_CARMOUR = 17;


To remove a disguise effect, you woulf use the followin:

RemoveEffect(object oCreature, effect eEffect);


and finally to remove from inventory, check the script I posted in this thread: http://www.lucasforums.com/showthread.php?s=&threadid=129600) (thread is about regeneration but the script can be used for any item)
 tk102
11-29-2004, 4:17 AM
#3
Ssomething like this:
void main () {
object oPC=GetFirstPC();
object oNPC=GetObjectByTag("npc_tag");
object oItem=GetItemInSlot(nSlot, oPC);
if (GetTag(oItem)=="certaintag") {
// one of the following

AssignCommand(oNPC,ActionTakeItem(oItem,oPC));

// or

AssignCommand(oPC,ActionUnequipItem(oItem));

//or
DestroyObject(oItem);
}
}
 Darkkender
11-29-2004, 5:13 AM
#4
thanks this is going to come in handy.

what i'm going to do is insert this into the add remove character scripts so that custom equipment or upgraded equipment is not lost when my recruit characters fill there space. the reason is because the utc's are not saving the game data for this same as for the levelup process. I've actually been thinking about adding a script to attach to trigger points to counteract some glitches that I don't like.

but on topic here in the GetItemInSlot command can I replace INVENTORY_SLOT_BODY with the number you provided for the integers Darth333?
 Darkkender
11-29-2004, 12:55 PM
#5
Originally posted by tk102
Ssomething like this:
void main () {
oPC=GetFirstPC();
oNPC=GetObjectByTag("npc_tag");
object oItem=GetItemInSlot(nSlot, oPC);
if (GetTag(oItem)=="certaintag") {
// one of the following

AssignCommand(oNPC,ActionTakeItem(oItem,oPC));

// or

AssignCommand(oPC,ActionUnequipItem(oItem));

//or
DestroyObject(oItem);
}
}

Ok I tried Darth333's script sample above and so far it hasn't worked now I noticed there is a diiference in the variables of the
ActionUnequipItem command darth's has a TRUE statement after the object while tk's only has the object. Now the scripts are compiling just not working in game. I have tried it both with the slot number's in the object scripts and the full INVENTORY_SLOT_BODY type of entry with neither yeilding results.

Also Tk I noticed you use a oPC definition at the beginning wouldn't that only be needed for centering on my PC and effecting it?

and one last question do you need to use the if command that you provided or is that just there as a alternate option when running the script?
 tk102
11-29-2004, 1:20 PM
#6
...ActionUnequipItem command darth's has a TRUE statement ...
Take a look at the nwscript.nss file. You'll see:
// 33: Unequip oItem from whatever slot it is currently in.
void ActionUnequipItem( object oItem, int bInstant = FALSE );
That's the definition of the function -- Darth333 passed a TRUE value to bInstant while I let it default to FALSE. It isn't documented whether it has any effect or not and I've used it successfully with FALSE.

Also Tk I noticed you use a oPC definition at the beginning wouldn't that only be needed for centering on my PC and effecting it?

and one last question do you need to use the if command that you provided or is that just there as a alternate option when running the script?

I wasn't sure how you were going to use the script. I tossed the oPC and oNPC in for clarity and shorthand. The if statement is used to evaluate whether the item you're about to unequip is the item you're expecting. Again, I didn't know how you were going to use the script. And you should only use one of the statements that follow the if statement.

My script assumed the PC would have the item equipped and that you would either
a) take the item from PC and give it to the NPC,
b) unequip the item from the PC or
c) Destroy the item. (Not sure the DestroyObject will work on an inventory item.)
 Darkkender
11-29-2004, 1:39 PM
#7
okay a couple more questions have formed I'm assuming I still need to use the object command before oPC and oNPC correct?

now the oItem I would still need to replace Item with whatever word i choose like armor for body slot, gauntlet for hands etc. correct?

As to clarity of what I'm trying to do.

When I activate my Replace original NPC with new recruit script I am trying to take all of the equipment off of the original NPC and return it to inventory instead of it disappearing completly and never being available again. This would be useful for anybody developing a custom recruit as it allows you to keep what you sometimes have saved up for to buy. Especially if you recruit somebody new that can use that equipment and you have that NPC destroyed before you get a chance to unequip them.

Thanks for all the help insofar
 tk102
11-29-2004, 6:21 PM
#8
I am trying to take all of the equipment off of the original NPC and return it to inventory instead of it disappearing completly and never being available again.
I believe this script will serve the purpose

void UnEquip(object oNPC,int nSlot) {
//subroutine to unequip each item

object oItem=GetItemInSlot(nSlot,oNPC);
if (GetIsObjectValid(oItem)) {
AssignCommand(oNPC,ActionUnequipItem(oItem));
}
return;
}

void main () {
// replace "npc_tag" with whatever
object oNPC=GetObjectByTag("npc_tag");

UnEquip(oNPC,INVENTORY_SLOT_HEAD);
UnEquip(oNPC,INVENTORY_SLOT_BODY);
UnEquip(oNPC,INVENTORY_SLOT_HANDS);
UnEquip(oNPC,INVENTORY_SLOT_RIGHTWEAPON);
UnEquip(oNPC,INVENTORY_SLOT_LEFTWEAPON);
UnEquip(oNPC,INVENTORY_SLOT_LEFTARM);
UnEquip(oNPC,INVENTORY_SLOT_RIGHTARM);
UnEquip(oNPC,INVENTORY_SLOT_IMPLANT);
UnEquip(oNPC,INVENTORY_SLOT_BELT);

// these are not necessary

// UnEquip(oNPC,INVENTORY_SLOT_CWEAPON_L);
// UnEquip(oNPC,INVENTORY_SLOT_CWEAPON_R);
// UnEquip(oNPC,INVENTORY_SLOT_CWEAPON_B);
// UnEquip(oNPC,INVENTORY_SLOT_CARMOUR);
return;
}

I'm assuming I still need to use the object command before oPC and oNPC correct?Yes. object is a declaration of a variable of type object. It is needed. (And yes I've edited my scripts to include it.)
 Darkkender
11-30-2004, 2:24 PM
#9
Ok I have implemented your latest version above and it compiles fine just like always but it still does not seem to work here is the script maybe you can tell me what I'm missing or need to change in order to get it to work.


void UnEquip(object oNPC,int nSlot)
{
//subroutine to unequip each item

object oItem=GetItemInSlot(nSlot,oNPC);
if (GetIsObjectValid(oItem))
{
AssignCommand(oNPC,ActionUnequipItem(oItem));
}
return;
}

void main ()
{
// replace "npc_tag" with whatever
object oNPC=GetObjectByTag("Bastila");
string sTemplate = "darkkendera";

UnEquip(oNPC,INVENTORY_SLOT_HEAD);
UnEquip(oNPC,INVENTORY_SLOT_BODY);
UnEquip(oNPC,INVENTORY_SLOT_HANDS);
UnEquip(oNPC,INVENTORY_SLOT_RIGHTWEAPON);
UnEquip(oNPC,INVENTORY_SLOT_LEFTWEAPON);
UnEquip(oNPC,INVENTORY_SLOT_LEFTARM);
UnEquip(oNPC,INVENTORY_SLOT_RIGHTARM);
UnEquip(oNPC,INVENTORY_SLOT_IMPLANT);
UnEquip(oNPC,INVENTORY_SLOT_BELT);
RemovePartyMember(0);
RemoveAvailableNPC(0);
DestroyObject(oNPC);
AddAvailableNPCByTemplate(0, sTemplate);
return;
}


At this point I'm sure I have something wrong I just can't see it.

*edit* removed superfulous code.
 tk102
12-01-2004, 1:59 PM
#10
Ok I have implemented your latest version above and it compiles fine just like always but it still does not seem to work here is the script maybe you can tell me what I'm missing or need to change in order to get it to work.

Hmm.. works for me...
I did this void UnEquip(object oNPC,int nSlot)
{
//subroutine to unequip each item

object oItem=GetItemInSlot(nSlot,oNPC);
if (GetIsObjectValid(oItem))
{
AssignCommand(oNPC,ActionUnequipItem(oItem));
}
return;
}

void main ()
{
// replace "npc_tag" with whatever
object oNPC=GetObjectByTag("Carth");
string sTemplate = "c_dewback"; //what the hell...

UnEquip(oNPC,INVENTORY_SLOT_HEAD);
UnEquip(oNPC,INVENTORY_SLOT_BODY);
UnEquip(oNPC,INVENTORY_SLOT_HANDS);
UnEquip(oNPC,INVENTORY_SLOT_RIGHTWEAPON);
UnEquip(oNPC,INVENTORY_SLOT_LEFTWEAPON);
UnEquip(oNPC,INVENTORY_SLOT_LEFTARM);
UnEquip(oNPC,INVENTORY_SLOT_RIGHTARM);
UnEquip(oNPC,INVENTORY_SLOT_IMPLANT);
UnEquip(oNPC,INVENTORY_SLOT_BELT);
RemoveFromParty(oNPC); // I like this function more
RemoveAvailableNPC(2); //2 for Carth
DestroyObject(oNPC);
AddAvailableNPCByTemplate(2, sTemplate);
return;
}
 Darkkender
12-02-2004, 3:13 PM
#11
void UnEquip(object oNPC,int nSlot)
{
//subroutine to unequip each item

object oItem=GetItemInSlot(nSlot,oNPC);
if (GetIsObjectValid(oItem))
{
AssignCommand(oNPC,ActionUnequipItem(oItem));
ActionTakeItem(oItem, oNPC);//this is all i needed for a resolution
}
return;
}

void main ()
{
// replace "npc_tag" with whatever
object oNPC=GetObjectByTag("Carth");

UnEquip(oNPC,INVENTORY_SLOT_HEAD);
UnEquip(oNPC,INVENTORY_SLOT_BODY);
UnEquip(oNPC,INVENTORY_SLOT_HANDS);
UnEquip(oNPC,INVENTORY_SLOT_RIGHTWEAPON);
UnEquip(oNPC,INVENTORY_SLOT_LEFTWEAPON);
UnEquip(oNPC,INVENTORY_SLOT_LEFTARM);
UnEquip(oNPC,INVENTORY_SLOT_RIGHTARM);
UnEquip(oNPC,INVENTORY_SLOT_IMPLANT);
UnEquip(oNPC,INVENTORY_SLOT_BELT); return;
}

Ok Here is what I ended up doing above. I found since I was launching the script from a dialogue as one big package that was where my problem was at, since there seems to be a built in delay for the unequip function above. So I actually set my dialogue up as having this launched before my add/remove script gets launched and I added that ActionTakeItem command in the UnEquip function and it worked like I was hoping. I'll try this as a combined script for the heck of it but I just figured I'd pass on my solution.
 Xavier2
12-05-2004, 1:40 PM
#12
I have this script:

void main () {
object oPC=GetFirstPC();

object oItem=GetItemInSlot(nSlot, oPC);
if (GetTag(oItem)=="plot_item") {
// one of the following

AssignCommand(oPC,ActionUnequipItem(oItem));

}
What should be the nSlot if we are talking about a non usable item?
 Darkkender
12-05-2004, 2:35 PM
#13
Originally posted by Xavier2
I have this script:

What should be the nSlot if we are talking about a non usable item?

If an item is non-useable then the script you have would not apply to the nSlot factor because it would not be equipped on the body. You would just want to use the ActionTakeItem command.
 tk102
12-05-2004, 2:37 PM
#14
And refer to Darth333's last post in this (http://www.lucasforums.com/showthread.php?s=&threadid=130821) thread as she describes how Bioware scripted checks for possessed, but not equipped, items.
 Xavier2
12-05-2004, 4:14 PM
#15
Ok. I used this code:
void main ()
{
object oPC=GetFirstPC();
object oItem=GetObjectByTag("plot_item");{
AssignCommand(oPC,ActionUnequipItem(oItem));
}
}
It is compiling ok, but it is not working. What am i doing wrong?
 Darth333
12-05-2004, 4:26 PM
#16
You have to specify in what slot you want to equip the item. Check my first post in this thread to get the possible slots.
 Xavier2
12-05-2004, 4:49 PM
#17
Originally posted by Darth333
You have to specify in what slot you want to equip the item. Check my first post in this thread to get the possible slots.
I don't want to equip. I want to unequip. And since it is a plot item none of the list in your post is a valid slot for plot items (at least i think so:D ). This script was just my poor attempt to build a script based in the functions mentioned above... :p Any other ideas?
 tk102
12-05-2004, 4:52 PM
#18
Xavier2 said:What should be the nSlot if we are talking about a non usable item?
to which Darkkender repliedIf an item is non-useable then the script you have would not apply to the nSlot factor because it would not be equipped on the body. You would just want to use the ActionTakeItem command.
So what DK is saying is that if an item isn't usable, that is non-equippable, then you don't use the ActionUnequipItem function-- use the ActionTakeItem function which doesn't use a slot.
 Xavier2
12-05-2004, 5:01 PM
#19
Originally posted by tk102
Xavier2 said:
to which Darkkender replied
So what DK is saying is that if an item isn't usable, that is non-equippable, then you don't use the ActionUnequipItem function-- use the ActionTakeItem function which doesn't use a slot.
Oh my! Now i see...Thanks tk102 and sorry for my :nut:
 Darth333
12-05-2004, 5:29 PM
#20
Oops, I was actually on something else and I totally misread your request :D Well you got your answer :)
Page: 1 of 1