• 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!

Lua NPC travel by storage not working

drafenous

New Member
Joined
Nov 8, 2017
Messages
7
Reaction score
1
Hello my friends!
I'm making a NPC for travel to Gengia, Pyro and Oken in my server.

But my npc can't travel to destination on say "yes".

Here is my script:

Lua:
    if (msgcontains(msg, "gengia")) then
        if(vip.hasVip(cid) == true) then
               npcHandler:say("Do you want to sail to Gengia for free?",cid)
            Topic[cid] = 4
        elseif (Topic[cid] == 4) then
        if (msgcontains(msg, 'yes')) then
            doTeleportThing(cid,{x = 31270, y = 31181, z = 6})
            doSendMagicEffect({x = 31270, y = 31181, z = 6},CONST_ME_TELEPORT)
        else
            npcHandler:say("You dont have enough of gold.",cid)
        end
        else
            npcHandler:say("Sorry, only VIP Players can travel there.",cid)
        end
    end

Here is the NPC interaction:
vr6WCOt.png
 
Solution
The above code should work correctly, and Mummrik fixed a couple of other errors as well.
(putting the topic check and message check into the same line, removing the gold message (since it will never be reached), and reorganising the script to flow better.)
The only thing I'd change is removing the multiple extra parentheses.

This is why proper indentation is the first thing you should take care to learn.
When you properly indent the provided code, the issue becomes clear quickly.
Your 'yes' & 'topic[cid] == 4' if statements are hidden inside another if statement and due to this, the script never finds it when you reply to the npc.

your script properly tabbed, for demonstration.
Lua:
if (msgcontains(msg, "gengia")) then...
Hello my friends!
I'm making a NPC for travel to Gengia, Pyro and Oken in my server.

But my npc can't travel to destination on say "yes".

Here is my script:

Lua:
    if (msgcontains(msg, "gengia")) then
        if(vip.hasVip(cid) == true) then
               npcHandler:say("Do you want to sail to Gengia for free?",cid)
            Topic[cid] = 4
        elseif (Topic[cid] == 4) then
        if (msgcontains(msg, 'yes')) then
            doTeleportThing(cid,{x = 31270, y = 31181, z = 6})
            doSendMagicEffect({x = 31270, y = 31181, z = 6},CONST_ME_TELEPORT)
        else
            npcHandler:say("You dont have enough of gold.",cid)
        end
        else
            npcHandler:say("Sorry, only VIP Players can travel there.",cid)
        end
    end

Here is the NPC interaction:
vr6WCOt.png

This should work

Lua:
    if (msgcontains(msg, "gengia")) then
        if(vip.hasVip(cid) == true) then
            npcHandler:say("Do you want to sail to Gengia for free?",cid)
            Topic[cid] = 4
       else
            npcHandler:say("Sorry, only VIP Players can travel there.",cid)
       end
    elseif (Topic[cid] == 4 and msgcontains(msg, 'yes')) then
       doTeleportThing(cid,{x = 31270, y = 31181, z = 6})
       doSendMagicEffect({x = 31270, y = 31181, z = 6},CONST_ME_TELEPORT)
       Topic[cid] = nil
   end
 
The above code should work correctly, and Mummrik fixed a couple of other errors as well.
(putting the topic check and message check into the same line, removing the gold message (since it will never be reached), and reorganising the script to flow better.)
The only thing I'd change is removing the multiple extra parentheses.

This is why proper indentation is the first thing you should take care to learn.
When you properly indent the provided code, the issue becomes clear quickly.
Your 'yes' & 'topic[cid] == 4' if statements are hidden inside another if statement and due to this, the script never finds it when you reply to the npc.

your script properly tabbed, for demonstration.
Lua:
if (msgcontains(msg, "gengia")) then
   if(vip.hasVip(cid) == true) then
       npcHandler:say("Do you want to sail to Gengia for free?",cid)
       Topic[cid] = 4
   elseif (Topic[cid] == 4) then
       if (msgcontains(msg, 'yes')) then
           doTeleportThing(cid,{x = 31270, y = 31181, z = 6})
           doSendMagicEffect({x = 31270, y = 31181, z = 6},CONST_ME_TELEPORT)
       else
           npcHandler:say("You dont have enough of gold.",cid)
       end
   else
       npcHandler:say("Sorry, only VIP Players can travel there.",cid)
   end
end

Mummricks code without the extra parentheses.
Lua:
if msgcontains(msg, "gengia") then
   if vip.hasVip(cid) == true then
       npcHandler:say("Do you want to sail to Gengia for free?", cid)
       Topic[cid] = 4
   else
       npcHandler:say("Sorry, only VIP Players can travel there.", cid)
   end
