• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

effects display

Gubailovo

Well-Known Member
Joined
Dec 19, 2013
Messages
407
Solutions
2
Reaction score
62
I have a script pointing to a certain coordinate on the map. (and it works correctly). When you add a visual effect in the form of arrows, it stops working. what am I doing wrong?

Lua:
function getDistance(diffPos)
    -- определ¤ем дистанцию
    text = ""
    dist = math.sqrt(diffPos.x * diffPos.x + diffPos.y * diffPos.y + diffPos.z * diffPos.z);
   
    if dist <= 2 then
        text = "здесь "
    elseif dist <= 4 then
        text = "близко "
    elseif dist <= 100 then
        text = ""
    elseif dist <= 274 then
        text = "далеко "
    else
        text = "очень далеко "
    end
   
    return text
end

function getDirection(diffPos)
    text = ""

    -- определим направление
    if diffPos.x >= 5 and math.abs(diffPos.y) < 5 then
        doSendMagicEffect(topos,NM_ME_VL)
        text = "на востоке"
    elseif diffPos.x <= -5 and math.abs(diffPos.y) < 5 then
        doSendMagicEffect(topos,NM_ME_V)
        text = "на западе"
    elseif diffPos.y >= 5 and math.abs(diffPos.x) < 5 then
        doSendMagicEffect(topos,NM_ME_NL)
        text = "на юге"
    elseif diffPos.y <= -5 and math.abs(diffPos.x) < 5 then
        doSendMagicEffect(topos,NM_ME_NP)
        text = "на севере"
    elseif diffPos.x >= 5 and diffPos.y >= 5 then
        doSendMagicEffect(topos,NM_ME_L)
        text = "на юго-востоке"
    elseif diffPos.x <= -5 and diffPos.y >= 5 then
        doSendMagicEffect(topos,NM_ME_P)
        text = "на юго-западе"
    elseif diffPos.x <= -5 and diffPos.y <= -5 then
        doSendMagicEffect(topos,NM_ME_VP)
        text = "на северо-западе"
    elseif diffPos.x >= 5 and diffPos.y <= -5 then
        doSendMagicEffect(topos,NM_ME_N)
        text = "на северо-востоке"
    else
        text = ""
    end
   
    return text
end

function onUse(cid, item, frompos, item2, topos)
    dest = getItemAddHP(item.uid)
   
    pcall(function () dx = treasure_x[dest] end)
    pcall(function () dy = treasure_y[dest] end)
    pcall(function () dz = treasure_z[dest] end)
    targetPos = {x=dx, y=dy, z=dz}
   
    plrpos = getPlayerPosition(cid)
    centerpos = {x=plrpos.x, y=plrpos.y, z=plrpos.z}
   
    diffPos = {x=(1643 - centerpos.x), y=(1613 - centerpos.y), z=(7 - centerpos.z)}
   
    doPlayerSendTextMessage(cid, 22, "Синекожий гоблин находитс¤ " .. getDistance(diffPos) .. getDirection(diffPos))
   
    return 1
end
error in console
Lua:
Lua error 1: 1
Lua error 2: attempt to index a nil value
 
Solution
B
In my opinion, you should only create separate functions if you are planning to re-use that code multiple times, or if there is a large amount of code in the main function.

Lua:
function onUse(cid, item, frompos, item2, topos)
 
    local text = ""
    local effect = 0
    local playerPos = getPlayerPosition(cid)
    local diffPos = {x=(1643 - playerPos.x), y=(1613 - playerPos.y), z=(7 - playerPos.z)}
    local dist = math.sqrt(diffPos.x * diffPos.x + diffPos.y * diffPos.y + diffPos.z * diffPos.z);
   
    if dist <= 2 then
        text = text .. "здесь "
    elseif dist > 2 and dist <= 4 then
        text = text .. "близко "
    elseif dist > 4 and dist <= 100 then
        text = text .. ""
    elseif dist > 100 and dist <= 274 then...
