• 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 [TFS 0.3.6] City Guide - doPlayerAddMapMark

potinho

Advanced OT User
Joined
Oct 11, 2009
Messages
1,403
Solutions
17
Reaction score
151
Location
Brazil
Hello everyone, everything good?

I tried using the guide script below, which would help me a lot. But when the NPC mark the position on the map, it gives the error below on my console. can you help me?

1631889197774.png



npcguide.lua

Lua:
-- City Guide, adding mapmarks to locations by Limos
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
 
function onCreatureAppear(cid)                npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid)            npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg)            npcHandler:onCreatureSay(cid, type, msg) end
function onThink()                    npcHandler:onThink() end
 
local config = {
    ["Riona"] = {mark = {x = 1000, y = 1000, z = 7}, type = MAPMARK_TICK, name = "Riona's Tool Shop", text = "find", info = "Riona sells tools and backpacks."},  
    ["Deposit"] = {mark = {x = 1000, y = 1000, z = 7}, type = MAPMARK_TICK, name = "Deposit", text = "find the"},
    ["Boat"] = {mark = {x = 1000, y = 1000, z = 7}, type = MAPMARK_TICK, name = "Boat", text = "find the", info = "You can use the boat to travel to other cities."},
    ["Rotworms"] = {mark = {x = 1000, y = 1000, z = 7}, type = MAPMARK_TICK, name = "Rotworms", text = "hunt"},
    ["Cyclops"] = {mark = {x = 1000, y = 1000, z = 7}, type = MAPMARK_TICK, name = "Cyclops", text = "hunt"},
    ["Dragons"] = {mark = {x = 1000, y = 1000, z = 7}, type = MAPMARK_TICK, name = "Dragons", text = "hunt"},
    ["Demons"] = {mark = {x = 1000, y = 1000, z = 7}, type = MAPMARK_TICK, name = "Demons", text = "hunt"}
}

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
 
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
 
     local function addCptl(first, rest)
          return first:upper()..rest:lower()
    end
 
    local x = config[msg:gsub("(%a)([%w_']*)", addCptl)]
 
    if(x and talkState[talkUser] ~= 2) then
        selfSay('Do you want me to add a mapmark where you can '..x.text..' '..msg..'?', cid)
        xmsg = msg
        talkState[talkUser] = 1
    elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 1) then
        x = config[xmsg:gsub("(%a)([%w_']*)", addCptl)]
        selfSay('Here you are.', cid)
        doPlayerAddMapMark(cid, x.mark,x.type,x.name)
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'no') and talkState[talkUser] == 1) then
        selfSay('Ok then.', cid)
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'information')) then
        selfSay('About which location do you want more information?', cid)
        talkState[talkUser] = 2
    elseif(talkState[talkUser] == 2) then
        if(x) then
            if(x.info) then
                selfSay('' .. x.info, cid)
            else
                selfSay('Sorry, I can\'t give you any useful information about this location.', cid)
            end
        else
            selfSay('I don\'t know about this place, look in the {list} which locations I know.', cid)
        end
        talkState[talkUser] = 0
    elseif (msgcontains(msg, 'mapmark')) then
        selfSay("Which location do you want to go?", cid)
        talkState[talkUser] = 0
    elseif(msgcontains(msg, 'list')) then
        selfSay('Here is my list, tell me where you want to go or you can also ask me for {information} about a location.', cid)
        local text = 'Locations\n'
        for i, x in pairs(config) do
            text = text .. '\n' .. i .. ''
        end
        doShowTextDialog(cid, 1949, '' .. text)
        talkState[talkUser] = 0
    else
        local messages = {'Sorry, I have no idea what you mean with '..msg..'.', 'What?', 'What do you mean?', 'Hmm?', 'Tell me a location, you can look in the {list} which locations I know.'}
        selfSay(messages[math.random(#messages)], cid)
    end
    return true
end
 
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

In /data/lib/101-compat i have:

doAddMapMark = doPlayerAddMapMark
 
Last edited:
Solution
Still got some errors:

1631908615297.png
Post automatically merged:

Found one problem: i changed "LuaScriptInterface" to "LuaInterface", now i got 4 errors:

1631911000865.png

And there is in those lines:

C++:
void ProtocolGame::sendAddMarker(const Position& pos, MapMarks_t markType, const std::string& desc)
{
    NetworkMessage_ptr msg = getOutputBuffer();
    if(msg)
    {
        TRACK_MESSAGE(msg);
        msg->AddByte(0xDD);
        msg->AddPosition(pos);
        msg->AddByte(markType);
        msg->AddString(desc);
    }
}
Post automatically merged:

Found solution:

Change

C++:
void ProtocolGame::sendAddMarker(const Position& pos, MapMarks_t markType, const std::string& desc)
{
    NetworkMessage_ptr msg = getOutputBuffer();
    if(msg)
    {...
Still got some errors:

1631908615297.png
Post automatically merged:

Found one problem: i changed "LuaScriptInterface" to "LuaInterface", now i got 4 errors:

1631911000865.png

And there is in those lines:

C++:
void ProtocolGame::sendAddMarker(const Position& pos, MapMarks_t markType, const std::string& desc)
{
    NetworkMessage_ptr msg = getOutputBuffer();
    if(msg)
    {
        TRACK_MESSAGE(msg);
        msg->AddByte(0xDD);
        msg->AddPosition(pos);
        msg->AddByte(markType);
        msg->AddString(desc);
    }
}
Post automatically merged:

Found solution:

Change

C++:
void ProtocolGame::sendAddMarker(const Position& pos, MapMarks_t markType, const std::string& desc)
{
    NetworkMessage_ptr msg = getOutputBuffer();
    if(msg)
    {
        TRACK_MESSAGE(msg);
        msg->AddByte(0xDD);
        msg->AddPosition(pos);
        msg->AddByte(markType);
        msg->AddString(desc);
    }

TO

C++:
void ProtocolGame::sendAddMarker(const Position& pos, MapMarks_t markType, const std::string& desc)
{
    NetworkMessage_ptr msg = getOutputBuffer();
    if(msg)
    {
        TRACK_MESSAGE(msg);
        msg->put<char>(0xDD);
        msg->putPosition(pos);
        msg->put<char>(markType);
        msg->putString(desc);
    }
}
 
Last edited:
Solution
Back
Top