Code from engine changed from C++ to LUA.
Good to make quests/events where players must find on map some items/npc/boss/spawn etc. ^_^
You can make talkaction which will show where is something (not only player)
Good to make quests/events where players must find on map some items/npc/boss/spawn etc. ^_^
You can make talkaction which will show where is something (not only player)
Lua:
function searchThingText(fromPos, toPos)
local DISTANCE_BESIDE = 0
local DISTANCE_CLOSE = 1
local DISTANCE_FAR = 2
local DISTANCE_VERYFAR = 3
local DIR_N = 0
local DIR_S = 1
local DIR_E = 2
local DIR_W = 3
local DIR_NE = 4
local DIR_NW = 5
local DIR_SE = 6
local DIR_SW = 7
local LEVEL_HIGHER = 0
local LEVEL_LOWER = 1
local LEVEL_SAME = 2
local distance = 0
local direction = 0
local level = 0
local dx = fromPos.x - toPos.x
local dy = fromPos.y - toPos.y
local dz = fromPos.z - toPos.z
if(dz > 0) then
level = LEVEL_HIGHER
elseif(dz < 0) then
level = LEVEL_LOWER
else
level = LEVEL_SAME
end
if(math.abs(dx) < 5 and math.abs(dy) < 5) then
distance = DISTANCE_BESIDE
else
local tmp = dx * dx + dy * dy
if(tmp < 10000) then
distance = DISTANCE_CLOSE
elseif(tmp < 75625) then
distance = DISTANCE_FAR
else
distance = DISTANCE_VERYFAR
end
end
local tang = 0
if(dx ~= 0) then
tang = dy / dx
else
tang = 10
end
if(math.abs(tang) < 0.4142) then
if(dx > 0) then
direction = DIR_W
else
direction = DIR_E
end
elseif(math.abs(tang) < 2.4142) then
if(tang > 0) then
if(dy > 0) then
direction = DIR_NW
else
direction = DIR_SE
end
else
if(dx > 0) then
direction = DIR_SW
else
direction = DIR_NE
end
end
else
if(dy > 0) then
direction = DIR_N
else
direction = DIR_S
end
end
local ss = ''
if(distance == DISTANCE_BESIDE) then
if(level == LEVEL_SAME) then
ss = ss .. "is stangding next to you"
elseif(level == LEVEL_HIGHER) then
ss = ss .. "is above you"
elseif(level == LEVEL_LOWER) then
ss = ss .. "is below you"
end
elseif(distance == DISTANCE_CLOSE) then
if(level == LEVEL_SAME) then
ss = ss .. "is to the"
elseif(level == LEVEL_HIGHER) then
ss = ss .. "is on a higher level to the"
elseif(level == LEVEL_LOWER) then
ss = ss .. "is on a lower level to the"
end
elseif(distance == DISTANCE_FAR) then
ss = ss .. "is far to the";
elseif(distance == DISTANCE_VERYFAR) then
ss = ss .. "is very far to the"
end
if(distance ~= DISTANCE_BESIDE) then
if(direction == DIR_N) then
ss = ss .. "north"
elseif(direction == DIR_S) then
ss = ss .. "south"
elseif(direction == DIR_E) then
ss = ss .. "east"
elseif(direction == DIR_W) then
ss = ss .. "west"
elseif(direction == DIR_NE) then
ss = ss .. "north-east"
elseif(direction == DIR_NW) then
ss = ss .. "north-west"
elseif(direction == DIR_SE) then
ss = ss .. "south-east"
elseif(direction == DIR_SW) then
ss = ss .. "south-west"
end
end
return ss
end
Last edited by a moderator: