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.

[TSL] Problem with unequip script

Page: 1 of 1
 shockix
03-14-2008, 8:22 PM
#1
Hi.

I created a script to unequip npc's items :

void UnEquip(int iSlot,object oNpc )
{
object oItem = GetItemInSlot( iSlot, oNpc);
AssignCommand(oNpc, ActionUnequipItem(oItem));
}

void main()
{

object oNpc = GetObjectByTag(GetScriptStringParameter());

UnEquip( INVENTORY_SLOT_HEAD, oNpc);
UnEquip( INVENTORY_SLOT_BODY, oNpc);
UnEquip( INVENTORY_SLOT_HANDS, oNpc);
UnEquip( INVENTORY_SLOT_RIGHTWEAPON, oNpc);
UnEquip( INVENTORY_SLOT_LEFTWEAPON, oNpc);
UnEquip( INVENTORY_SLOT_LEFTARM, oNpc);
UnEquip( INVENTORY_SLOT_RIGHTARM, oNpc);
UnEquip( INVENTORY_SLOT_IMPLANT, oNpc);
UnEquip( INVENTORY_SLOT_BELT, oNpc);
UnEquip( INVENTORY_SLOT_RIGHTWEAPON2, oNpc);
UnEquip( INVENTORY_SLOT_LEFTWEAPON2, oNpc);
}

This script is attached to an end node (in a dlg file) and is supposed to unequip all the items of the Npc I was talking to.

But it doesn't work. In fact, items remain equipped. But if I click on the npc and make him the new party leader, all his items are unequipped.

Any idea ?
 stoffe
03-15-2008, 6:51 AM
#2
I created a script to unequip npc's items :

This script is attached to an end node (in a dlg file) and is supposed to unequip all the items of the Npc I was talking to.

But it doesn't work. In fact, items remain equipped. But if I click on the npc and make him the new party leader, all his items are unequipped.


Might be that the game does something with characters when exiting dialog mode. You could try delaying the unequipping a little and clear their action queue and see if that makes a difference. Like:


void UnEquip();
int GetNextEquipSlot(int iCurrent);


// ST: Main function
void main() {
object oNPC = GetObjectByTag( GetScriptStringParameter() );
DelayCommand(1.0, AssignCommand(oNPC, UnEquip()));
}


// ST: Support function - unequip everything in all non-monster item slots
void UnEquip() {
int i;

ClearAllActions();

for (i = INVENTORY_SLOT_HEAD; i <= INVENTORY_SLOT_LEFTWEAPON2; i = GetNextEquipSlot(i)) {
if (GetIsObjectValid(GetItemInSlot(i))) {
ActionUnequipItem( GetItemInSlot(i), TRUE);
}
}
}


// ST: Utility function - get the next non-monster item slot in sequence
int GetNextEquipSlot(int iCurrent) {
switch (iCurrent) {
case INVENTORY_SLOT_HEAD : return INVENTORY_SLOT_BODY;
case INVENTORY_SLOT_BODY : return INVENTORY_SLOT_HANDS;
case INVENTORY_SLOT_HANDS : return INVENTORY_SLOT_RIGHTWEAPON;
case INVENTORY_SLOT_RIGHTWEAPON : return INVENTORY_SLOT_LEFTWEAPON;
case INVENTORY_SLOT_LEFTWEAPON : return INVENTORY_SLOT_LEFTARM;
case INVENTORY_SLOT_LEFTARM : return INVENTORY_SLOT_RIGHTARM;
case INVENTORY_SLOT_RIGHTARM : return INVENTORY_SLOT_IMPLANT;
case INVENTORY_SLOT_IMPLANT : return INVENTORY_SLOT_BELT;
case INVENTORY_SLOT_BELT : return INVENTORY_SLOT_RIGHTWEAPON2;
case INVENTORY_SLOT_RIGHTWEAPON2: return INVENTORY_SLOT_LEFTWEAPON2;
case INVENTORY_SLOT_LEFTWEAPON2 : return 999;
}
return 999;
}
 shockix
03-15-2008, 7:02 AM
#3
Thanks for your answer.

I usually tried to delay the command. It was my first idea. I thought that the dialog had to be over for the unequip command to works.
Unfortunately, this didn't work. I already have to click on the npc for him to be unequipped.

I know there is a way. When you fight with Handmaiden in the Ebon Hawk, all her items are unequipped without you taking her control.
I tryed Dencs to decompile the script that seems to unequip her but it failed.
 stoffe