maybe I'm doing something wrong?
Lua:
if diffPos.x >= 5 and math.abs(diffPos.y) < 5 then
        doSendMagicEffect(topos,NM_ME_VL)
        text = "на востоке"
    elseif diffPos.x <= -5 and math.abs(diffPos.y) < 5 then
        doSendMagicEffect(topos,NM_ME_V)
        text = "на западе"
    elseif diffPos.y >= 5 and math.abs(diffPos.x) < 5 then
        doSendMagicEffect(topos,NM_ME_NL)
        text = "на юге"
    elseif diffPos.y <= -5 and math.abs(diffPos.x) < 5 then
        doSendMagicEffect(topos,NM_ME_NP)
        text = "на севере"
    elseif diffPos.x >= 5 and diffPos.y >= 5 then
        doSendMagicEffect(topos,NM_ME_L)
        text = "на юго-востоке"
    elseif diffPos.x <= -5 and diffPos.y >= 5 then
        doSendMagicEffect(topos,NM_ME_P)
        text = "на юго-западе"
    elseif diffPos.x <= -5 and diffPos.y <= -5 then
        doSendMagicEffect(topos,NM_ME_VP)
        text = "на северо-западе"
    elseif diffPos.x >= 5 and diffPos.y <= -5 then
        doSendMagicEffect(topos,NM_ME_N)
        text = "на северо-востоке"
    else
        text = ""
    end
  
    return text
end

lib.lua
Lua:
NM_ME_P = 72
NM_ME_NP = 73
NM_ME_N = 74
NM_ME_VL = 75
NM_ME_L = 76
NM_ME_NL = 77
NM_ME_V = 78
NM_ME_VP = 70


here is the expression

Lua:
doSendMagicEffect(topos,NM_ME_N)
 
maybe I'm doing something wrong?
Lua:
if diffPos.x >= 5 and math.abs(diffPos.y) < 5 then
        doSendMagicEffect(topos,NM_ME_VL)
        text = "на востоке"
    elseif diffPos.x <= -5 and math.abs(diffPos.y) < 5 then
        doSendMagicEffect(topos,NM_ME_V)
        text = "на западе"
    elseif diffPos.y >= 5 and math.abs(diffPos.x) < 5 then
        doSendMagicEffect(topos,NM_ME_NL)
        text = "на юге"
    elseif diffPos.y <= -5 and math.abs(diffPos.x) < 5 then
        doSendMagicEffect(topos,NM_ME_NP)
        text = "на севере"
    elseif diffPos.x >= 5 and diffPos.y >= 5 then
        doSendMagicEffect(topos,NM_ME_L)
        text = "на юго-востоке"
    elseif diffPos.x <= -5 and diffPos.y >= 5 then
        doSendMagicEffect(topos,NM_ME_P)
        text = "на юго-западе"
    elseif diffPos.x <= -5 and diffPos.y <= -5 then
        doSendMagicEffect(topos,NM_ME_VP)
        text = "на северо-западе"
    elseif diffPos.x >= 5 and diffPos.y <= -5 then
        doSendMagicEffect(topos,NM_ME_N)
        text = "на северо-востоке"
    else
        text = ""
    end
 
    return text
end

lib.lua
Lua:
NM_ME_P = 72
NM_ME_NP = 73
NM_ME_N = 74
NM_ME_VL = 75
NM_ME_L = 76
NM_ME_NL = 77
NM_ME_V = 78
NM_ME_VP = 70


here is the expression

Lua:
doSendMagicEffect(topos,NM_ME_N)
topos is never defined, which is giving you the nil value.
 
You have to pass topos as a parameter in your getDirection function

Lua:
function getDistance(diffPos)
    -- определ¤ем дистанцию
    text = ""
    dist = math.sqrt(diffPos.x * diffPos.x + diffPos.y * diffPos.y + diffPos.z * diffPos.z);
 
    if dist <= 2 then
        text = "здесь "
    elseif dist <= 4 then
        text = "близко "
    elseif dist <= 100 then
        text = ""
    elseif dist <= 274 then
        text = "далеко "
    else
        text = "очень далеко "
    end
 
    return text
