Author Topic: Check for companion's weapon  (Read 779 times)

Legacy_Fester Pot

  • Hero Member
  • *****
  • Posts: 1698
  • Karma: +0/-0
Check for companion's weapon
« on: July 24, 2010, 04:17:23 pm »


               I have two TEXT APPEARS scripts for the following conversation selections.

1. And nice sword work there.
2. Good shooting from up on the ridge.

For the first option this script is used:

-----
#include "x2_inc_itemprop"

int StartingConditional()
{
object oPC = GetPCSpeaker();
object oAhlias = GetObjectByTag("AhliasNox");
object oWeapon = GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oAhlias);

if (IPGetIsRangedWeapon(oWeapon)==TRUE) return FALSE;

return TRUE;
}
-----

For the second option this script is used:

-----
#include "x2_inc_itemprop"

int StartingConditional()
{
object oPC = GetPCSpeaker();
object oAhlias = GetObjectByTag("AhliasNox");
object oWeapon = GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oAhlias);

if (IPGetIsMeleeWeapon(oWeapon)==TRUE) return FALSE;

return TRUE;
}
-----

If the companion is using a melee weapon, option 2 is not available and option 1 is. This is working.

The problem is that when the companion is using a ranged weapon, option 1 and option 2 are available.

I don't know what the problem is and need some direction.

Thanks.

FP!
               
               

               


                     Modifié par Fester Pot, 24 juillet 2010 - 03:18 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Check for companion's weapon
« Reply #1 on: July 24, 2010, 05:14:34 pm »


               The only time I see your getting both to show up is if there is no weapon in the companion's hand.  for a test try adding tis to one of your starting conditionals.  



int StartingConditional()

{

object oPC = GetPCSpeaker();

object oAhlias = GetObjectByTag("AhliasNox");

object oWeapon = GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oAhlias);



if (GetIsObjectValid(oWeapon)) SpeakString( "There is nothing in the targets hand");

else SpeakString("target has a "+GetName(oWeapon)+" In there hand");








if (IPGetIsRangedWeapon(oWeapon)==TRUE) return FALSE;



return TRUE;

}



my guess is the your npc is unequiping the ranged weapons.
               
               

               
            

Legacy_Fester Pot

  • Hero Member
  • *****
  • Posts: 1698
  • Karma: +0/-0
Check for companion's weapon
« Reply #2 on: July 24, 2010, 07:44:52 pm »


               Alright, it always says, "target has a In there hand".



It does not matter if I switch INVENTORY_SLOT_LEFTHAND to INVENTORY_SLOT_RIGHTHAND and they always have a weapon in their hand at this point.



Neither melee or ranged is being detected, so nothing is being displayed as a TEXT APPEARS conditional. Even though the companion has a crossbow in equipped, it does not display the conversation node option.



Stumped again. '<img'>



FP!
               
               

               
            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Check for companion's weapon
« Reply #3 on: July 24, 2010, 08:03:40 pm »


               Lightfoot has little error in his script, it should be

if (!GetIsObjectValid(oWeapon)) SpeakString(
"There is nothing in the targets hand");

else SpeakString("target
has a "+GetName(oWeapon)+" In there hand");

anyway it fullfilled purpose so we now know oWeapon is invalid. My guess is that oAhlias is invalid too.

I dont know why you getting oAhlias via GetObjectByTag, if its object with whom PC speaks, then use OBJECT_SELF, anyway check the creature tag.

BTW, practically its better to use conditionals scripts by opposite, I mean, not you got there text 1 for when PC has melee weapon, yet you check if PC has not ranged weapon. Do it simple, check for melee weapon, which will then mean that if target has no weapon it wont show up (yet now it does).
               
               

               


                     Modifié par ShaDoOoW, 24 juillet 2010 - 07:05 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Check for companion's weapon
« Reply #4 on: July 24, 2010, 09:16:03 pm »


               Try it this way and lets see what we get.



int StartingConditional()
{
object oPC = GetPCSpeaker();
object oAhlias = GetAssociate(ASSOCIATE_TYPE_HENCHMAN,oPC);
object oWeapon = GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oAhlias);

if (!GetIsObjectValid(oWeapon)) SpeakString( "There is nothing in the targets hand");
else SpeakString("target has a "+GetName(oWeapon)+" In there hand"):

return IPGetIsRangedWeapon(oWeapon);
}
               
               

               


                     Modifié par Lightfoot8, 24 juillet 2010 - 08:22 .
                     
                  


            

Legacy_ChaosInTwilight

  • Full Member
  • ***
  • Posts: 126
  • Karma: +0/-0
Check for companion's weapon
« Reply #5 on: July 24, 2010, 10:46:26 pm »


               

If the companion is using a melee weapon, option 2 is not available and option 1 is. This is working.

The problem is that when the companion is using a ranged weapon, option 1 and option 2 are available.

I don't know what the problem is and need some direction.


Your testing with 2 different functions(IPGetIsRangedWeapon IPGetIsMeleeWeapon), and one is bugged and returning incorrectly.

Chaos Disapproves -1

True if range weapon equipped:
#include "x2_inc_itemprop"
//If range weapon equipped, TRUE
int StartingConditional()
{
object oPC = GetPCSpeaker();
object oAhlias = GetObjectByTag("AhliasNox");
object oWeapon = GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oAhlias);

if (IPGetIsRangedWeapon(oWeapon)==TRUE) return TRUE;

return FALSE;
}

False if range weapon equipped:
#include "x2_inc_itemprop"

//If range weapon NOT equipped, TRUE

int StartingConditional()

{

object oPC = GetPCSpeaker();

object oAhlias = GetObjectByTag("AhliasNox");

object oWeapon = GetItemInSlot(INVENTORY_SLOT_LEFTHAND, oAhlias);



if (IPGetIsRangedWeapon(oWeapon)==FALSE) return FALSE;



return TRUE;

}

Afterthought: That or more likely...your using one of those CEP weapons aren't you?

The ones that won't appear in the include since their not "real" weapons in the core NWN?
               
               

               


                     Modifié par ChaosInTwilight, 24 juillet 2010 - 09:47 .
                     
                  


            

Legacy_Fester Pot

  • Hero Member
  • *****
  • Posts: 1698
  • Karma: +0/-0
Check for companion's weapon
« Reply #6 on: July 25, 2010, 04:35:40 pm »


               Thanks everyone for the guidance in sorting this issue out!



I've got it working and the TEXT APPEARS fires when the correct melee/ranged is equipped by the companion. It was not a CEP weapon causing the issue but rather my attempt at writing these scripts and just not doing it right.



FP!
               
               

               
            

Legacy_Genisys

  • Hero Member
  • *****
  • Posts: 961
  • Karma: +0/-0
Check for companion's weapon
« Reply #7 on: July 25, 2010, 04:49:19 pm »


               GetObjectByTag is not what you want to use on a creature it's:

object oPC = GetPCSpeaker();
object oCompanion =  ????;   //You fill in how to identify who the companion is..
 
object oItem = GetItemPossessedBy("ThisTag", oCompanion);
object oSlot;
string sTag;
int nCheck = FALSE;

oSlot = GetItemInInventorySlot(WHAT_SLOT?, oCompanion);
sTag = GetTag(oSlot);

if(sTag == "THIS_TAG")
{
  nCheck = TRUE:  //Show the Converation Line..
}

return nCheck;    //Otherwise Don't Show the Conversation Line..


Hope this helped?
               
               

               


                     Modifié par Genisys, 25 juillet 2010 - 03:55 .