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

Buy items with demonic essences, with tables, NPC 0.3.7

  • Thread starter Thread starter Xikini
  • Start date Start date
X

Xikini

Guest
The Forgotten Server, version 0.3.7_SVN (Crying Damson)

I want an npc which will trade with demonic essence instead of gold coins.

Ideally the npc would have these functions.

trade -> which item would you like to trade? or would like to to know the items you can trade?
can trade -> loops and checks for all items in table, and sends "I trade demonic essences for thing1, thing2, and thing3.
thing1 -> check for item name in table
-> I can sell you that item for ..check item price in table.. . Would you like to do that?
yes ->check price from table -> check if player has enough essence -> give item from table.

The harder part..
If a person wants thing1, but thing1 comes in different colours, ask if want a specific one, or a random one for less price.

thing2 -> I can sell you thing2 for ..check price.. or I can give you a random thing2 for ..otherPrice.. . Would you like thing2 or random?
thing2 -> checkprice -> check player essence -> give item.
random -> checkprice -> check player essence -> give item+ add actionID from table.

Some id's to work with.
essence = 6500
brown backpack = 1988
dwarven ring = 2213
life ring = 2168
knife = 2403
present box = 1990 (random item box, I will script an action to give random item onUse.)

Guessing the table would need these in it..
Code:
[1] = {item = "knife",          type = weapon,   itemID = 2403, price = 100, randomPrice = 0, actionID = 0},
[2] = {item = "brown backpack", type = backpack, itemID = 1988, price = 100, randomPrice = 20, actionID = 45055},
[3] = {item = "dwarven ring",   type = ring,     itemID = 2213, price = 200, randomPrice = 40, actionID = 45056},
[4] = {item = "life ring",      type = ring,     itemID = 2168, price = 200, randomPrice = 40, actionID = 45056}

I'm not really looking for a script..
I'm more looking for how to access the table, and keep the position within the table saved while talking with the npc.
I'm just terrible with loops and tables. :P
 
You can add the name of the item like this ["knife"] and then check for msg.
Code:
local config = {
    ["knife"] = {itemID = 2403, price = 100, etc = etc}
}

local x = config[msg:lower()]
if x then -- if the player says knife then
    doBlabla(cid, x.itemID) -- this will get the itemid of the knife
end

Not sure what you mean with the rest. Can you give examples with itemids what to trade for what and what should be random?
 
You can add the name of the item like this ["knife"] and then check for msg.
Code:
local config = {
    ["knife"] = {itemID = 2403, price = 100, etc = etc}
}

local x = config[msg:lower()]
if x then -- if the player says knife then
    doBlabla(cid, x.itemID) -- this will get the itemid of the knife
end

Not sure what you mean with the rest. Can you give examples with itemids what to trade for what and what should be random?
If it were to be in an npc conversation..
Code:
Player:knife
Npc:knife for 200 essences?
Player:yes
Npc:here you are.

Player:life ring
Npc:life ring for 200 essences? or would you like a random ring for 40 essence?
if
Player:life ring
Npc:here you are.
if
Player:random
Npc:here you are. (gives a present box)
I put in what I thought I'd need to use within the table.
item = name of item
type = what type of item it is, so when npc asks if you want 'random' item, it will use the correct term
itemID = item id of the item
price = price of specific item
randomprice = price of present box (which when used will give a random ring)
actionID = actionid to be placed on the present box, for the action script. If actionID = zero, it doesn't ask if you want the random item.
(actionID is useless I suppose.. as it could just do math.random from another list labeled rings.. isnide the same npc :p)
 
like limos said

Code:
local config = {
    ["knife"] = {itemID = 2403, price = 100, count = 1, random= nil, actionID = nil},
    ["ring"] = {itemID = presentid, price = someprice, count = 1, random = true, actionID = 2000}
}
local x = config[msg:lower()]
if x then -- if the player says knife then
if x.random then doSomeShit
end
end

btw I created one dont know if works havent tested
Code:
-- Based on https://github.com/PrinterLUA/FORGOTTENSERVER-ORTS/blob/master/data/npc/scripts/Harog.lua
-- This script is working with demonic essences as gold coin, If you want to edit that just search for demonic essences id and change it.
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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 = {
    actionID = 1234,
    boxID = 1990,
    cost = math.random(20, 40)
}
local function getTable(player)
    local itemsList = {
        {name="knife", id=2403, buy=100},
        {name="dwarven ring", id=2213, buy=200},
        {name="life ring", id=2168, buy=200},
        {name="brown backpack", id=1988, buy=100},
        {name="ring of the sky", id=2123, sell=500}
    }
    return itemsList