end

function getDirection(diffPos, topos)
    text = ""

    -- определим направление
    if diffPos.x >= 5 and math.abs(diffPos.y) < 5 then
        doSendMagicEffect(topos,NM_ME_VL)
        text = "на востоке"
    elseif diffPos.x <= -5 and math.abs(diffPos.y) < 5 then
        doSendMagicEffect(topos,NM_ME_V)
        text = "на западе"
    elseif diffPos.y >= 5 and math.abs(diffPos.x) < 5 then
        doSendMagicEffect(topos,NM_ME_NL)
        text = "на юге"
    elseif diffPos.y <= -5 and math.abs(diffPos.x) < 5 then
        doSendMagicEffect(topos,NM_ME_NP)
        text = "на севере"
    elseif diffPos.x >= 5 and diffPos.y >= 5 then
        doSendMagicEffect(topos,NM_ME_L)
        text = "на юго-востоке"
    elseif diffPos.x <= -5 and diffPos.y >= 5 then
        doSendMagicEffect(topos,NM_ME_P)
        text = "на юго-западе"
    elseif diffPos.x <= -5 and diffPos.y <= -5 then
        doSendMagicEffect(topos,NM_ME_VP)
        text = "на северо-западе"
    elseif diffPos.x >= 5 and diffPos.y <= -5 then
        doSendMagicEffect(topos,NM_ME_N)
        text = "на северо-востоке"
    else
        text = ""
    end
 
    return text
end

function onUse(cid, item, frompos, item2, topos)
    dest = getItemAddHP(item.uid)
 
    pcall(function () dx = treasure_x[dest] end)
    pcall(function () dy = treasure_y[dest] end)
    pcall(function () dz = treasure_z[dest] end)
    targetPos = {x=dx, y=dy, z=dz}
 
    plrpos = getPlayerPosition(cid)
    centerpos = {x=plrpos.x, y=plrpos.y, z=plrpos.z}
 
    diffPos = {x=(1643 - centerpos.x), y=(1613 - centerpos.y), z=(7 - centerpos.z)}
 
    doPlayerSendTextMessage(cid, 22, "Синекожий гоблин находитс¤ " .. getDistance(diffPos) .. getDirection(diffPos, topos))
 
    return 1
end
 
You have to pass topos as a parameter in your getDirection function

Lua:
function getDistance(diffPos)
    -- определ¤ем дистанцию
    text = ""
    dist = math.sqrt(diffPos.x * diffPos.x + diffPos.y * diffPos.y + diffPos.z * diffPos.z);
 
    if dist <= 2 then
        text = "здесь "
    elseif dist <= 4 then
        text = "близко "
    elseif dist <= 100 then
        text = ""
    elseif dist <= 274 then
        text = "далеко "
    else
        text = "очень далеко "
    end
 
    return text
end

function getDirection(diffPos, topos)
    text = ""

    -- определим направление
    if diffPos.x >= 5 and math.abs(diffPos.y) < 5 then
        doSendMagicEffect(topos,NM_ME_VL)
        text = "на востоке"
    elseif diffPos.x <= -5 and math.abs(diffPos.y) < 5 then
        doSendMagicEffect(topos,NM_ME_V)
        text = "на западе"
    elseif diffPos.y >= 5 and math.abs(diffPos.x) < 5 then
        doSendMagicEffect(topos,NM_ME_NL)
        text = "на юге"
    elseif diffPos.y <= -5 and math.abs(diffPos.x) < 5 then
        doSendMagicEffect(topos,NM_ME_NP)
        text = "на севере"
    elseif diffPos.x >= 5 and diffPos.y >= 5 then
        doSendMagicEffect(topos,NM_ME_L)
        text = "на юго-востоке"
    elseif diffPos.x <= -5 and diffPos.y >= 5 then
        doSendMagicEffect(topos,NM_ME_P)
        text = "на юго-западе"
    elseif diffPos.x <= -5 and diffPos.y <= -5 then
        doSendMagicEffect(topos,NM_ME_VP)
        text = "на северо-западе"
    elseif diffPos.x >= 5 and diffPos.y <= -5 then
        doSendMagicEffect(topos,NM_ME_N)
        text = "на северо-востоке"
    else
        text = ""
    end
 
    return text
