Lua:
function getNajblizej(pos)
local miasta = {
["carlin"] = {x=200,y=380,z=7},
["venore"] = {x=1200,y=2380,z=7},
["thais"] = {x=200,y=17000,z=7},
["edron"] = {x=250, y=600, z=7},
}
local city = ''
local distance = 0
for k,v in pairs(miasta) do
local dist = ((pos.x-v.x)^2+(pos.y-v.y)^2)^(1/2)
if (dist < 0) then
dist = 0-dist
end
if city == '' then
city = k
distance = dist
elseif (distance > dist)then
city = k
distance = dist
end
end
return {city, distance}
end
example:
Lua:
local poz = {x=340, y=800, z=7}
lol = getNajblizej(poz)
print(lol[1], lol[2])
in talkaction:
Lua:
function onSay(cid, words, param, channel)
if(param == '') then
return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command requires param.")
end
local t = string.explode(param, ",")
if((not t[1]) or (not t[2]) or (not t[3])) then
return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Command requires param.")
end
poz = getPlayerPosition(cid)
lol = getNajblizej(poz)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "The nearest town is: ".. lol[1] ..", distance is: ".. lol[2] .."")
return true
end
thx for help Azi
Last edited: