Aller au contenu

Photo

welp i've run into problems


7 réponses à ce sujet

#1
gordonbrown82

gordonbrown82
  • Members
  • 544 messages
this code fires in a conversation:

#include "events_h"
#include "global_objects_h"
#include "utility_h"
#include "sys_chargen_h"
void main()
{
    object oHero = GetHero();
   object oNecklace = GetItemInEquipSlot(11, oHero);
   object oItem = GetObjectByTag("necklace2");

   if (oNecklace == oItem)
   {
    UT_TeamGoesHostile(1);
   }
}
it's supposed to look if the character has necklace2 equipped in item slot 11 and if it does, team 1 attacks.
when i play the game the result is that the player gets attacked after initiating conversation no matter if he wears the necklace or not. the tags are all checkin out so that's not the problem here.

#2
Craig Graff

Craig Graff
  • Members
  • 608 messages
Did you make sure that the creatures on the team srart out in the Neutral group?

Not likely related to your current problem, but a better way to check if the item is equipped would be
[dascript]
void main()
{
    object oHero = GetHero();
   object oNecklace = GetItemInEquipSlot(11, oHero);

   if (GetTag(oNecklace) == "necklace2")
   {
    UT_TeamGoesHostile(1);
   }
}
[/dascript]
The problem with your original code is that if there is more than one object with the tag "necklace2" it will often fail (since you can't be sure which object will be returned by GetObjectByTag).

#3
gordonbrown82

gordonbrown82
  • Members
  • 544 messages
thanks craig your code worked immediately. why i don't know. the only difference i see it that yours is a tag comparison instead of an object comparison.

#4
Adaram

Adaram
  • Members
  • 464 messages

gordonbrown82 wrote...

thanks craig your code worked immediately. why i don't know. the only difference i see it that yours is a tag comparison instead of an object comparison.


Which helps avoid the problem of comparing the object if, by chance, there are more than one "necklace2"'s.  At least I think that's why Craig's code is different.  Correct?

#5
gordonbrown82

gordonbrown82
  • Members
  • 544 messages
would that necklace2 be in the main campaign or something because i know that i haven't made such an object. i made a new necklace called "ikflcizgq" and gave it to the player but that didn't work either. but also i don't get why it would make a difference if there are more necklaces. if item slot 11 doesn't contain anything, and that nothing is compared to something, then the comparison should be invalid and the UT_TeamGoesHostile shouldn't fire.

#6
DavidSims

DavidSims
  • BioWare Employees
  • 196 messages
Here's what I think the problem was. I don't think GetObjectByTag can grab an item out of a creature's inventory, so that function would return OBJECT_INVALID. If the player wasn't wearing any necklace, GetItemInEquipmentSlot would return OBJECT_INVALID as well.



OBJECT_INVALID == OBJECT_INVALID resolves to TRUE, so the team goes hostile.

#7
gordonbrown82

gordonbrown82
  • Members
  • 544 messages
ok thanks david.

#8
Nattfodd

Nattfodd
  • Members
  • 321 messages

gordonbrown82 wrote...

thanks craig your code worked immediately. why i don't know. the only difference i see it that yours is a tag comparison instead of an object comparison.


That's was the difference. Your script compare different data; you compare a whole object with an Object Tag, if (oNecklace == oItem).
You mast compare theobject Tag with another object Tag ,  if (GetTag(oNecklace) == oItem).