end

function onUse(cid, item, frompos, item2, topos)
    dest = getItemAddHP(item.uid)
 
    pcall(function () dx = treasure_x[dest] end)
    pcall(function () dy = treasure_y[dest] end)
    pcall(function () dz = treasure_z[dest] end)
    targetPos = {x=dx, y=dy, z=dz}
 
    plrpos = getPlayerPosition(cid)
    centerpos = {x=plrpos.x, y=plrpos.y, z=plrpos.z}
 
    diffPos = {x=(1643 - centerpos.x), y=(1613 - centerpos.y), z=(7 - centerpos.z)}
 
    doPlayerSendTextMessage(cid, 22, "Синекожий гоблин находитс¤ " .. getDistance(diffPos) .. getDirection(diffPos, topos))
 
    return 1
end
in "function getDirection(diffPos, topos)" this does not work.
I need " doSendMagicEffect(topos,NM_ME_N)" put in " function onUse(cid, item, frompos, item2, topos)" and link it to "getDirection(diffPos, topos))" .
but for this I do not have enough experience and knowledge. anyone can help me?

Скриншот 25-02-2022 214739.jpg
 
In my opinion, you should only create separate functions if you are planning to re-use that code multiple times, or if there is a large amount of code in the main function.

Lua:
function onUse(cid, item, frompos, item2, topos)
 
    local text = ""
    local effect = 0
    local playerPos = getPlayerPosition(cid)
    local diffPos = {x=(1643 - playerPos.x), y=(1613 - playerPos.y), z=(7 - playerPos.z)}
    local dist = math.sqrt(diffPos.x * diffPos.x + diffPos.y * diffPos.y + diffPos.z * diffPos.z);
   
    if dist <= 2 then
        text = text .. "здесь "
    elseif dist > 2 and dist <= 4 then
        text = text .. "близко "
    elseif dist > 4 and dist <= 100 then
        text = text .. ""
    elseif dist > 100 and dist <= 274 then
        text = text .. "далеко "
    else
        text = text .. "очень далеко "
    end
   
    if diffPos.x >= 5 and math.abs(diffPos.y) < 5 then
        effect = NM_ME_VL
        text = text .. "на востоке"
    elseif diffPos.x <= -5 and math.abs(diffPos.y) < 5 then
        effect = NM_ME_V
        text = text .. "на западе"
    elseif diffPos.y >= 5 and math.abs(diffPos.x) < 5 then
        effect = NM_ME_NL
        text = text .. "на юге"
    elseif diffPos.y <= -5 and math.abs(diffPos.x) < 5 then
        effect = NM_ME_NP
        text = text .. "на севере"
    elseif diffPos.x >= 5 and diffPos.y >= 5 then
        effect = NM_ME_L
        text = text .. "на юго-востоке"
    elseif diffPos.x <= -5 and diffPos.y >= 5 then
        effect = NM_ME_P
        text = text .. "на юго-западе"
    elseif diffPos.x <= -5 and diffPos.y <= -5 then
        effect = NM_ME_VP
        text = text .. "на северо-западе"
    elseif diffPos.x >= 5 and diffPos.y <= -5 then
        effect = NM_ME_N
        text = text .. "на северо-востоке"
    end
 
    if topos and effect then
        doSendMagicEffect(topos, effect)
    end
    doPlayerSendTextMessage(cid, 22, "Синекожий гоблин находитс¤ " .. text)
 
    return true
end


