Jump to content

Home

Script Help: Equip weapon if one is not equipped


deathdisco

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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));        
   }
}

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...