Page 1 of 1

updating player position when "pushed" by a mob

Posted: Sat Jul 14, 2012 7:26 pm
by CNKTHoward
Hi

I've got another question concerning the API and MM. I have a priest who is supposed to heal the group, but he only enables the healing function on a certain waypoint - so the X, Y and Z position is absolute.
If my priest is being pushed away from my teammates whilst he is in healing mode on the X, Y and Z position and out of range for any healspells, he just stands around and waits for the battle to end (that's how the healing mode is programmed. it gets enabled when the priest reaches the waypoint and if he is batteling (player.batteling()).)

So my question is: How can I update my character's position, so he can adjust his position and run back to the waypoint coordinates or even run to the teammembers until he is in healrange again?

Thx in advance!


edit: sorry for offtopic here, but didn't want to create a new thread. Can I check if a partymember has the buff "xy"? I know of the existance of:

Code: Select all

player:hasBuff("BuffName")
but this refers to my own character, not a partymember. F.e. I want to check, if partymember "char1" has "regeneration" on it, and if not casting regeneration on him.

Re: updating player position when "pushed" by a mob

Posted: Sat Jul 14, 2012 8:58 pm
by lisa
pretty hard to give advice on this 1 unless I could see the code at that waypoint.

Re: updating player position when "pushed" by a mob

Posted: Sun Jul 15, 2012 5:12 am
by CNKTHoward
Waypoint code:

Code: Select all

censored
BossFightHeal():

Code: Select all

censored

Re: updating player position when "pushed" by a mob

Posted: Sun Jul 15, 2012 5:21 am
by lisa
That actually looks familiar ;)

Anyway so the issue is you go into a loop and only leave the loop when you leave combat, so in order to keep the character at that exact spot you will need to add moving code into the loop.

You have a player:update() which means the bot knows the characters exact position, it is now just a matter of making the bot move the character to the coords you want.

Since I am guessing this is inside an instance I would concider using teleport, if you don't have the teleport userfunction then you can just use player:moveTo({X=x#,Z=z#},true)
obviously you will need to replace the x# and z# with the coords you want.

I would probably add it after this in the code
if (not player.Battling) then
return
end

Re: updating player position when "pushed" by a mob

Posted: Sun Jul 15, 2012 5:29 am
by CNKTHoward

Code: Select all

if (not player.Battling) then
	player:moveTo({X=2282,Z=2418},true)
	return
end	
Hm, that makes my character move back to the WP AFTER the fight. I need him to be in range for healing the other partymembers though.

Re: updating player position when "pushed" by a mob

Posted: Sun Jul 15, 2012 5:46 am
by lisa

Code: Select all

if (not player.Battling) then
   return
end
player:moveTo({X=2282,Z=2418},true) 
Ok so you don't want to go back to coords then.
Do you have the teleport userfunction?

untested and just ports to the same spot as other party member, not ideal and I don't know how many party members you have to worry about, if just 1 then porting next to them is probably fine.

Code: Select all

		for i,v in ipairs(partymemberpawn) do
			player:target(partymemberpawn[i])
			player:update()
			partymemberpawn[i]:update()
			partymemberpawn[i]:updateBuffs()
			target = player:getTarget();
			if target.HP/target.MaxHP*100 > 10 then
				if distance(player.X, player.Z, partymemberpawn[i].X, partymemberpawn[i].Z) > 150 then
					teleport(partymemberpawn[i].X,partymemberpawn[i].Z)
				end			
				player:checkSkills(true);
			end
			if (not player.Battling) then return end   
		end

Re: updating player position when "pushed" by a mob

Posted: Sun Jul 15, 2012 5:49 am
by CNKTHoward
Thx! I'll try this later. I use the player:moveTo function for now, since I don't have the teleport userfunction.

Re: updating player position when "pushed" by a mob

Posted: Sun Jul 15, 2012 5:53 am
by lisa
I edited it to move it to only move if the character needs to heal someone, otherwise it would move every time to them.

just replace
teleport(partymemberpawn.X,partymemberpawn.Z)
with
player:moveTo({X=partymemberpawn.X,Z=partymemberpawn.Z},true)

Re: updating player position when "pushed" by a mob

Posted: Sun Jul 15, 2012 3:59 pm
by CNKTHoward
I get this MM error when using the code.
player.lua:2307 attempt to perform arithmetic on field 'Z' (a nil value)

Code: Select all

					if target.HP/target.MaxHP*100 > 10 then
						if distance(player.X, player.Z, partymemberpawn[i].X, partymemberpawn[i].Z) > 150 then
							player:moveTo({partymemberpawn[i].X, partymemberpawn[i].Z}, true)
						end
						player:checkSkills(true);
					end

Re: updating player position when "pushed" by a mob

Posted: Sun Jul 15, 2012 7:15 pm
by lisa
line 2307 has this

Code: Select all

	end
What rombot version are you using?
If current version then why is your player.lua different?

Also the issue is this.
you have
player:moveTo({partymemberpawn.X, partymemberpawn.Z}, true)
I posted this
player:moveTo({X=partymemberpawn.X,Z=partymemberpawn.Z},true)

Re: updating player position when "pushed" by a mob

Posted: Tue Jul 17, 2012 6:01 am
by CNKTHoward
What rombot version are you using?
latest
If current version then why is your player.lua different?
It's slightly edited to disable PvPing

that's why line 2307 is

Code: Select all

local angle = math.atan2(waypoint.Z - self.Z, waypoint.X - self.X);
for me.

Since it's a mistake in the table definition

Code: Select all

[color=#FF0000]player:moveTo({partymemberpawn[i].X, partymemberpawn[i].Z}, true)[/color]

Code: Select all

[color=#00FF00]player:moveTo({X=partymemberpawn[i].X,Z=partymemberpawn[i].Z},true)[/color]
there is nothing wrong with the player.lua.

Your correct code of the moveTo call fixed my problem though, so no need for further support.