-- Hitbox lua by Rian2_idih

mouse = {}

function distance(x1,y1,x2,y2)
	return math.floor(math.sqrt(math.pow(x1-x2,2)+math.pow(y1-y2,2)))
end

addhook("always","lags")
function lags()
	for _, id in pairs(player(0,"tableliving")) do
		reqcld(id,2)
	end
end

addhook("clientdata","reciever")
function reciever(id,mode,x,y)
	if mode==2 then
		mouse[id]={x,y}
	end
end

addhook("hit","calculation")
function calculation(id,pl,weapon,hp,ap)
	hitbox = distance(player(id,"x"),player(id,"y"),mouse[pl][1],mouse[pl][2])
	if hitbox<=3 then			-- Head
		hp = 0
		if player(id,"armor")>65 then
			parse("setarmor "..id.." "..player(id,"armor")-35)
		elseif player(id,"armor")<=65 then
			parse("customkill "..pl.." \""..itemtype(weapon,"name").."\" "..id)
		elseif player(id,"armor")==201 then
			parse("customkill "..pl.." \""..itemtype(weapon,"name").."\" "..id)
		elseif player(id,"armor")==202 or player(id,"armor")==204 then
			hp = 50
		elseif player(id,"armor")==203 then
			hp = 25
		elseif player(id,"armor")==205 then
			hp = 5
		end
		if (player(id,"health")-hp)>0 then
			parse("sethealth "..id.." "..player(id,"health")-hp)
		else
			parse("customkill "..pl.." \""..itemtype(weapon,"name").."\" "..id)
		end
		return 1
	elseif hitbox>20 then
		hp = hp-math.floor(25*hp/100)
		if (player(id,"health")-hp)>0 then
			parse("sethealth "..id.." "..player(id,"health")-hp)
		else
			parse("customkill "..pl.." \""..itemtype(weapon,"name").."\" "..id)
		end
		return 1
	elseif hitbox>3 and hitbox<=20 then
		return 0
	end
end