Jump to content
×
×
  • Create New...

Quest Function - Math.Sqrt


iks

Recommended Posts

M2 Download Center

Download Here ( Internal )

Hey guys. 

At the beginning - sorry for my English. I hope you understand everything below :)

 

A few months ago I was thinking about one thing... I wanted to have many NPC's with the same VNUM on one map. And now - how to check, what "type" of NPC is this NPC?

 

There are 3 targets marked. So now - I wanted to do 3 other operations with this NPC's.

 

My idea:

Check my and NPC coordinates. But how...?

 

Second idea:

Check only my position and square around me.

 

 

So...

function math_sqrt_distance(x, y)
	if math.sqrt(math_sqr(pc.get_local_x() - x + math_sqr(pc.get_local_y() - y))) < 40 then
		return true
	end
	
	return false
end

function math_sqr(value)
	return value*value
end

How to use it?

 

 

For example:

when 20350.click begin
	local positions_array = {
		{800, 200},
		{200, 200},
	}
	
	local texts_array = {
		"First NPC",
		"Second NPC",
	}
	
	for i = 1, table.getn(positions_array) do
		if math_sqrt_distance(positions_array[i][1], positions_array[i][2]) == true then
			say_title(texts_array[i])
			break
		end
	end
end

And that's it. 

 

At the end: this function checks our positions and 40 coordinates around us. If array "positions_array" contains positions which are returning "true" then the output is getting from array "texts_array".

 

Have a good time.

  • Love 4
Link to comment

Nice idea :)

But your function:

function math_sqrt_distance(x, y)
    if math.sqrt(math_sqr(pc.get_local_x() - x + math_sqr(pc.get_local_y() - y))) < 40 then
        return true
    end
     
    return false
end

I would write like this:

function math_sqrt_distance(x, y)
    if math.sqrt((pc.get_local_x() - x)^2 + (pc.get_local_y() - y)^2) < 40 then
        return true
    end
     
    return false
end

Because this is the general way of getting a distance between two points :)

and you need the "**2" because without it can come to a negative squirt and this wont work :)

Link to comment

Nice idea :)

But your function:

function math_sqrt_distance(x, y)
    if math.sqrt(math_sqr(pc.get_local_x() - x + math_sqr(pc.get_local_y() - y))) < 40 then
        return true
    end
     
    return false
end

I would write like this:

function math_sqrt_distance(x, y)
    if math.sqrt((pc.get_local_x() - x)**2 + (pc.get_local_y() - y)**2) < 40 then
        return true
    end
     
    return false
end

Because this is the general way of getting a distance between two points :)

and you need the "**2" because without it can come to a negative squirt and this wont work :)

I'm not sure about **2. Is it work with "metin lua"?

 

 

 

Btw. it works great.

function math_sqr(value)
    return value*value
end
  • Love 2
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.