• 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 Help on Script Npc Carlos Trade

Mikii

Active Member
Joined
Mar 28, 2013
Messages
197
Reaction score
46
I nedding opening trade while player talking on npc and having storage... More don't work my idea for this..

NPC is Carlos ~~ I sending tutorial and open trade chanel, more don't open trade chanel with myscript:


Code:
    elseif (msgcontains(msg, 'yes') or msgcontains(msg, 'trade')) and getPlayerStorageValue(cid, c.storage) == 6 then   
        if talkState[talkUser] == 1 then 
            if (msg == "yes") then
                npcHandler:say("No, no, you have to say {trade}.", cid)
            else
           

                    local shopModule = ShopModule:new()
                    npcHandler:addModule(shopModule)

                    shopModule:addSellableItem({'meat', 'meat'}, 2666, 2, 'meat')
                    shopModule:addSellableItem({'ham', 'ham'}, 2671, 2, 'ham')       
                    doCreatureSay(cid, "trade", TALKTYPE_CHANNEL_NP , getCreaturePosition(cid))   

                --setPlayerStorageValue(cid, c.storage, 7)
                npcHandler:say("Very nice! Food for me! Sell it to me, fast! Once you sold your food to me, just say '{ready}' to let me know you are done.", cid)
                doSendTutorial(cid, 13)   
                           
            end
       
        end   
    elseif (msgcontains(msg, 'yes') or msgcontains(msg, 'ready')) and getPlayerStorageValue(cid, c.storage) == 7 then 

--Continue


I'am geting hide doCreatureSay for this.. rsrsrsrs More Don't work.
Need Help....
 
Move the shop module stuff outside of onCreatureSay, and use this to open the trade window:
Code:
ShopModule.requestTrade(cid, nil, nil, {module = {npcHandler = npcHandler}}, nil)
 
@Mark
I could not understand your explanation very well mark. If I move out npc interprets the word "trade" as a command, and not as a message. The user can only open once that window. 100% rl.


