Jump to content

Recommended Posts

Posted

Hello everyone. I've got a little problem and some questions.

 

1.I want my mob to throw poison potions at me and melee attack me when i get close. I've looked at witch's code and i've made my mob throw potions at me. So that works, but when i use attackOnColide task on my mob, it only melee attacks me, not throwing potions. How to do so:

Throw potions at me when im far from mob, or mob cant get me( im on the roof or something in this sort ), and melee attack me when i get close to it.

 

Help me please, i really need this.

Posted

You should take a look at the Witch, as it throws potions.

 

Check out my question again. I've made my mob throwing potions, but when i set task attackOnColide to him, it only perform melee attacks on me and not throwing potions. Without that task, my mob throws potions well. I want him to perform both attacks.

Posted

So did you understand my question and can you help me please?

You need 2 AI tasks. One which throws the potions and one which performs the melee attack. The methods in the EntityAI class are pretty self explanatory to be honest.

 

this.tasks.addTask(0, new EntityAISwimming(this));
	this.tasks.addTask(1, new EntityAIWander(this, 0.2F));
	this.tasks.addTask(1, new EntityAIAttackOnCollide(this,
			EntityPlayer.class, this.moveSpeed, false));
	this.tasks.addTask(3, new EntityAIWatchClosest(this,
			EntityPlayer.class, 6.0F));
	this.tasks.addTask(4, new EntityAILookIdle(this));
	this.tasks.addTask(5, new EntityAIArrowAttack(this, this.moveSpeed, 60, 10.0F));

	this.targetTasks.addTask(0, new EntityAIHurtByTarget(this, true));
	this.targetTasks.addTask(1, new EntityAINearestAttackableTarget(this,
			EntityPlayer.class, 25.0F, 0, true));

 

Those are my Entity tasks. I think ArrowAttack and AttackOnCollide perform both attacks. But ArrowAttack is not working with AttackOnCollide. So when i use AttackOnCollide, my Entity only perform melee attacks. So ArrowAttack is just confusing and stop working. Understand? But when i remove AttackOnCollide task, ArrowAttack works fine. But my mob cant perform melee attacks. Those tasks are not working with eachother. So i dont know what to do lol.

Posted

What?? Um and how i suppose to do that actually? This is so hard, hundreds of code.

Learn how to program. Sorry, modding without programming is impossible.

 

I know the basics of java. But i without copying stuff and reading from somewhere, thats impossible to draw a code by myself. All that symbols have to be correctly put.

Posted

Then remove the task when there is no player around.

 

What? How i suppose to do that? Please give the code if you know something about it.

See the line

task.addTask

?

Then this exist too

task.removeTask

 

Now, how to find a player ?

EntityPlayer closePlayer = this.worldObj.getClosestPlayerToEntity(this, putSomeDistanceHere);
if(closePlayer==null){
//forever alone
}else{
//kill the bastard
}

Posted

Then remove the task when there is no player around.

 

What? How i suppose to do that? Please give the code if you know something about it.

See the line

task.addTask

?

Then this exist too

task.removeTask

 

Now, how to find a player ?

EntityPlayer closePlayer = this.worldObj.getClosestPlayerToEntity(this, putSomeDistanceHere);
if(closePlayer==null){
//forever alone
}else{
//kill the bastard
}

 

Ok, so i've made how you type and that works! So my mob shoots potion in me when he cant get me with himself. Thank you so much.

Posted

Then remove the task when there is no player around.

 

What? How i suppose to do that? Please give the code if you know something about it.

See the line

task.addTask

?

Then this exist too

task.removeTask

 

Now, how to find a player ?

EntityPlayer closePlayer = this.worldObj.getClosestPlayerToEntity(this, putSomeDistanceHere);
if(closePlayer==null){
//forever alone
}else{
//kill the bastard
}

 

I think that exactly what you mean? Well it works. Sometimes he mess up a little though

EntityPlayer closePlayer = this.worldObj.getClosestPlayerToEntity(this, 4);
	if(closePlayer==null){
		EntityAIArrowAttack arrowattack = null;
		this.tasks.removeTask(arrowattack);
		this.tasks.addTask(3, new EntityAIAttackOnCollide(this,
				EntityPlayer.class, this.moveSpeed, false));

	}else
	{
		EntityAIAttackOnCollide attackoncollide = null;
		this.tasks.removeTask(attackoncollide);
	}
}

Posted

I think that exactly what you mean? Well it works. Sometimes he mess up a little though

EntityPlayer closePlayer = this.worldObj.getClosestPlayerToEntity(this, 4);
	if(closePlayer==null){
		EntityAIArrowAttack arrowattack = null;
		this.tasks.removeTask(arrowattack);
		this.tasks.addTask(3, new EntityAIAttackOnCollide(this,
				EntityPlayer.class, this.moveSpeed, false));

	}else
	{
		EntityAIAttackOnCollide attackoncollide = null;
		this.tasks.removeTask(attackoncollide);
	}
}

EntityAIAttackOnCollide attackoncollide = null;
		this.tasks.removeTask(attackoncollide);

This is really unlikely to work. You need to cache the task you want to change.

 

public EntityAIBase cache;

public void onUpdate{
  ...
EntityPlayer closePlayer = this.worldObj.getClosestPlayerToEntity(this, 4);
	if(closePlayer==null){
                       if(this.cache!=null){
		   this.tasks.removeTask(cache);
                           this.cache = null;
                      }
	}else if(this.cache ==null)
	{
	      this.cache = new EntityAIAttackOnCollide(this,
				EntityPlayer.class, this.moveSpeed, false);
              this.tasks.addTask(3, cache);
	}
}

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.