end

local function setNewTradeTable(table)
    local items = {}
    for _, v in ipairs(table) do
        items[v.id] = {itemId = v.id, buyPrice = v.buy, sellPrice = v.sell, subType = 0, realName = v.name}
    end
    return items
end

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    local player = Player(cid)
    if msgcontains(msg, "trade") then
        local items = setNewTradeTable(getTable(player))
        local function onBuy(cid, item, subType, amount, ignoreCap, inBackpacks)
            if (ignoreCap == false and (player:getFreeCapacity() < ItemType(items[item].itemId):getWeight(amount) or inBackpacks and player:getFreeCapacity() < (ItemType(items[item].itemId):getWeight(amount) + ItemType(1988):getWeight()))) then
                return player:sendTextMessage(MESSAGE_STATUS_SMALL, 'You don\'t have enough cap.')
            end
            if player:getItemCount(6500) >= items[item].buyPrice then
                if inBackpacks then
                    local container = Game.createItem(1988, 1)
                    local bp = player:addItemEx(container)
                    if(bp ~= 1) then
                        return player:sendTextMessage(MESSAGE_STATUS_SMALL, 'You don\'t have enough container.')
                    end
                    for i = 1, amount do
                        container:addItem(items[item].itemId, items[item])
                    end
                else
                    return
                    player:addItem(items[item].itemId, amount, false, items[item]) and
                    player:removeItem(6500, amount * items[item].buyPrice) and
                    player:sendTextMessage(MESSAGE_INFO_DESCR, 'You bought '..amount..'x '..items[item].realName..' for '..items[item].buyPrice * amount..' demonic essences.')
                end
                player:sendTextMessage(MESSAGE_INFO_DESCR, 'You bought '..amount..'x '..items[item].realName..' for '..items[item].buyPrice * amount..' demonic essences.')
                player:removeItem(6500, amount * items[item].buyPrice)
            else
                player:sendTextMessage(MESSAGE_STATUS_SMALL, 'You do not have enough demonic essences.')
            end
            return true
        end

        local function onSell(cid, item, subType, amount, ignoreEquipped)
            if items[item].sellPrice then
                return
                player:removeItem(items[item].itemId, amount, -1, ignoreEquipped) and
                player:addItem(6500, items[item].sellPrice * amount) and
                player:sendTextMessage(MESSAGE_INFO_DESCR, 'You sold '..amount..'x '..items[item].realName..' for '..items[item].sellPrice * amount..' demonic essences.')
            end
            return true
        end

        openShopWindow(cid, getTable(player), onBuy, onSell)
        npcHandler:say("Keep in mind you won't find better offers here. Just browse through my wares.", cid)

    elseif msgcontains(msg, "random") then
        npcHandler.topic[cid] = 0
        if player:getItemCount(6500) >= c.cost then
            local box = player:addItem(c.boxID, 1)
            box:setActionId(c.actionID)
            player:removeItem(6500, c.cost)
            npcHandler:say("Good luck", cid)
        else
            player:sendTextMessage(MESSAGE_STATUS_SMALL, 'You do not have enough demonic essences.')
        end
    end
    return true
end

npcHandler:setMessage(MESSAGE_GREET, 'Hello.')
npcHandler:setMessage(MESSAGE_FAREWELL, 'It was a pleasure to help you, |PLAYERNAME|.')
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

npcHandler:addModule(FocusModule:new())

When you say random it will check ur demonic essences and then give you a present box (can be edited) with an action id (can be edited too), was thinking in something like a piggy bank (easier way) thats not hard to do so thats ur job. If you say trade, trade npc box will appear and you can only pay with demonic essences, also you can sell some rings thats optional.
Should work as I say havent tested cus I cant.
 
Last edited:
like limos said

Code:
local config = {
    ["knife"] = {itemID = 2403, price = 100, count = 1, random= nil, actionID = nil},
    ["ring"] = {itemID = presentid, price = someprice, count = 1, random = true, actionID = 2000}
}
local x = config[msg:lower()]
if x then -- if the player says knife then
if x.random then doSomeShit
end
end