If you want the effect to be in the direction 1sqm from the player:
Lua:
function onUse(cid, item, frompos, item2, topos)
 
    local text = ""
    local effect = 0
    local playerPos = getPlayerPosition(cid)
    local diffPos = {x=(1643 - playerPos.x), y=(1613 - playerPos.y), z=(7 - playerPos.z)}
    local dist = math.sqrt(diffPos.x * diffPos.x + diffPos.y * diffPos.y + diffPos.z * diffPos.z);
    local dirPos = {x=playerPos.x, y=playerPos.y, z=playerPos.z}
    
    if dist <= 2 then
        text = text .. "здесь "
    elseif dist > 2 and dist <= 4 then
        text = text .. "близко "
    elseif dist > 4 and dist <= 100 then
        text = text .. ""
    elseif dist > 100 and dist <= 274 then
        text = text .. "далеко "
    else
        text = text .. "очень далеко "
    end
    
    if diffPos.x >= 5 and math.abs(diffPos.y) < 5 then
        effect = NM_ME_VL
        text = text .. "на востоке"
        dirPos.x = dirPos.x - 1
    elseif diffPos.x <= -5 and math.abs(diffPos.y) < 5 then
        effect = NM_ME_V
        text = text .. "на западе"
        dirPos.x = dirPos.x + 1
    elseif diffPos.y >= 5 and math.abs(diffPos.x) < 5 then
        effect = NM_ME_NL
        text = text .. "на юге"
        dirPos.y = dirPos.y + 1
    elseif diffPos.y <= -5 and math.abs(diffPos.x) < 5 then
        effect = NM_ME_NP
        text = text .. "на севере"
        dirPos.y = dirPos.y - 1
    elseif diffPos.x >= 5 and diffPos.y >= 5 then
        effect = NM_ME_L
        text = text .. "на юго-востоке"
        dirPos.x = dirPos.x - 1
        dirPos.y = dirPos.y + 1
    elseif diffPos.x <= -5 and diffPos.y >= 5 then
        effect = NM_ME_P
        text = text .. "на юго-западе"
        dirPos.x = dirPos.x + 1
        dirPos.y = dirPos.y + 1
    elseif diffPos.x <= -5 and diffPos.y <= -5 then
        effect = NM_ME_VP
        text = text .. "на северо-западе"
        dirPos.x = dirPos.x + 1
        dirPos.y = dirPos.y - 1
    elseif diffPos.x >= 5 and diffPos.y <= -5 then
        effect = NM_ME_N
        text = text .. "на северо-востоке"
        dirPos.x = dirPos.x - 1
        dirPos.y = dirPos.y - 1
    end
 
    if effect then
        doSendMagicEffect(dirPos, effect)
    end
    doPlayerSendTextMessage(cid, 22, "Синекожий гоблин находитс¤ " .. text)
 
    return true
end
 
Last edited by a moderator:
Solution
In my opinion, you should only create separate functions if you are planning to re-use that code multiple times, or if there is a large amount of code in the main function.

Lua:
function onUse(cid, item, frompos, item2, topos)
 
    local text = ""
    local effect = 0
    local playerPos = getPlayerPosition(cid)
    local diffPos = {x=(1643 - playerPos.x), y=(1613 - playerPos.y), z=(7 - playerPos.z)}
    local dist = math.sqrt(diffPos.x * diffPos.x + diffPos.y * diffPos.y + diffPos.z * diffPos.z);
  
    if dist <= 2 then
        text = text .. "здесь "
    elseif dist > 2 and dist <= 4 then
        text = text .. "близко "
    elseif dist > 4 and dist <= 100 then
        text = text .. ""
    elseif dist > 100 and dist <= 274 then
        text = text .. "далеко "
    else
        text = text .. "очень далеко "
    end
  
    if diffPos.x >= 5 and math.abs(diffPos.y) < 5 then
        effect = NM_ME_VL
        text = text .. "на востоке"
    elseif diffPos.x <= -5 and math.abs(diffPos.y) < 5 then
        effect = NM_ME_V
        text = text .. "на западе"
    elseif diffPos.y >= 5 and math.abs(diffPos.x) < 5 then
        effect = NM_ME_NL
        text = text .. "на юге"
    elseif diffPos.y <= -5 and math.abs(diffPos.x) < 5 then
        effect = NM_ME_NP
        text = text .. "на севере"
    elseif diffPos.x >= 5 and diffPos.y >= 5 then
        effect = NM_ME_L
        text = text .. "на юго-востоке"
    elseif diffPos.x <= -5 and diffPos.y >= 5 then
        effect = NM_ME_P
        text = text .. "на юго-западе"
    elseif diffPos.x <= -5 and diffPos.y <= -5 then
        effect = NM_ME_VP
        text = text .. "на северо-западе"
    elseif diffPos.x >= 5 and diffPos.y <= -5 then
        effect = NM_ME_N
        text = text .. "на северо-востоке"
    end
 
    if topos and effect then
        doSendMagicEffect(topos, effect)
    end
    doPlayerSendTextMessage(cid, 22, "Синекожий гоблин находитс¤ " .. text)
 
    return true
