-- Move Direction by MikuAuahDark

Move_Up=1
Move_Down=2
Move_Left=4
Move_Right=8

Move_Direction={}

for i=1,32 do
	Move_Direction[i]={0,0,0}
end

function SetPlayerPos(id,x,y)
	x=x or math.floor(player(id,"x"))
	y=y or math.floor(player(id,"y"))
	parse("setpos "..id.." "..x.." "..y)
	local temp=Move_Direction[id]
	temp[1]=x
	temp[2]=y
end

function GetPlayerDirection(id)
	return Move_Direction[id][3]
end

addhook("spawn","ResetDirection")
function ResetDirection(id)
	local temp=Move_Direction[id]
	temp[1]=math.floor(player(id,"x"))
	temp[2]=math.floor(player(id,"y"))
	temp[3]=0
end

addhook("always","MoveDirection")
function MoveDirection()
	for n,v in pairs(player(0,"tableliving")) do
		local x=math.floor(player(v,"x"))
		local y=math.floor(player(v,"y"))
		local p=Move_Direction[v]
		local r=0
		if x>p[1] then
			r=r+8
		elseif p[1]>x then
			r=r+4
		end
		if y>p[2] then
			r=r+2
		elseif p[2]>y then
			r=r+1
		end
		p[1]=x
		p[2]=y
		p[3]=r
	end
end