btw I created one dont know if works havent tested
Code:
-- Based on https://github.com/PrinterLUA/FORGOTTENSERVER-ORTS/blob/master/data/npc/scripts/Harog.lua
-- This script is working with demonic essences as gold coin, If you want to edit that just search for demonic essences id and change it.
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)

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 = {
    actionID = 1234,
    boxID = 1990,
    cost = math.random(20, 40)
}
local function getTable(player)
    local itemsList = {
        {name="knife", id=2403, buy=100},
        {name="dwarven ring", id=2213, buy=200},
        {name="life ring", id=2168, buy=200},
        {name="brown backpack", id=1988, buy=100},
        {name="ring of the sky", id=2123, sell=500}
    }
    return itemsList
end

local function setNewTradeTable(table)
    local items = {}
    for _, v in ipairs(table) do
        items[v.id] = {itemId = v.id, buyPrice = v.buy, sellPrice = v.sell, subType = 0, realName = v.name}
    end
    return items
end

local function creatureSayCallback(cid, type, msg)
    if not npcHandler:isFocused(cid) then
        return false
    end
    local player = Player(cid)
    if msgcontains(msg, "trade") then
        local items = setNewTradeTable(getTable(player))
        local function onBuy(cid, item, subType, amount, ignoreCap, inBackpacks)
            if (ignoreCap == false and (player:getFreeCapacity() < ItemType(items[item].itemId):getWeight(amount) or inBackpacks and player:getFreeCapacity() < (ItemType(items[item].itemId):getWeight(amount) + ItemType(1988):getWeight()))) then
                return player:sendTextMessage(MESSAGE_STATUS_SMALL, 'You don\'t have enough cap.')
            end
            if player:getItemCount(6500) >= items[item].buyPrice then
                if inBackpacks then
                    local container = Game.createItem(1988, 1)
                    local bp = player:addItemEx(container)
                    if(bp ~= 1) then
                        return player:sendTextMessage(MESSAGE_STATUS_SMALL, 'You don\'t have enough container.')
                    end
                    for i = 1, amount do
                        container:addItem(items[item].itemId, items[item])
                    end
                else
                    return
                    player:addItem(items[item].itemId, amount, false, items[item]) and
                    player:removeItem(6500, amount * items[item].buyPrice) and
                    player:sendTextMessage(MESSAGE_INFO_DESCR, 'You bought '..amount..'x '..items[item].realName..' for '..items[item].buyPrice * amount..' demonic essences.')
                end
                player:sendTextMessage(MESSAGE_INFO_DESCR, 'You bought '..amount..'x '..items[item].realName..' for '..items[item].buyPrice * amount..' demonic essences.')
                player:removeItem(6500, amount * items[item].buyPrice)
            else
                player:sendTextMessage(MESSAGE_STATUS_SMALL, 'You do not have enough demonic essences.')
            end
            return true
        end

        local function onSell(cid, item, subType, amount, ignoreEquipped)
            if items[item].sellPrice then
                return
                player:removeItem(items[item].itemId, amount, -1, ignoreEquipped) and
                player:addItem(6500, items[item].sellPrice * amount) and
                player:sendTextMessage(MESSAGE_INFO_DESCR, 'You sold '..amount..'x '..items[item].realName..' for '..items[item].sellPrice * amount..' demonic essences.')
            end
            return true
        end

        openShopWindow(cid, getTable(player), onBuy, onSell)
        npcHandler:say("Keep in mind you won't find better offers here. Just browse through my wares.", cid)

    elseif msgcontains(msg, "random") then
        npcHandler.topic[cid] = 0
        if player:getItemCount(6500) >= c.cost then
            local box = player:addItem(c.boxID, 1)
            box:setActionId(c.actionID)
            player:removeItem(6500, c.cost)
            npcHandler:say("Good luck", cid)
        else
            player:sendTextMessage(MESSAGE_STATUS_SMALL, 'You do not have enough demonic essences.')
        end
    end
    return true
end

npcHandler:setMessage(MESSAGE_GREET, 'Hello.')
npcHandler:setMessage(MESSAGE_FAREWELL, 'It was a pleasure to help you, |PLAYERNAME|.')
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)

npcHandler:addModule(FocusModule:new())

