Jump to content

"Object reference not set" when trying to add a class to animalBoar


Xaliber

Recommended Posts

In an effort to make zombies target animals in this modlet I'm making, I want to set so zombies target the docile boars.

 

However each time I add class to animalBoar, the game shows "Object reference not set to an instance of an object" when trying to spawn the boar. Same goes with the zombies, when spawned, they seem to be looking for the (non-existing?) EntityAnimalBoar so the console says "Object reference not set".

 

I've looked at other classes like EntityAnimalRabbit and can only found it in entityclasses.xml, which means adding a new entity class shouldn't be a problem?

 

Here is my code in entityclasses.xml

 

<append xpath="/entity_classes/entity_class[@name='animalBoar']">
	<property name="Class" value="EntityAnimalBoar"/>

	<property name="AITask-1" value="Swim"/>
	<property name="AITask-2" value="RunawayWhenHurt"/>
	<property name="AITask-3" value="RunawayFromEntity" data="class=EntityZombie"/>
	<property name="AITask-4" value="Look"/>
</append>

Link to comment
Share on other sites

In an effort to make zombies target animals in this modlet I'm making, I want to set so zombies target the docile boars.

 

However each time I add class to animalBoar, the game shows "Object reference not set to an instance of an object" when trying to spawn the boar. Same goes with the zombies, when spawned, they seem to be looking for the (non-existing?) EntityAnimalBoar so the console says "Object reference not set".

 

I've looked at other classes like EntityAnimalRabbit and can only found it in entityclasses.xml, which means adding a new entity class shouldn't be a problem?

 

Here is my code in entityclasses.xml

 

<append xpath="/entity_classes/entity_class[@name='animalBoar']">
	<property name="Class" value="EntityAnimalBoar"/>

	<property name="AITask-1" value="Swim"/>
	<property name="AITask-2" value="RunawayWhenHurt"/>
	<property name="AITask-3" value="RunawayFromEntity" data="class=EntityZombie"/>
	<property name="AITask-4" value="Look"/>
</append>

 

There is no entityanimalBoar, which is why its generating that error. It uses animalTemplateHostile as a class, which it gets through extending.

Link to comment
Share on other sites

There is no entityanimalBoar, which is why its generating that error. It uses animalTemplateHostile as a class, which it gets through extending.

 

Yes, I mean, that's what I'm trying to do. I'm trying to add EntityAnimalBoar as a class for animalBoar, so I can set the zombieTemplateMale to attack boars without having them also attack zombie dogs (by setting its SetNearestEntityAsTarget to EntityPlayer,0,0,EntityNPC,0,0,EntityAnimalStag,0,0,EntityAnimalBoar,0,0).

 

But seems like I'm doing it wrong? Is there a better way to achieve what I intend to do?

Link to comment
Share on other sites

Yes, I mean, that's what I'm trying to do. I'm trying to add EntityAnimalBoar as a class for animalBoar, so I can set the zombieTemplateMale to attack boars without having them also attack zombie dogs (by setting its SetNearestEntityAsTarget to EntityPlayer,0,0,EntityNPC,0,0,EntityAnimalStag,0,0,EntityAnimalBoar,0,0).

 

But seems like I'm doing it wrong? Is there a better way to achieve what I intend to do?

 

The entity classes are in the DLL, as they are code, rather than just an XML reference. You could have them EntityEnemyAnimal for a class reference. It already exists.

Link to comment
Share on other sites

The entity classes are in the DLL, as they are code, rather than just an XML reference. You could have them EntityEnemyAnimal for a class reference. It already exists.

 

Ahh, I expected that. That's too bad. :/

 

I did use EntityEnemyAnimal but that makes the zombies hit zombie dogs and zombie bears. When applied to zombie dogs, it makes the dogs hit each other too. Is there a way to exclude EntityZombieDogs?

Link to comment
Share on other sites

That... kind of worked! Zombies now target boars, but boars won't react. They don't run nor they attack back. :/

 

I used this.

 