end


If you want the effect to be in the direction 1sqm from the player:
Lua:
function onUse(cid, item, frompos, item2, topos)
 
    local text = ""
    local effect = 0
    local playerPos = getPlayerPosition(cid)
    local diffPos = {x=(1643 - playerPos.x), y=(1613 - playerPos.y), z=(7 - playerPos.z)}
    local dist = math.sqrt(diffPos.x * diffPos.x + diffPos.y * diffPos.y + diffPos.z * diffPos.z);
    local dirPos = {x=playerPos.x, y=playerPos.y, z=playerPos.z}
   
    if dist <= 2 then
        text = text .. "здесь "
    elseif dist > 2 and dist <= 4 then
        text = text .. "близко "
    elseif dist > 4 and dist <= 100 then
        text = text .. ""
    elseif dist > 100 and dist <= 274 then
        text = text .. "далеко "
    else
        text = text .. "очень далеко "
    end
   
    if diffPos.x >= 5 and math.abs(diffPos.y) < 5 then
        effect = NM_ME_VL
        text = text .. "на востоке"
        dirPos.x = dirPos.x - 1
    elseif diffPos.x <= -5 and math.abs(diffPos.y) < 5 then
        effect = NM_ME_V
        text = text .. "на западе"
        dirPos.x = dirPos.x + 1
    elseif diffPos.y >= 5 and math.abs(diffPos.x) < 5 then
        effect = NM_ME_NL
        text = text .. "на юге"
        dirPos.y = dirPos.y + 1
    elseif diffPos.y <= -5 and math.abs(diffPos.x) < 5 then
        effect = NM_ME_NP
        text = text .. "на севере"
        dirPos.y = dirPos.y - 1
    elseif diffPos.x >= 5 and diffPos.y >= 5 then
        effect = NM_ME_L
        text = text .. "на юго-востоке"
        dirPos.x = dirPos.x - 1
        dirPos.y = dirPos.y + 1
    elseif diffPos.x <= -5 and diffPos.y >= 5 then
        effect = NM_ME_P
        text = text .. "на юго-западе"
        dirPos.x = dirPos.x + 1
        dirPos.y = dirPos.y + 1
    elseif diffPos.x <= -5 and diffPos.y <= -5 then
        effect = NM_ME_VP
        text = text .. "на северо-западе"
        dirPos.x = dirPos.x + 1
        dirPos.y = dirPos.y - 1
    elseif diffPos.x >= 5 and diffPos.y <= -5 then
        effect = NM_ME_N
        text = text .. "на северо-востоке"
        dirPos.x = dirPos.x - 1
        dirPos.y = dirPos.y - 1
    end
 
    if effect then
        doSendMagicEffect(dirPos, effect)
    end
    doPlayerSendTextMessage(cid, 22, "Синекожий гоблин находитс¤ " .. text)
 
    return true
end
thanks for the help. Everything works perfectly.

Скриншот 18-02-2022 011847.jpg
It remains only to adjust the direction of the pointers. But I can handle it
 
Back
Top