03-15-2008, 7:34 AM
#4
I know there is a way. When you fight with Handmaiden in the Ebon Hawk, all her items are unequipped without you taking her control.
I tryed Dencs to decompile the script that seems to unequip her but it failed.

You mean this script, or another?

a_hand_fight:

// ST: a_hand_fight.nss (003EBO_s.rim)

#include "k_inc_hawk"

// ---------------------------------------------------------------
// ST: Function prototypes
// ---------------------------------------------------------------
void AttackPlayer(object oAttacker);


// ---------------------------------------------------------------
// ST: Main Function - run from Handmaiden's dialog.
// ---------------------------------------------------------------
void main() {
object oPC = GetFirstPC();
object oMaiden;
object oSomething;
int nParam = GetScriptParameter(1);

oMaiden = GetObjectByTag("Handmaiden");

SetLocalBoolean(oMaiden, 26, FALSE);
SetLocalBoolean(oMaiden, 27, FALSE);
SetLocalBoolean(oMaiden, 29, FALSE);
SetLocalBoolean(oMaiden, 28, TRUE);

int i = 0;

SetMinOneHP(oPC, TRUE);

switch (nParam) {
case 0: {
SetGlobalFadeOut();
SetGlobalFadeIn(0.5, 2.0);

object oDoor = GetObjectByTag("CargoDoor");
AssignCommand(oDoor, ActionCloseDoor(oDoor));
SetLocked(oDoor, TRUE);

for (i = 0; i < 12; i++) {
ChangeToStandardFaction(GetObjectByTag(GetNPCTag(i )), STANDARD_FACTION_NEUTRAL);
}

AssignCommand(oPC, ActionJumpToObject(GetObjectByTag("WP_HANDFIGHT_PC")));
AssignCommand(oPC, ClearAllEffects());

GiveItem(GetItemInSlot(INVENTORY_SLOT_LEFTWEAPON, oPC), oPC);
GiveItem(GetItemInSlot(INVENTORY_SLOT_RIGHTWEAPON, oPC), oPC);
GiveItem(GetItemInSlot(INVENTORY_SLOT_BODY, oPC), oPC);

AurPostString("a_hand_fight: disarming handmaiden..", 6, 6, 3.0);

object oHand = GetObjectByTag("Handmaiden");
AssignCommand(oHand, ActionJumpToObject(GetObjectByTag("WP_HANDFIGHT_HAND")));
AssignCommand(oHand, ClearAllEffects());

GiveItem(GetItemInSlot(INVENTORY_SLOT_LEFTWEAPON, oHand), oPC);
GiveItem(GetItemInSlot(INVENTORY_SLOT_RIGHTWEAPON, oHand), oPC);
GiveItem(GetItemInSlot(INVENTORY_SLOT_BODY, oHand), oHand);

DelayCommand(1.9, AttackPlayer(oMaiden));
}
break;
}
}

// ---------------------------------------------------------------
// ST: Go hostile and attack player in a rather peculiar way...
// ---------------------------------------------------------------
void AttackPlayer(object oAttacker) {
DelayCommand(0.5, AssignCommand(oAttacker, ActionAttack(GetFirstPC())));
DelayCommand(0.5, ChangeToStandardFaction(oAttacker, STANDARD_FACTION_HOSTILE_1));
DelayCommand(0.6, GN_DetermineCombatRound());

SetMinOneHP(oAttacker, TRUE);
}
 shockix
03-15-2008, 8:32 AM
#5
Thanks. This is the script I had in mind.

I'll try to understand it.
 stoffe
03-15-2008, 8:39 AM
#6
Thanks. This is the script I had in mind.

I'll try to understand it.

Looks like they unequip items using the GiveItem() function to give the equipped item to the character who already possess it .
 shockix
03-15-2008, 9:33 AM
#7
Precisely.

The GiveItem command is to put an specific object into pc's inventory. When this specific object is equipped, the only way is to unequip it. And the game does.
I modified my first script :

void UnEquip(int iSlot,object oNpc )
{
object oItem = GetItemInSlot( iSlot, oNpc);
//AssignCommand(oNpc, ActionUnequipItem(oItem)); Previous command
GiveItem( oItem, GetFirstPC() ); // New one
}

It now works as intended.

Thanks a lot for your help.
Page: 1 of 1