<append xpath="/entity_classes/entity_class[@name='animalBoar']">
	<property name="Class" value="EntityAnimalStag"/>

	<property name="AITask-1" value="Swim"/>
	<property name="AITask-2" value="Territorial"/>
	<property name="AITask-3" value="ApproachSpot"/>
	<property name="AITask-4" value="Look"/>
	<property name="AITask-5" value="Wander"/>
	<property name="AITarget-1" value="SetAsTargetIfHurt" data="class=EntityNPC,EntityPlayer,EntityZombie,EntityZombieDog,EntityBandit"/>
	<property name="AITarget-2" value="BlockingTargetTask"/>
	<property name="AITarget-3" value="" />
</append>

Link to comment
Share on other sites

If it was me:

I would use a <set> instead of <append>.

 

Then I would copy all the properties from the boar into the set and make sure I used the:

extends="animalTemplateTimid"

Since it already has the class change you need in it.

 

Then I would add in the whole AI/Target package to it.

       <property name="AIGroupCircle" value="1"/>
<property name="AIPathCostScale" value=".4, .6"/>
<property name="AITask-1" value="Swim"/>
<property name="AITask-2" value="BreakBlock"/>
<property name="AITask-3" value="ApproachAndAttackTarget" param1="EntityNPC,20,EntityPlayer,20"/>
<property name="AITask-4" value="ApproachSpot"/>
<property name="AITask-5" value="Look"/>
<property name="AITask-6" value="Wander"/>
<property name="AITarget-1" value="SetAsTargetIfHurt"/>
<property name="AITarget-2" value="BlockIf" param1="alert e 0"/>
<property name="AITarget-3" value="BlockingTargetTask"/>
<property name="AITarget-4" value="SetNearestEntityAsTarget" param1="EntityPlayer,15,EntityNPC,10"/>

Then test it (to see if it is acting accordingly).

If so.

Then prune the AI package to be exactly how you want it.

 

Edit: the reason for using the <set> is so I would have all the properties to mess with at my disposal, and to ensure I have all the needed components that the entity needs to function. :)

Link to comment
Share on other sites

That actually does it! Using the AI/Target package from animalTemplateHostile somehow generates errors, so I used this instead:

 

<property name="AIPathCostScale" value=".4, .6"/>
	<property name="AITask-1" value="Swim"/>
	<property name="AITask-2" value="BreakBlock"/>
	<property name="AITask-3" value="ApproachAndAttackTarget" data="class=EntityNPC,20,EntityPlayer,20,EntityZombie,20,EntityEnemyAnimal,20"/>
	<property name="AITask-4" value="ApproachSpot"/>
	<property name="AITask-5" value="Look"/>
	<property name="AITask-6" value="Wander"/>
	<property name="AITarget-1" value="SetAsTargetIfHurt" data="class=EntityNPC,EntityPlayer,EntityZombie,EntityEnemyAnimal"/>
	<property name="AITarget-2" value="BlockingTargetTask"/>
	<property name="AITarget-3" value=""/>

 

The key is on "ApproachAndAttackTarget" apparently. So thanks a lot! :)

 

- - - Updated - - -

 

Oh sorry, one more thing...

 

Do you happen to have any idea why setting this:

 

<property name="AITarget-3" value="SetNearestCorpseAsTarget" data="class=EntityPlayer,EntityNPC,EntityAnimalStag"/>

 

generates the same "Object reference not set" error?

 

The default value on zombieTemplateMale is

<property name="AITarget-3" value="SetNearestCorpseAsTarget" data="class=EntityPlayer"/>

 

 

I wanted the zombies to feed on animal corpse after they killed it.

Link to comment
Share on other sites

*Speculating without actually picking it apart*

Maybe the "SetNearestCorpseAsTarget" command, doesn't fully recognize those entities as being "corpses" when it checks and throws the errors? or maybe it doesn't recognize the commas for it for the extra entities?!?

Just a guess. I haven't spent a lot of time testing everything in the A17/18 stuff yet.

 

Maybe try to enter them individually and see if that works? give them their own lines.

Might be worth a try.

Best I can come up with off the cuff.

And glad you got it mostly working how you want it :)

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...