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

Npc that trades 2 different items for one item.

mrlaffo

New Member
Joined
Jan 11, 2013
Messages
23
Reaction score
0
Hello, i'm in need of a npc that would exchange
For example:
1 magic sword 100 demonic essences
To:
Warlord sword

Is there anyone out there that might have this script i can use for my 8.6 EVO ot ?
 
How many items in total? Can you make a list and an example of the npc conversation ingame (how it will look like when you talk to the npc).
 
me: Hi
npc: Hello there NAME! I'm trading my special weapons for your items !
me: Weapons
npc: You can trade yourself a Warlord sword, Spellbook of dark mysteries and Royal crossbow
me: Royal crossbow
Npc: Do you want to exchange arbalest and 100 demonic essences for a royal crossbow ?

Like that with all items
Warlord sword = 100 demonic essence + magic sword
spellbook of d = 100 demonic essence + spellbook of lost souls
royal crossbow = 100 demonic essence + arbalest

These items for now, but i might add a mace and a axe for the NPC for knights benefits.

You can change the npc conversations but i would like it something similar
 
Also i'm new to this scripting. I'm actually learning could you add me somewhere and just help me sometimes ? I'm not looking for someone to make my scripts for me but i'm looking for someone that might coach me a little bit. So i can learn it properly. This npc is the current problem we gotta fix
 
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local talkState, xmsg = {}, {}

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 items = {
   ["warlord sword"] = {
     payitems = {
       {id = 6500, count = 100},
       {id = 2400, count = 1},
     },
     rewarditem = 2408
   },
   ["spellbook of dark mysteries"] = {
     payitems = {
       {id = 6500, count = 100},
       {id = 8903, count = 1},
     },
     rewarditem = 8918
   },
   ["royal crossbow"] = {
     payitems = {
       {id = 6500, count = 100},
       {id = 5803, count = 1},
     },
     rewarditem = 8851
   }
}

local function getItemsFromTable(itemtable)
     local text = ""
     for v = 1, #itemtable do
         count, info = itemtable[v].count, getItemInfo(itemtable[v].id)
         local ret = ", "
         if v == 1 then
             ret = ""
         elseif v == #itemtable then
             ret = " and "
         end
         text = text .. ret
         text = text .. (count > 1 and count or info.article).." "..(count > 1 and info.plural or info.name)
     end
     return text
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, "weapons") then
         selfSay("You can trade yourself a {warlord sword}, {spellbook of dark mysteries} and {royal crossbow}.", cid)
         talkState[talkUser] = 1
     elseif items[msg:lower()] and talkState[talkUser] == 1 then
         local x = items[msg:lower()]
         local info = getItemInfo(x.rewarditem)
         selfSay("Do you want to exchange "..getItemsFromTable(x.payitems).." for "..info.article.." "..info.name.."?", cid)
         talkState[talkUser] = 2
         xmsg[cid] = msg
     elseif msgcontains(msg, "yes") and items[xmsg[cid]:lower()] and talkState[talkUser] == 2 then
         local x, n = items[xmsg[cid]:lower()], 0
         for c = 1, #x.payitems do
             if getPlayerItemCount(cid, x.payitems[c].id) >= x.payitems[c].count then
                 n = n + 1
             end
         end
         if n == #x.payitems then
             for r = 1, #x.payitems do
                 doPlayerRemoveItem(cid, x.payitems[r].id, x.payitems[r].count)
             end
             doPlayerAddItem(cid, x.rewarditem, 1)
             selfSay("Great, here is your "..xmsg[cid]..".", cid)
         else
             selfSay("You don't have all items, you need "..getItemsFromTable(x.payitems)..".", cid)
         end  
         talkState[talkUser] = 0
         xmsg[cid] = ""
     end
     return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

local talkState, xmsg = {}, {}

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 items = {
   ["warlord sword"] = {
     payitems = {
       {id = 6500, count = 100},
       {id = 2400, count = 1},
     },
     rewarditem = 2408
   },
   ["spellbook of dark mysteries"] = {
     payitems = {
       {id = 6500, count = 100},
       {id = 8903, count = 1},
     },
     rewarditem = 8918
   },
   ["royal crossbow"] = {
     payitems = {
       {id = 6500, count = 100},
       {id = 5803, count = 1},
     },
     rewarditem = 8851
   }
}

local function getItemsFromTable(itemtable)
     local text = ""
     for v = 1, #itemtable do
         count, info = itemtable[v].count, getItemInfo(itemtable[v].id)
         local ret = ", "
         if v == 1 then
             ret = ""
         elseif v == #itemtable then
             ret = " and "
         end
         text = text .. ret
         text = text .. (count > 1 and count or info.article).." "..(count > 1 and info.plural or info.name)
     end
     return text
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, "weapons") then
         selfSay("You can trade yourself a {warlord sword}, {spellbook of dark mysteries} and {royal crossbow}.", cid)
         talkState[talkUser] = 1
     elseif items[msg:lower()] and talkState[talkUser] == 1 then
         local x = items[msg:lower()]
         local info = getItemInfo(x.rewarditem)
         selfSay("Do you want to exchange "..getItemsFromTable(x.payitems).." for "..info.article.." "..info.name.."?", cid)
         talkState[talkUser] = 2
         xmsg[cid] = msg
     elseif msgcontains(msg, "yes") and items[xmsg[cid]:lower()] and talkState[talkUser] == 2 then
         local x, n = items[xmsg[cid]:lower()], 0
         for c = 1, #x.payitems do
             if getPlayerItemCount(cid, x.payitems[c].id) >= x.payitems[c].count then
                 n = n + 1
             end
         end
         if n == #x.payitems then
             for r = 1, #x.payitems do
                 doPlayerRemoveItem(cid, x.payitems[r].id, x.payitems[r].count)
             end
             doPlayerAddItem(cid, x.rewarditem, 1)
             selfSay("Great, here is your "..xmsg[cid]..".", cid)
         else
             selfSay("You don't have all items, you need "..getItemsFromTable(x.payitems)..".", cid)
         end 
         talkState[talkUser] = 0
         xmsg[cid] = ""
     end
     return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

Hey, it works great but there is only 1 problem.
When i write HI to him he says
16:06 Robbie the dealer: Welcome, Wyrome! I have been expecting you.

I want him to say Hello there Wyrome! I got some weapons for exchange.

Or something like that, so people understand that they should write weapons to know what weps
 
Use greetmessage in the xml of the npc, like this
Code:
<?xml version="1.0" encoding="UTF-8"?>
<npc name="Robbie the dealer" script="exhchange.lua" walkinterval="2000" floorchange="0">
     <health now="100" max="100"/>
     <look type="274" head="0" body="113" legs="78" feet="114" addons="3"/>
     <parameters>
         <parameter key="message_greet" value="Hello there |PLAYERNAME|! I'm trading my special {weapons} for your items!"/>
     </parameters>
</npc>
 
Back
Top