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.

Script Help: Equip weapon if one is not equipped

Page: 1 of 1
 deathdisco
02-17-2007, 3:37 PM
#1
I'm trying to have the PC equip a temporary lightsaber if one is not equipped.
The problem I'm having is even if the PC all ready has a light saber, the temp saber is still being equipped. The script I have is incomplete, it's as far as I can get with it.

Here's what I got so far:

void main()
{
object oEquipment = GetItemInSlot(4, GetFirstPC());

location locA = Location(Vector(0.00,-124.50,-1.55), 95.70);
CreateObject(OBJECT_TYPE_CREATURE, "frmtrn", locA);


if (GetIsObjectValid(oEquipment))

if ((((GetBaseItemType(oEquipment) != 8) || (GetBaseItemType(oEquipment) != 9)) || (GetBaseItemType(oEquipment) != 10)))
{
AssignCommand(GetFirstPC(), ActionUnequipItem(oEquipment));
object oSbr = CreateItemOnObject("tempsbr",GetFirstPC());
AssignCommand(GetFirstPC(), ActionEquipItem(oSbr, INVENTORY_SLOT_RIGHTWEAPON, TRUE));
}
else if ((((GetBaseItemType(oEquipment) == 8) || (GetBaseItemType(oEquipment) == 9)) || (GetBaseItemType(oEquipment) == 10)))
{ return;
}
}

TIA.

EDIT: almost forgot, how would I make my party members not participate in this fight?
 stoffe
02-17-2007, 4:40 PM
#2
I'm trying to have the PC equip a temporary lightsaber if one is not equipped.
The problem I'm having is even if the PC all ready has a light saber, the temp saber is still being equipped. The script I have is incomplete, it's as far as I can get with it.

The problem, as far as I can see, is where you check the base item type of the equipped weapon. Your check will always return true since you check if the player does not have a lightsaber equipped, or not a shortsaber equipped, or not a doublesaber equipped.

So, if you have a saber equipped you logically can't have a shortsaber or a doublesaber equipped at the same time, and one of the other conditions would return TRUE, since only one of the conditions need to return TRUE for the whole if-statement to trigger.

Thus you should use AND (&&) instead of OR (||) in your check. That way it would only trigger if the player does not have any type of lightsaber equipped. Like:


void main() {
object oPC = GetFirstPC();
object oEquipment = GetItemInSlot(INVENTORY_SLOT_RIGHTWEAPON, oPC);

location locA = Location(Vector(0.00,-124.50,-1.55), 95.70);
CreateObject(OBJECT_TYPE_CREATURE, "frmtrn", locA);

if (GetIsObjectValid(oEquipment)) {
int iType = GetBaseItemType(oEquipment);

if ((iType != BASE_ITEM_LIGHTSABER)
&& (iType != BASE_ITEM_DOUBLE_BLADED_LIGHTSABER)
&& (iType != BASE_ITEM_SHORT_LIGHTSABER))
{
object oSbr = CreateItemOnObject("tempsbr", oPC);
AssignCommand(oPC, ActionUnequipItem(oEquipment));
AssignCommand(oPC, ActionEquipItem(oSbr, INVENTORY_SLOT_RIGHTWEAPON, TRUE));
}
}
}



EDIT: almost forgot, how would I make my party members not participate in this fight?

You could temporarily remove them from the active party and change their faction to 5 (Neutral). That way they would just stand there watching and not interfere, and the player couldn't control them. When the fight is over you put them back into the active party again.
 deathdisco
02-17-2007, 5:35 PM
#3
Thanks that worked perfectly.
You could temporarily remove them from the active party and change their faction to 5 (Neutral). That way they would just stand there watching and not interfere, and the player couldn't control them. When the fight is over you put them back into the active party again.

How do I account for different party combos?
 stoffe
02-17-2007, 6:01 PM
#4
How do I account for different party combos?

You could add two global variables to keep track on who was in the party. Either two Global Numbers that track the party table slots, or two Global Strings that keep track of the Tags of the party members.

Then you read the values from those globals to restore the proper party members to the active party.
 deathdisco
02-18-2007, 7:12 PM
#5
You could add two global variables to keep track on who was in the party. Either two Global Numbers that track the party table slots, or two Global Strings that keep track of the Tags of the party members.

Then you read the values from those globals to restore the proper party members to the active party.

Actually I'm just going to remove any party members completely. The area is set to escapeable so they can be added back in via party selection menu. Keeping track of that many possible NPC's is beyond my scripting skills anyway.

I seem to have problems getting NPC's(party or not) to do any thing when the scripts are being fired within a dialog. :headbump
I tried setting solo mode and moving party members to a different location. If I was lucky it worked half of the time. :mad:

Anyway back to the original issue,
I need to modify the temp lightsaber script. I need it to work if you do not have a weapon equipped also.
TIA.
 stoffe
02-18-2007, 7:36 PM
#6
Actually I'm just going to remove any party members completely. The area is set to escapeable so they can be added back in via party selection menu. Keeping track of that many possible NPC's is beyond my scripting skills anyway.

You would only have to keep track of two text strings, but if you want to let the player re-form the party afterwards manually that works as well. :)

Anyway back to the original issue,
I need to modify the temp lightsaber script. I need it to work if you do not have a weapon equipped also.
TIA.

This variant should take unarmed players into account as well:


void main() {
object oPC = GetFirstPC();
object oEquipment = GetItemInSlot(INVENTORY_SLOT_RIGHTWEAPON, oPC);

location locA = Location(Vector(0.00,-124.50,-1.55), 95.70);
CreateObject(OBJECT_TYPE_CREATURE, "frmtrn", locA);

int bHasSaber = FALSE;
if (GetIsObjectValid(oEquipment)) {
int iType = GetBaseItemType(oEquipment);
if ((iType == BASE_ITEM_LIGHTSABER)
|| (iType == BASE_ITEM_DOUBLE_BLADED_LIGHTSABER)
|| (iType == BASE_ITEM_SHORT_LIGHTSABER))
{
bHasSaber = TRUE;
}
}

if (!bHasSaber) {
object oSbr = CreateItemOnObject("tempsbr", oPC);
AssignCommand(oPC, ActionUnequipItem(oEquipment));
AssignCommand(oPC, ActionEquipItem(oSbr, INVENTORY_SLOT_RIGHTWEAPON, TRUE));
}
}
 deathdisco
02-18-2007, 9:04 PM
#7
Thanks Stoffe,
Works perfectly. :)
Page: 1 of 1