When you say random it will check ur demonic essences and then give you a present box (can be edited) with an action id (can be edited too), was thinking in something like a piggy bank (easier way) thats not hard to do so thats ur job. If you say trade, trade npc box will appear and you can only pay with demonic essences, also you can sell some rings thats optional.
Should work as I say havent tested cus I cant.
Code:
[8:15:44.514] [Error - NpcScript Interface]
[8:15:44.515] data/npc/scripts/CarlsQuests/essencedude.lua:onCreatureSay
[8:15:44.516] Description:
[8:15:44.516] data/npc/scripts/CarlsQuests/essencedude.lua:41: attempt to call g -- when I say trade
lobal 'Player' (a nil value)
[8:15:44.517] stack traceback:
[8:15:44.517]  data/npc/scripts/CarlsQuests/essencedude.lua:41: in function 'ca
llback'
[8:15:44.518]  data/npc/lib/npcsystem/npchandler.lua:455: in function 'onCreatu
reSay'
[8:15:44.518]  data/npc/scripts/CarlsQuests/essencedude.lua:9: in function <dat
a/npc/scripts/CarlsQuests/essencedude.lua:9>

[8:15:53.106] [Error - NpcScript Interface]
[8:15:53.107] data/npc/scripts/CarlsQuests/essencedude.lua:onCreatureSay
[8:15:53.107] Description:
[8:15:53.108] data/npc/scripts/CarlsQuests/essencedude.lua:41: attempt to call g -- when I say random
lobal 'Player' (a nil value)
[8:15:53.109] stack traceback:
[8:15:53.109]  data/npc/scripts/CarlsQuests/essencedude.lua:41: in function 'ca
llback'
[8:15:53.110]  data/npc/lib/npcsystem/npchandler.lua:455: in function 'onCreatu
reSay'
[8:15:53.110]  data/npc/scripts/CarlsQuests/essencedude.lua:9: in function <dat
a/npc/scripts/CarlsQuests/essencedude.lua:9>
It's not quite as I intended, however I'm pretty sure I'd need to convert it to 0.3.7, as it's written like a 1.0 script.
I don't mind creating the npc myself.
I just need to understand how to hold onto the string that the player said, so that I can access the same part of the table again.
I understand how to create the table, I just don't understand how to properly access it.
----
What I'm requesting I guess, is.. I want a short example script mostly to access the table.
Code:
["life ring"] = {category = ring, itemID = 2168, price = 200, randomPrice = 40, actionID = 0},

To make it easier, here's the things I need.

