Aller au contenu

Photo

Equipping/changing clothing on an NPC [solved]


  • Veuillez vous connecter pour répondre
9 réponses à ce sujet

#1
BillHoyt

BillHoyt
  • Members
  • 109 messages
I have a simple item-aquisition quest where the hero goes out to kill a monster, picks up a dropped item, then returns it to the quest giver. In this case the item is a set of clothing, which I would like the quest-giver to wear once the quest (or in this case, final dialogue) is complete.  All the plot switches work fine (quest completes, reward is given), everything except the final step of putting on the clothing.

My quest giver NPC (tag:spiderman) has a non-stealable, non-droppable instance of "gen_im_cth_com_c03" in his inventory.

Here is my script, which I am running from the final dialogue line:

#include "plot_h"

object oPC = GetHero();
object oNPC = UT_GetNearestCreatureByTag(oPC, "SPIDERMAN", 0);
object oItem = GetObjectByTag("gen_im_cth_com_c03", 1);

void main()
{
     //Get rid of Spider Man's clothes from PC inventory
     UT_RemoveItemFromInventory(R"spider_man_clothes.uti",1);

     //Equip Spider Man's clothing
      EquipItem(oNPC, oItem);
}

I know it's running, because the recovered clothing is removed from the PC's inventory, it just never "appears" back on the quest giver.  So what am I doing wrong here?

Thanks in advance.

Modifié par BillHoyt, 12 avril 2010 - 05:38 .


#2
Magic

Magic
  • Members
  • 187 messages
Cool, I learned more from your script than the answer requires. :)

- Is the tag really "SPIDERMAN", or rather "spiderman"?
- UT_RemoveItemFromInventory() destroys the item. It does not exactly what the description says, since it has no return value.
- object oItem = GetObjectByTag("gen_im_cth_com_c03", 1);
will return the second item with this tag from the area list's item list. Will you be absolutely sure that this is the one to be equipped? Maybe it just get destroyed? Probably there is only one?
- From my understanding you wanted to write:

#include "plot_h"

object oPC = GetHero();
object oNPC = UT_GetNearestCreatureByTag(oPC, "spiderman", 0);
object oItem = GetObjectByTag("gen_im_cth_com_c03");

void main()
{
     //Get rid of Spider Man's clothes from PC inventory
     MoveItem(oPC, oNPC, oItem);

     //Equip Spider Man's clothing
     EquipItem(oNPC, oItem);
}

- Still, this only works well if there's only one item with tag "gen_im_cth_com_c03". Otherwise you might want to check the PC's inventory for this item.
- ... Spiderman?

Modifié par Magic, 12 avril 2010 - 05:01 .


#3
BillHoyt

BillHoyt
  • Members
  • 109 messages
Problem solved... it was the 1 after GetObjectByTag and probably Spider Man's tag as well. Thanks a million, Spider Man looks so much nicer not standing around in his underoos.



FWIW there was only one instance of "gen_im_cth_com_c03" in the area, but that was not the item recovered. Rather than picking up something and handing it over, I picked up something, destroyed it in my inventory, then equipped one like it that was already hidden in NPC inventory, which provides the same effect. More than one way to skin a nug, I guess.



I appreciate the help. Thanks again

#4
Nattfodd

Nattfodd
  • Members
  • 321 messages
Is it possible to make equipment changes "during" conversation, and not only at the end?

#5
BillHoyt

BillHoyt
  • Members
  • 109 messages
Yes, you can. Just attach the script to the dialogue line that you wish it to be performed during and you'll see the change before the following line appears.

#6
Nattfodd

Nattfodd
  • Members
  • 321 messages
I tried your suggtestion, but it don't works.
Posted Image

During dialogue the owner always is equipped with is starting armor. The equipment change happen however at after dialogue ends (i only unequip its armor and i see it in underwear).

This is the script code:
void main()
{
    object oTarget = GetObjectByTag("target_creature");
    object [] arInv_Equipment = GetItemsInInventory(oTarget, GET_ITEMS_OPTION_EQUIPPED);
    int n_arInventorySize = GetArraySize(arInv_Equipment);
    int ix_Item;
    for(ix_Item = 0; ix_Item 
    {
        UnequipItem(oTarget, arInv_Equipment[ix_Item]);
    }
}

Maybe the only way to have also a visual change of equipment during dialogue is using cutscenes.

Modifié par Nattfodd, 17 avril 2010 - 04:19 .


#7
BillHoyt

BillHoyt
  • Members
  • 109 messages
Hmmm... I was going to ask if you are using cutscenes, but apparently you are not. I am also not using one.

I assume your last line of dialogue is a PC line that says "(continue...)" or some such? Just for testing, try attaching the UnEquiptItem script to the NPC dialogue line that appears immediately before it. My final script (attached below) runs there. The clothing appears on the NPC and there is about a 2-second delay before my final "(continue...)" option appears.

If that does not work, I hope someone with more experience than I can chip in...

#include "plot_h"

object oPC = GetHero();
object oNPC = UT_GetNearestCreatureByTag(oPC, "spiderman", 0);
object oItem = GetObjectByTag("gen_im_cth_com_c03");

void main()
{
//Get rid of Spider Man's clothes from PC inventory
UT_RemoveItemFromInventory(R"spider_man_clothes.uti",1);

//Equip Spider Man's clothing
EquipItem(oNPC, oItem);
}

Modifié par BillHoyt, 17 avril 2010 - 04:50 .


#8
Nattfodd

Nattfodd
  • Members
  • 321 messages
I tried your solution but it stills does not work. I'm not using cutscene as you said.

The dialogue line that is calling the script is in the middle of conversation and it is a line associated to the dialogue's owner.

#9
Magic

Magic
  • Members
  • 187 messages
The script you posted is missing a few things. If there was no mistake in copying the lines, it probably didn't even compile? If the changes still don't work, please check if the script is executed at all.

void main()
{
    object oTarget = GetObjectByTag("target_creature");
    object [] arInv_Equipment = GetItemsInInventory(oTarget, GET_ITEMS_OPTION_EQUIPPED);
    int n_arInventorySize = GetArraySize(arInv_Equipment);
    int ix_Item;

    for(ix_Item = 0; ix_Item < n_arInventorySize; ix_Item++)
    {
        UnequipItem(oTarget, arInv_Equipment[ix_Item]);
    }
}

Edit: Maybe it was just the forum formatting which destroyed it.

Modifié par Magic, 18 avril 2010 - 01:45 .


#10
Nattfodd

Nattfodd
  • Members
  • 321 messages
Yes it was the forum formatting that deleted a part of the code. In fact i don't have problem of compiling but a problem of "when" the unequip happens, not during the dialog as i wish but at the end.