elseif Topic[cid] == 4 and msgcontains(msg, "yes") then
   doTeleportThing(cid, {x = 31270, y = 31181, z = 6})
   doSendMagicEffect({x = 31270, y = 31181, z = 6}, CONST_ME_TELEPORT)
   Topic[cid] = nil
end

ps: give best answer to above, I'm just trying to help you learn where the error was.
 
Solution
The above code should work correctly, and Mummrik fixed a couple of other errors as well.
(putting the topic check and message check into the same line, removing the gold message (since it will never be reached), and reorganising the script to flow better.)
The only thing I'd change is removing the multiple extra parentheses.

This is why proper indentation is the first thing you should take care to learn.
When you properly indent the provided code, the issue becomes clear quickly.
Your 'yes' & 'topic[cid] == 4' if statements are hidden inside another if statement and due to this, the script never finds it when you reply to the npc.

your script properly tabbed, for demonstration.
Lua:
if (msgcontains(msg, "gengia")) then
   if(vip.hasVip(cid) == true) then
       npcHandler:say("Do you want to sail to Gengia for free?",cid)
       Topic[cid] = 4
   elseif (Topic[cid] == 4) then
       if (msgcontains(msg, 'yes')) then
           doTeleportThing(cid,{x = 31270, y = 31181, z = 6})
           doSendMagicEffect({x = 31270, y = 31181, z = 6},CONST_ME_TELEPORT)
       else
           npcHandler:say("You dont have enough of gold.",cid)
       end
   else
       npcHandler:say("Sorry, only VIP Players can travel there.",cid)
   end
end

Mummricks code without the extra parentheses.
Lua:
if msgcontains(msg, "gengia") then
   if vip.hasVip(cid) == true then
       npcHandler:say("Do you want to sail to Gengia for free?", cid)
       Topic[cid] = 4
   else
       npcHandler:say("Sorry, only VIP Players can travel there.", cid)
   end
elseif Topic[cid] == 4 and msgcontains(msg, "yes") then
   doTeleportThing(cid, {x = 31270, y = 31181, z = 6})
   doSendMagicEffect({x = 31270, y = 31181, z = 6}, CONST_ME_TELEPORT)
   Topic[cid] = nil
end

ps: give best answer to above, I'm just trying to help you learn where the error was.
I like that you explain what was wrong and hopefully teach people how to code/script :)
Edit:
I should follow your lead :D
 
The above code should work correctly, and Mummrik fixed a couple of other errors as well.
(putting the topic check and message check into the same line, removing the gold message (since it will never be reached), and reorganising the script to flow better.)
The only thing I'd change is removing the multiple extra parentheses.

This is why proper indentation is the first thing you should take care to learn.
When you properly indent the provided code, the issue becomes clear quickly.
Your 'yes' & 'topic[cid] == 4' if statements are hidden inside another if statement and due to this, the script never finds it when you reply to the npc.

your script properly tabbed, for demonstration.
Lua:
if (msgcontains(msg, "gengia")) then
   if(vip.hasVip(cid) == true) then
       npcHandler:say("Do you want to sail to Gengia for free?",cid)
       Topic[cid] = 4
   elseif (Topic[cid] == 4) then
       if (msgcontains(msg, 'yes')) then
           doTeleportThing(cid,{x = 31270, y = 31181, z = 6})
           doSendMagicEffect({x = 31270, y = 31181, z = 6},CONST_ME_TELEPORT)
       else
           npcHandler:say("You dont have enough of gold.",cid)
       end
   else
       npcHandler:say("Sorry, only VIP Players can travel there.",cid)
   end
end

Mummricks code without the extra parentheses.
Lua:
if msgcontains(msg, "gengia") then
   if vip.hasVip(cid) == true then
       npcHandler:say("Do you want to sail to Gengia for free?", cid)
       Topic[cid] = 4
   else
       npcHandler:say("Sorry, only VIP Players can travel there.", cid)
   end
elseif Topic[cid] == 4 and msgcontains(msg, "yes") then
   doTeleportThing(cid, {x = 31270, y = 31181, z = 6})
   doSendMagicEffect({x = 31270, y = 31181, z = 6}, CONST_ME_TELEPORT)
   Topic[cid] = nil
end

ps: give best answer to above, I'm just trying to help you learn where the error was.


OMG, thanks!
It's work fine alot...
i'm trying to learn LUA Script and this is my frist try for create an NPC with storage check to travel for vip areas.

I also liked that you explained to me how it works, what in the Brazilian forums about Open Tibia the staff does not do very often ... What made me even more grateful!

Thanks alot!
 
Back
Top