Announcement

Collapse
No announcement yet.

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

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

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

    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

    Code:
    	<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>

    #2
    Originally posted by Xaliber View Post
    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

    Code:
    	<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.

    Comment


      #3
      Originally posted by sphereii View Post
      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?

      Comment


        #4
        Originally posted by Xaliber View Post
        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.

        Comment


          #5
          Originally posted by sphereii View Post
          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?

          Comment


            #6
            Did you try assigning the boar the <property name="Class" value="EntityAnimalStag"/>?
            If that works..
            Just manually input the hostile AI target/tasks, so it still will attack if hurt.

            Comment


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

              I used this.

              Code:
              <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>

              Comment


                #8
                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:
                Code:
                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.
                Code:
                        <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.
                Last edited by Tin; 12-09-2019, 02:27 PM.

                Comment


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

                  Code:
                  <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:

                  Code:
                  	<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
                  Code:
                  	<property name="AITarget-3" value="SetNearestCorpseAsTarget" data="class=EntityPlayer"/>

                  I wanted the zombies to feed on animal corpse after they killed it.
                  Last edited by Xaliber; 12-10-2019, 05:27 PM.

                  Comment


                    #10
                    *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

                    Comment

                    Working...
                    X