If player says list, list all items from the table. life ring, dwarven ring, brown backpack, knife (note: It needs to pull from the table, so I don't need to edit it.. check string + loop until bottom)

If player says life ring, it will check if actionID is above zero.
if actionID == 0 then
say this ("Do you want to trade "..string.itemname.." for "..value.price.."?", cid)
check for yes/no
if yes, check for essence, give item, say here you go
if no, say no then

else
say this ("Do you want to trade {"..string.itemname.."} for "..value.price.." or do you want buy a random {"..category.."} for "..value.randomprice.."?", cid)
check for string/category
if string, ask yes/no, check for essence, give item, say here you go
if category, ask yes/no, check for essence, give present+actionID, say here you go

----
I really do appreciate the time you took in making that script, however it's just not what I'm looking for.

--edit changed colour, Also want to stress I don't want a trade window to appear.
 
Last edited by a moderator:
Indeed more easy :D
7tk4Ul5Rr.png


But from what I posted, what else do you need to know to make the script?
 
Indeed more easy :D
7tk4Ul5Rr.png


But from what I posted, what else do you need to know to make the script?
Code:
local x = config[msg:lower()]
if x then -- if the player says knife then
doBlabla(cid, x.itemID) -- this will get the itemid of the knife
end

I don't understand it! :P
How would I loop through the items, to list them all?
Player: List
Npc: (checks table) Says: "thing1, thing 2, thing3...thing56."

As for the 'x', how does the npc know to hold onto that string, to use it again?
Player: life ring
NPC: would you like to buy life ring or random ring?
Player: life ring
NPC: you want to buy life ring for 400 essence?
Player: yes
NPC:here you go!
 
You don't need to use a loop like this.
Just add the keywords to the table and the values for that keyword.
By using x. you can get the values for that keyword.
Code:
local config = {
     ["knife"] = {itemID = 2403, price = 100, a = 10},
     ["spoon"] = {itemID = 2565, price = 50, a = 15}
}

local x = config[msg:lower()]
if x then -- if the player says knife or spoon then
     -- if a player says knife:
     -- x.itemID = 2403
     -- x.price = 100
     -- x.a = 10
    
     -- if a player says spoon:
     -- x.itemID = 2565
     -- x.price = 50
     -- x.a = 15
 
You don't need to use a loop like this.
Just add the keywords to the table and the values for that keyword.
By using x. you can get the values for that keyword.
Code:
local config = {
     ["knife"] = {itemID = 2403, price = 100, a = 10},
     ["spoon"] = {itemID = 2565, price = 50, a = 15}
}

local x = config[msg:lower()]
if x then -- if the player says knife or spoon then
     -- if a player says knife:
     -- x.itemID = 2403
     -- x.price = 100
     -- x.a = 10
   
     -- if a player says spoon:
     -- x.itemID = 2565
     -- x.price = 50
     -- x.a = 15
I think I suck at explaining :P
--------------------------
The loop is for only 1 keyword.
-- if player says list
-- tell every item in list.
--------------------------
How do I keep the npc focused on the last string that was accessed within the table? (or rather how does the NPC remember the last keyword used? Do I need to store the last string in some sort of floating memory? or is this done automatically?)
-- if player says knife
-- ask if player wants knife or random weapon
-- wait for reply (how does the npc know what we were talking about previously?)
-------------------------

I'm trying to use a table instead of making a 1000 line script for a trade npc. :P
there is going to be at least 200 items in this npc. :D
 
This is maybe useful as example.
http://otland.net/threads/city-guide-adding-mapmarks-to-locations.166422/

To let the npc remember keywords you can also add them in a table instead of just one value, which is better actually when more people are talking with the npc at the same time.
Code:
local xmsg = {} -- above the function


xmsg[cid] = msg -- to save msg
-- blabla
local x = config[xmsg[cid]:lower()] -- to get values from the saved msg
 
There should be a new forum section created.
"I am dense as shit, please bear with me as I ask 14 questions trying to find one answer, but I have no idea what I'm looking for." :D

Btw, how would I do the loop? :P
 
well, hope u understand
Code:
local loop = {
    ["tiger"] = {family="felidae", bioname="panthera tigris", kingdom="animalia", domestic=false},
    ["lion"] = {family="felidae", bioname="panthera leo", kingdom="animalia", domestic=false},
    ["dog"] = {family="canidae", bioname="canis lupus familiaris", kingdom="animalia", domestic=true}
}

local info = loop[msg:lower()]
if info then
    if info.family == "felidae" then
        print("You have selected ".. info .." from the ".. info.family .." family and ".. info.domestic and "is" or "is not".. "domestic.")
        print("Kingdom: "..info.kingdom)
    else
        print("Everybody loves dogs")
    end
end
 
From the link I posted
Code:
local text = 'Locations\n'
for i, x in pairs(config) do
    text = text .. '\n' .. i .. ''
end
doShowTextDialog(cid, 1949, '' .. text)
This will look like this
O-NgEdC.png

But you can change locations ofc and the names wil be like in your script.
i will be the keywords, x the value, so you can do x.itemID for example to get the itemid incase you want to add it to the list.
\n is an enter btw.
 
Alrighty, so after much struggle.. :p
I have come up with this.
Weirdly, it puts the items in order with the itemID.. when I say help. Is it possible make it say them in the order it appears inside the script?
BQtY2To.png

As for when I say knife, I get an error.

Error.
Code:
[12:37:29.908] [Error - NpcScript Interface]
[12:37:29.909] data/npc/scripts/CarlsQuests/essencedude.lua:onCreatureSay
[12:37:29.909] Description:
[12:37:29.909] data/npc/scripts/CarlsQuests/essencedude.lua:49: attempt to index
global 'x' (a nil value)
[12:37:29.910] stack traceback:
[12:37:29.910]  data/npc/scripts/CarlsQuests/essencedude.lua:49: in function 'ca
llback'
[12:37:29.910]  data/npc/lib/npcsystem/npchandler.lua:455: in function 'onCreatu
reSay'
[12:37:29.910]  data/npc/scripts/CarlsQuests/essencedude.lua:8: in function <dat
a/npc/scripts/CarlsQuests/essencedude.lua:8>
NPC.
Code:
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 greet(cid)
     talkState[cid] = 0
     return true
   end

   function getNpcName()
     return getCreatureName(getNpcId())
   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

   local player_money  = getPlayerItemCount(cid,6500)

   local config = {
     ["brown backpack"] =  {itemID = "1988", price = 999, name = "brown backpack"},
     ["knife"] =           {itemID = "2403", price = 100, name = "knife"},
     ["dwarven ring"] =    {itemID = "2213", price = 200, name = "dwarven ring"},
     ["life ring"] =       {itemID = "2168", price = 200, name = "life ring"}
   }


   if msgcontains(msg, "help") then -- HELP START (NEVER EDIT)
  local text = ""
  for i, x in pairs(config) do
  if text ~= "" then
  text = text.. ", "
  end
  text = text..config[i].name
  end
  selfSay("I sell items for demonic essence. The items I have for sale are.. " ..text.. "", cid)

   local x = config[msg:lower()]
   elseif msgcontains(msg, "knife") then
     selfSay("Would you like to buy "..x.name.." for "..x.price.." demonic essences?", cid)
     talkState[talkUser] = 1
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
     if player_money >= x.price then
     doPlayerRemoveMoney(cid,x.price)
     doPlayerAddItem(cid,x.itemdID,1)
     selfSay("Thank you kind sir. Here is your "..x.name..".", cid)
     talkState[talkUser] = 0
     end



   elseif msgcontains(msg, "no") then
     selfSay("No then.", cid)
     talkState[talkUser] = 0

   end

   return true
end

npcHandler:setCallback(CALLBACK_GREET, greet)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
--Edit
I dunno if that's even what you meant when using the table. lmao
It seems like there would be a simpler way to have the npc always respond the same way. :rolleyes:
(and after like 3 days the person I'm helping decided he doesn't even want the random item box for lower price :mad:)
 
Last edited by a moderator:
Code:
local x = config[msg:lower()]
Is local inside the if statement for help, so add it above it, else it will only work in that part.
You can also remove local but then people still need to say help first.
 
Code:
local x = config[msg:lower()]
Is local inside the if statement for help, so add it above it, else it will only work in that part.
You can also remove local but then people still need to say help first.
Moved it above help, added some extra to keyword 'no'.

MFpBVjz.png

error
Code:
[13:15:07.352] [Error - NpcScript Interface]
[13:15:07.353] data/npc/scripts/CarlsQuests/essencedude.lua:onCreatureSay
[13:15:07.353] Description:
[13:15:07.353] data/npc/scripts/CarlsQuests/essencedude.lua:52: attempt to index
 local 'x' (a nil value)
[13:15:07.353] stack traceback:
[13:15:07.354]  data/npc/scripts/CarlsQuests/essencedude.lua:52: in function 'ca
llback'
[13:15:07.354]  data/npc/lib/npcsystem/npchandler.lua:455: in function 'onCreatu
reSay'
[13:15:07.354]  data/npc/scripts/CarlsQuests/essencedude.lua:9: in function <dat
a/npc/scripts/CarlsQuests/essencedude.lua:9>
NPC
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
local 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

   function greet(cid)
     talkState[cid] = 0
     return true
   end
   
   function getNpcName()
     return getCreatureName(getNpcId())
   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

   local player_money  = getPlayerItemCount(cid,6500)
   
   local config = {
     ["brown backpack"] =    {itemID = "1988", price = 999, name = "brown backpack"},
     ["knife"] =        {itemID = "2403", price = 100, name = "knife"},
     ["dwarven ring"] =      {itemID = "2213", price = 200, name = "dwarven ring"},
     ["life ring"] =      {itemID = "2168", price = 200, name = "life ring"}
   }
   
   local x = config[msg:lower()]
   if msgcontains(msg, "help") then -- HELP START (NEVER EDIT)
  local text = ""
  for i, x in pairs(config) do
  if text ~= "" then
  text = text.. ", "
  end
  text = text..config[i].name
  end
  selfSay("I sell items for demonic essence. The items I have for sale are.. " ..text.. "", cid)
   
   elseif msgcontains(msg, "knife") then
     selfSay("Would you like to buy "..x.name.." for "..x.price.." demonic essences?", cid)
     talkState[talkUser] = 1
   elseif msgcontains(msg, "yes") and talkState[talkUser] == 1 then
     if player_money >= x.price then
     doPlayerRemoveMoney(cid,x.price)
     doPlayerAddItem(cid,x.itemdID,1)
     selfSay("Thank you kind sir. Here is your "..x.name..".", cid)
     talkState[talkUser] = 0
     end
   
   
   
   elseif msgcontains(msg, "no") and talkState[talkUser] >= 1 then
     selfSay("No then.", cid)
     talkState[talkUser] = 0

   end

   return true   
end

npcHandler:setCallback(CALLBACK_GREET, greet)
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Above the function add
Code:
local xmsg = {}
Under talkState[talkUser] = 1 add
Code:
xmsg[cid] = msg
Then under the msgcontains yes line
Code:
local x = config[xmsg[cid]:lower()]
 
Back
Top