See me all code. [ Shearch for this: "npcHandler:say("No, no, you have to say {trade}.", cid)" only here open trade. No more.
PHP:
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 c = {
    storage = 1020,
}
local story = {}
--local shopModule = ShopModule:new()
--npcHandler:addModule(shopModule)
--shopModule:addSellableItem({'meat', 'meat'}, 2666, 2, 'meat')
--shopModule:addSellableItem({'ham', 'ham'}, 2671, 2, 'ham')
local function cancelStory(cid)
    if not(story[cid]) then return true end
    for _, eventId in pairs(story[cid]) do
        stopEvent(eventId)
    end
    story[cid] = {}
end
function creatureFarewell(cid)
    if not(isPlayer(cid)) then return true end
    cancelStory(cid)
    npcHandler:say('Good bye then.', cid)
    return true
end

function greetCallback(cid)
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    if getPlayerStorageValue(cid, c.storage) < 1 then
        npcHandler:setMessage(MESSAGE_GREET, "Be greeted, " .. getPlayerName(cid) .. "! As a tailor and merchant I have to say - we need to do something about your {outfit}, shall we?")
        setPlayerStorageValue(cid, c.storage, 1)
        talkState[talkUser] = 1    
    elseif getPlayerStorageValue(cid, c.storage) == 1 then
            npcHandler:setMessage(MESSAGE_GREET, "Hey, I thought you were going to run away, but luckily you came back. I'll show you how to change your {outfit}, okay?")
            talkState[talkUser] = 1        
    elseif getPlayerStorageValue(cid, c.storage) == 2 then
            npcHandler:setMessage(MESSAGE_GREET, "Welcome back! You know, after providing my little outfit service, I like to ask a little favour of you. Can you {help} me?")
            talkState[talkUser] = 1  

    elseif getPlayerStorageValue(cid, c.storage) == 3 then
          npcHandler:setMessage(MESSAGE_GREET, "Oh hey " .. getPlayerName(cid) .. ", you didn't answer my question yet - could you help me get some {food}? I'll even give you some gold for it.")
          talkState[talkUser] = 1
      
    elseif getPlayerStorageValue(cid, c.storage) == 4 then
          npcHandler:setMessage(MESSAGE_GREET, "Welcome back " .. getPlayerName(cid) .. "!, I hope you changed your mind and will bring me some meat? I'll even give you some gold for it.")
            talkState[talkUser] = 1
    elseif getPlayerStorageValue(cid, c.storage) == 5 then
          npcHandler:setMessage(MESSAGE_GREET, "Welcome back " .. getPlayerName(cid) .. "! Did you have a successful hunt and carry a piece of {meat} or ham with you?")
            talkState[talkUser] = 1        

    elseif getPlayerStorageValue(cid, c.storage) == 6 then
          npcHandler:setMessage(MESSAGE_GREET, "Welcome back " .. getPlayerName(cid) .. "! Do you still have that piece of meat or ham? If so, please ask me for a {trade} and I'll give you some gold for it.")
            talkState[talkUser] = 1
    elseif getPlayerStorageValue(cid, c.storage) == 7 then
          npcHandler:setMessage(MESSAGE_GREET, "Hey there " .. getPlayerName(cid) .. "! Well, that's how trading with NPCs like me works. I think you are ready now to cross the bridge to Rookgaard! Take care!")
            setPlayerStorageValue(cid, c.storage, 8)
            talkState[talkUser] = 1    

    elseif getPlayerStorageValue(cid, c.storage) == 8 then
          npcHandler:setMessage(MESSAGE_GREET, "Hello again, " .. getPlayerName(cid) .. "!  What are you still doing here? You should head over the bridge to Rookgaard village now!")
                npcHandler:releaseFocus(cid)

  end
    return true
end

                
function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
    if (msgcontains(msg, 'yes') or msgcontains(msg, 'quest') or msgcontains(msg, 'outifit')) and getPlayerStorageValue(cid, c.storage) <= 1 then
        if talkState[talkUser] == 1 then
            setPlayerStorageValue(cid, c.storage, 2)    
            npcHandler:say("Very well. Just choose an outfit and a colour combination that suits you. You can open this dialogue anytime by right-clicking on yourself and selecting 'Set Outfit'. Just try it and then talk to me again!", cid)
            doSendTutorial(cid, 12)        
            talkState[talkUser] = 1
            npcHandler:releaseFocus(cid)
        end
    elseif (msgcontains(msg, 'yes') or msgcontains(msg, 'help') or msgcontains(msg, 'food')) and getPlayerStorageValue(cid, c.storage) == 2 then
        if talkState[talkUser] == 1 then
            npcHandler:say("You see, I'm quite hungry from standing here all day. Could you get me some {food}?", cid)
            setPlayerStorageValue(cid, c.storage, 3)
            talkState[talkUser] = 1
        end
    elseif (msgcontains(msg, 'yes') or msgcontains(msg, 'food')) and getPlayerStorageValue(cid, c.storage) == 3 then
        if talkState[talkUser] == 1 then
            npcHandler:say("Thank you! I would do it myself, but I don't have a weapon. Just kill a few rabbits or deer, loot food from them and bring me one piece of {meat} or ham, will you?", cid)
            setPlayerStorageValue(cid, c.storage, 4)
        end
    elseif (msgcontains(msg, 'yes') or msgcontains(msg, 'food') or msgcontains(msg, 'meat')) and getPlayerStorageValue(cid, c.storage) == 4 then
        if talkState[talkUser] == 1 then
        npcHandler:say("Splendid. I'll be awaiting your return eagerly. Don't forget that you can click on the 'Chase Opponent' button to run after those fast creatures. Good {bye} for now!", cid)
        setPlayerStorageValue(cid, c.storage, 5)
        npcHandler:releaseFocus(cid)
        end
    elseif (msgcontains(msg, 'yes') or msgcontains(msg, 'food') or msgcontains(msg, 'meat')) and getPlayerStorageValue(cid, c.storage) == 5 then
        if talkState[talkUser] == 1 then
            if (getPlayerItemCount(cid, 2666) >= 1) or (getPlayerItemCount(cid, 2671) >= 1) then
                npcHandler:say("What's that delicious smell? That must be a piece of meat! Please hurry, simply ask me for a {trade} and I'll give you two gold pieces for it!", cid)
                setPlayerStorageValue(cid, c.storage, 6)
                talkState[talkUser] = 1

            else
                npcHandler:say("Hmm. No, I don't think you have something with you that I'd like to eat. Please come back once you looted a piece of meat or a piece of ham from a rabbit or deer.", cid)
                npcHandler:releaseFocus(cid)
            end
        end
    elseif (msgcontains(msg, 'yes') or msgcontains(msg, 'trade')) and getPlayerStorageValue(cid, c.storage) == 6 then
        if talkState[talkUser] == 1 then
            if (msg == "yes") then
                npcHandler:say("No, no, you have to say {trade}.", cid)
            else
        
        

                --doCreatureSay(cid, "trade", TALKTYPE_CHANNEL_O , getCreaturePosition(cid))
                ShopModule.requestTrade(cid, nil, nil, {module = {npcHandler = npcHandler}}, nil)
                --setPlayerStorageValue(cid, c.storage, 7)
                npcHandler:say("Very nice! Food for me! Sell it to me, fast! Once you sold your food to me, just say '{ready}' to let me know you are done.", cid)
                doSendTutorial(cid, 13)
                        
            end
    
        end
    elseif (msgcontains(msg, 'yes') or msgcontains(msg, 'ready')) and getPlayerStorageValue(cid, c.storage) == 7 then
        
            cancelStory(cid)
            story[cid] = selfStory({"Well, that's how trading with NPCs like me works. I think you are ready now to cross the bridge to Rookgaard, just follow the path to the northwest. Good luck, " .. getPlayerName(cid) .. "...", "And by the way: if you thought all of this was boring and you'd rather skip the tutorial with your next character, just say 'skip tutorial' to Santiago. ...", "Then you'll miss out on those nice items and experience though. Hehehe! It's your choice. Well, take care for now!"}, cid, 6000)
            setPlayerStorageValue(cid, c.storage, 8)
            npcHandler:releaseFocus(cid)

    elseif msgcontains(msg, "no") then    
        selfSay('Good bye then.', cid)
        talkState[talkUser] = 0
        npcHandler:releaseFocus(cid)
    end
    return true
end


npcHandler:setCallback(CALLBACK_FAREWELL, creatureFarewell)
npcHandler:setCallback(CALLBACK_CREATURE_DISAPPEAR, creatureFarewell)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:setCallback(CALLBACK_GREET, greetCallback)
npcHandler:setMessage(MESSAGE_WALKAWAY, "Good bye then.")
npcHandler:addModule(FocusModule:new())
 
Last edited:
Back
Top