• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Trading NPC

ZeeBeast

Preferable Beta Tester
Joined
Dec 5, 2013
Messages
206
Reaction score
10
Location
United States
Hey everyone. I was wondering if it is possible to make an NPC that gives you a certain item(s) if you give it a certain item(s).
For example. An NPC that gives you a golden amulet when you give it a gold nugget and a gold ingot.
If it is possible, can someone please help me.
 
Jetro's Mission quest npc 1.0
: I edited it a little, I think it now give you 2 items, you can change it.
Edit: i changed it for you, now if you give him gold ingot and gold nugget he wil lgive you golden amulet.
Code:
--[[ Jetro's Mission quest npc 1.0
    ALL CREDITS TO JETRO
    ]]--
local config =
{
    requirements =
    {
        storage = 0, --STORAGE REQUIRED
        requiredlevel = false, --REQUIRES LEVEL? TRUE OR FALSE
        level = 300, --LEVEL (IF REQUIRED)
        requiredpremium = false, --REQUIRES PREMIUM? TRUE OR FALSE
        itemsrequired = --ITEMS REQUIRED'S LIST
        {
            [2157] = {amount = 1},
            [9971] = {amount = 1}
        },
    },

    rewards =
    {


        expvalue = 10000000, --EXPERIENCE. (false if it won't give exp)
        expcolor = 35, --COLOR OF ANIMATED TEXT: min = 1, max = 255
        money = 1000000, --MONEY. (false if it won't give money)
        reward = --ITEMS'S LIST (false if it won't give items)
        {
            [2130] = {amount = 1},
        },
    }
}

local function getRequiredThings(cid)
        local msg = ""
        local itemsleft = { }

            for i,x in pairs(config.requirements.itemsrequired) do
                local item = getPlayerItemCount(cid, i)
                if (item < x.amount) then
                    table.insert(itemsleft, x.amount - item.. "x "..getItemNameById(i))
                end
            end

            msg = #itemsleft > 0 and "Items: "..table.concat(itemsleft, ", ") or ""

        return msg
    end




local itemscap = 0

for i,x in pairs (config.requirements.itemsrequired) do
    itemscap = itemscap + getItemWeightById(i, x.amount)
end

local requir = {}
for i,x in pairs(config.requirements.itemsrequired) do
    table.insert (requir, x.amount .. "x "..getItemNameById(i))
end






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

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local cap = getPlayerFreeCap(cid)
    local s = getPlayerStorageValue(cid, config.requirements.storage) == 1 and true or false
    local lv = getPlayerLevel(cid)
    local prm = isPremium(cid)


    --LIST OF MESSAGES THAT THE NPC WILL SAY--
    local msgs =
    {
        requirements = "If you want to make a very nice deal with me, listen up. I need "..table.concat(requir, ", ").. ". Do you have  "..(#requir > 1 and "them" or "it").. "?",
        reward = "And here's my part of the deal.",
        done = "You have already done this mission.",
        notpremium = "Sorry, only players with premium account can make this mission.",
        notitems = "I think you missed something there, you don't have all the items "..getRequiredThings(cid),
        notlevel = "I think you should be atleast level 300 before demanding such a trade {"..config.requirements.level.."}",
        wrong = "Huh?",
        negation = "Ok, maybe next time.."
    }


    local rq = getRequiredThings(cid)


    if (msgcontains(msg, 'mission')) then
        if (config.requirements.requiredpremium == true and not prm ) then
            return selfSay(msgs.notpremium, cid)
        end
        if (s == true)then
            return selfSay(msgs.done, cid)
        end

        if (config.requirements.requiredlevel == true and lv < config.requirements.level) then
            return selfSay(msgs.notlevel, cid)
        end
        selfSay(msgs.requirements,cid)
        talk_state = 1

    elseif (msgcontains(msg, "yes")) and talk_state == 1 then
        if ( rq == "" ) then
            if (cap < itemscap) then
                return selfSay("Sorry, you don't have enough capacity to carry the reward. All weights items.cap", cid)
            end
            if (config.rewards.expvalue ~= false) then
                doPlayerAddExp(cid, config.rewards.expvalue)
                if (config.rewards.expcolor > 255 or config.rewards.expcolor <= 0) then
                    config.rewards.expcolor = math.random(255)
                end
                doSendAnimatedText(getThingPos(cid), config.rewards.expvalue, config.rewards.expcolor)
            end

            if (config.rewards.money ~= false) then
                doPlayerAddMoney(cid, config.rewards.money)
            end

            if (config.rewards.reward ~= false) then
                for i,x in pairs (config.rewards.reward) do
                    doPlayerAddItem(cid, i, x.amount)
                end
            end

            for i,x in pairs (config.requirements.itemsrequired) do
                doPlayerRemoveItem(cid, i, x.amount)
            end
            selfSay(msgs.reward.."".. rq, cid)
            talk_state = 0

        else
            selfSay("You still don't have all items, you still need "..rq, cid)
            talk_state = 0
        end
    elseif (msgcontains(msg, "no") and talk_state == 1 ) then
        selfSay(msgs.negation, cid)
        talk_state = 0
    else
        selfSay(msgs.wrong, cid)
    end


return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Jetro's Mission quest npc 1.0
: I edited it a little, I think it now give you 2 items, you can change it.
Edit: i changed it for you, now if you give him gold ingot and gold nugget he wil lgive you golden amulet.
Code:
--[[ Jetro's Mission quest npc 1.0
    ALL CREDITS TO JETRO
    ]]--
local config =
{
    requirements =
    {
        storage = 0, --STORAGE REQUIRED
        requiredlevel = false, --REQUIRES LEVEL? TRUE OR FALSE
        level = 300, --LEVEL (IF REQUIRED)
        requiredpremium = false, --REQUIRES PREMIUM? TRUE OR FALSE
        itemsrequired = --ITEMS REQUIRED'S LIST
        {
            [2157] = {amount = 1},
            [9971] = {amount = 1}
        },
    },

    rewards =
    {


        expvalue = 10000000, --EXPERIENCE. (false if it won't give exp)
        expcolor = 35, --COLOR OF ANIMATED TEXT: min = 1, max = 255
        money = 1000000, --MONEY. (false if it won't give money)
        reward = --ITEMS'S LIST (false if it won't give items)
        {
            [2130] = {amount = 1},
        },
    }
}

local function getRequiredThings(cid)
        local msg = ""
        local itemsleft = { }

            for i,x in pairs(config.requirements.itemsrequired) do
                local item = getPlayerItemCount(cid, i)
                if (item < x.amount) then
                    table.insert(itemsleft, x.amount - item.. "x "..getItemNameById(i))
                end
            end

            msg = #itemsleft > 0 and "Items: "..table.concat(itemsleft, ", ") or ""

        return msg
    end




local itemscap = 0

for i,x in pairs (config.requirements.itemsrequired) do
    itemscap = itemscap + getItemWeightById(i, x.amount)
end

local requir = {}
for i,x in pairs(config.requirements.itemsrequired) do
    table.insert (requir, x.amount .. "x "..getItemNameById(i))
end






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

function creatureSayCallback(cid, type, msg)
    if(not npcHandler:isFocused(cid)) then
        return false
    end
    local cap = getPlayerFreeCap(cid)
    local s = getPlayerStorageValue(cid, config.requirements.storage) == 1 and true or false
    local lv = getPlayerLevel(cid)
    local prm = isPremium(cid)


    --LIST OF MESSAGES THAT THE NPC WILL SAY--
    local msgs =
    {
        requirements = "If you want to make a very nice deal with me, listen up. I need "..table.concat(requir, ", ").. ". Do you have  "..(#requir > 1 and "them" or "it").. "?",
        reward = "And here's my part of the deal.",
        done = "You have already done this mission.",
        notpremium = "Sorry, only players with premium account can make this mission.",
        notitems = "I think you missed something there, you don't have all the items "..getRequiredThings(cid),
        notlevel = "I think you should be atleast level 300 before demanding such a trade {"..config.requirements.level.."}",
        wrong = "Huh?",
        negation = "Ok, maybe next time.."
    }


    local rq = getRequiredThings(cid)


    if (msgcontains(msg, 'mission')) then
        if (config.requirements.requiredpremium == true and not prm ) then
            return selfSay(msgs.notpremium, cid)
        end
        if (s == true)then
            return selfSay(msgs.done, cid)
        end

        if (config.requirements.requiredlevel == true and lv < config.requirements.level) then
            return selfSay(msgs.notlevel, cid)
        end
        selfSay(msgs.requirements,cid)
        talk_state = 1

    elseif (msgcontains(msg, "yes")) and talk_state == 1 then
        if ( rq == "" ) then
            if (cap < itemscap) then
                return selfSay("Sorry, you don't have enough capacity to carry the reward. All weights items.cap", cid)
            end
            if (config.rewards.expvalue ~= false) then
                doPlayerAddExp(cid, config.rewards.expvalue)
                if (config.rewards.expcolor > 255 or config.rewards.expcolor <= 0) then
                    config.rewards.expcolor = math.random(255)
                end
                doSendAnimatedText(getThingPos(cid), config.rewards.expvalue, config.rewards.expcolor)
            end

            if (config.rewards.money ~= false) then
                doPlayerAddMoney(cid, config.rewards.money)
            end

            if (config.rewards.reward ~= false) then
                for i,x in pairs (config.rewards.reward) do
                    doPlayerAddItem(cid, i, x.amount)
                end
            end

            for i,x in pairs (config.requirements.itemsrequired) do
                doPlayerRemoveItem(cid, i, x.amount)
            end
            selfSay(msgs.reward.."".. rq, cid)
            talk_state = 0

        else
            selfSay("You still don't have all items, you still need "..rq, cid)
            talk_state = 0
        end
    elseif (msgcontains(msg, "no") and talk_state == 1 ) then
        selfSay(msgs.negation, cid)
        talk_state = 0
    else
        selfSay(msgs.wrong, cid)
    end


return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Wouldn't I also need an xml document telling the name and look type of this npc?
 
yes. in data/npc make new .xml and paste:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Trader" script="trademe.lua" walkinterval="0" floorchange="0">
    <health now="150" max="150"/>
    <look type="309" head="0" body="0" legs="0" feet="0"/>
</npc>
the jetro script should be in data/npc/scripts named "trademe"
 
yes. in data/npc make new .xml and paste:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Trader" script="trademe.lua" walkinterval="0" floorchange="0">
    <health now="150" max="150"/>
    <look type="309" head="0" body="0" legs="0" feet="0"/>
</npc>
the jetro script should be in data/npc/scripts named "trademe"
Thank you very much.
 
Code:
    if (msgcontains(msg, 'mission')) then
        if (config.requirements.requiredpremium == true and not prm ) then
            return selfSay(msgs.notpremium, cid)
        end
        if (s == true)then
            return selfSay(msgs.done, cid)
        end
Is there a way to make this so it replies to more than just 'mission'?
 
Yes, I will try in a bit. I need to learn howto edit npcs properly myself. But right now i am busy, will post when I have tried the npc at my own server and post here if I fail or succeed. But I think I can manage, shouldn't be too hard.

By the way, please tell me what you want to say and what you want npc to say..
 
It has 5 missions+, I'd rather focus editing this one with 1 quest only. Seems alot easier to edit..
I doubt he can edit it himself "Wouldn't I also need an xml document telling the name and look type of this npc?"
But as soon as I know what he want npc to say, or just give me an example, I'll start trying.
 
Back
Top