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

Solved NPC sells keys issue

Mera Mero

Guess Who?
Joined
Dec 27, 2014
Messages
417
Reaction score
86
Greeting otlanders ,i've got problem with npc that sell keys with actionid i need this npc to sell more than 1 key and what can i add to make it sell items by trade window? if someone can help me to make it easy config would be nice this is script of npc
Code:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
local talkState = {}
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

function creatureSayCallback(cid, type, msg)
   if(not npcHandler:isFocused(cid)) then
return false
end

npcHandler:addModule(FocusModule:new())
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

local first = {
useExpReward = false,
}

local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

if(msgcontains(msg, 'key')) then
   if getPlayerStorageValue(cid,55002) <= 0 then
     selfSay("I can sell you key to arena under our city. Can you pay me 5 gp for it?", cid)
     talkState[talkUser] = 2
   else
     setPlayerStorageValue(cid,55002,1)
     selfSay("I sold you my key, I don't have more.", cid)
     talkState[talkUser] = 0
   end
   
elseif(msgcontains(msg, 'yes') and talkState[talkUser] == 2) then
  if getPlayerStorageValue(cid,55002) <= 0 then
     if getPlayerItemCount(cid,2148) >= 5 then
       if(doPlayerRemoveItem(cid,2148,5)) then
         selfSay("Here you are.", cid)
         doItemSetAttribute(doPlayerAddItem(cid, 2088, 1), 'aid', 3142)
         setPlayerStorageValue(cid,55002,-1)
         talkState[talkUser] = 0
  elseif(useExpReward) then
  doPlayerAddExperience(cid,0)
  end
     else
       getPlayerItemCount(cid,2148,0-4)
       selfSay("You need more money.", cid)
       talkState[talkUser] = 0
     end
  end
elseif(msgcontains(msg, 'no') and talkState[talkUser] == 2) then
   selfSay("Okey.", cid)
   talkState[talkUser] = 0
end
return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
and i've got another issue i need to make duration for that key to disappear after X time ,do you know how? TFS 0.3.6
Thanks otlanders :)
 
Last edited:
You can let the item decay in items.xml and add doDecayItem(uid).
For the keys, should there be different names for the keys or how should the player choose which key he wants?
 
You can let the item decay in items.xml and add doDecayItem(uid).
For the keys, should there be different names for the keys or how should the player choose which key he wants?
i need npc to sell keys with trade for example
player :hi
npc :hi player name i'm selling keys for X price
player :trade
player : choose an item after then click ok and he will buy it like runes seller
where can i add dodecayitem(UID)?
EDITED but this keys must be with action ids

yo?
 
Last edited by a moderator:
Code:
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


function creatureSayCallback(cid, type, msg)
     if not npcHandler:isFocused(cid) then
       return false
     end

     local shopWindow = {}
     local keys = {
         {id = 2088, buy = 5, name = "silver key", actionid = 3142},
         {id = 2089, buy = 20, name = "copper key", actionid = 3143},
         {id = 2091, buy = 50, name = "golden key", actionid = 3144}
     }

     local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
         if doPlayerRemoveMoney(cid, shopWindow[item].Price) then
             local thing = doPlayerAddItem(cid, shopWindow[item].ID, 1)
             doItemSetAttribute(thing, 'aid', shopWindow[item].Actionid)
             doDecayItem(thing)
             doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have bought a "..shopWindow[item].KeyName.." for "..shopWindow[item].Price.." gold.")
         else
             selfSay("You don't have enough money.", cid)
         end
         return true
     end

     if msgcontains(msg, 'trade') then
         for var, item in pairs(keys) do
             shopWindow[item.id] = {ID = item.id, Price = item.buy, KeyName = item.name, Actionid = item.actionid}
         end
         openShopWindow(cid, keys, onBuy, onSell)
     end
     return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
Last edited:
Code:
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 shopWindow = {}
local keys = {
     {id = 2088, buy = 5, name = "silver key", actionid = 3142},
     {id = 2089, buy = 20, name = "copper key", actionid = 3143},
     {id = 2091, buy = 50, name = "golden key", actionid = 3144}
}

local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
     if doPlayerRemoveMoney(cid, shopWindow[item].Price) then
         local thing = doPlayerAddItem(cid, shopWindow[item].ID, 1)
         doItemSetAttribute(thing, 'aid', shopWindow[item].Actionid)
         doDecayItem(thing)
         doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have bought a "..shopWindow[item].KeyName.." for "..shopWindow[item].Price.." gold.")
     else
         selfSay("You don't have enough money.", cid)
     end
     return true
end


function creatureSayCallback(cid, type, msg)
     if not npcHandler:isFocused(cid) then
         return false
     end

     if msgcontains(msg, 'trade') then
         for var, item in pairs(keys) do
             shopWindow[item.id] = {ID = item.id, Price = item.buy, KeyName = item.name, Actionid = item.actionid}
         end
         openShopWindow(cid, keys, onBuy, onSell)
     end
     return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
thx!!!:oops: may you have a look on this thread more please?
http://otland.net/threads/puzzling-thing.227890/page-2
 
sorry for double post but i wanted to add this npc to sell these keys with item id but doesn't work ,where is the mistake?
Code:
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 shopWindow = {}
local keys = {
     {id = 2088, buy = 5, name = "silver key", actionid = 3142, amount = 5, itemid = 2157},
     {id = 2089, buy = 20, name = "copper key", actionid = 3143 ,amount = 5, itemid = 2157},
     {id = 2091, buy = 50, name = "golden key", actionid = 3144 ,amount = 5, itemid = 9971}
}

local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
     if doPlayerRemoveItem(cid, amount, itemid , shopWindow[item].Price) then
         local thing = doPlayerAddItem(cid, shopWindow[item].ID, 1)
         doItemSetAttribute(thing, 'aid', shopWindow[item].Actionid)
         doDecayItem(thing)
         doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have bought a "..shopWindow[item].KeyName.." for "..shopWindow[item].Price.." gold.")
     else
         selfSay("You don't have enough money.", cid)
     end
     return true
end


function creatureSayCallback(cid, type, msg)
     if not npcHandler:isFocused(cid) then
         return false
     end

     if msgcontains(msg, 'trade') then
         for var, item in pairs(keys) do
             shopWindow[item.id] = {ID = item.id, Price = item.buy, KeyName = item.name, Actionid = item.actionid}
         end
         openShopWindow(cid, keys, onBuy, onSell)
     end
     return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
 
sorry for double post but i wanted to add this npc to sell these keys with item id but doesn't work ,where is the mistake?
Code:
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 shopWindow = {}
local keys = {
     {id = 2088, buy = 5, name = "silver key", actionid = 3142, amount = 5, itemid = 2157},
     {id = 2089, buy = 20, name = "copper key", actionid = 3143 ,amount = 5, itemid = 2157},
     {id = 2091, buy = 50, name = "golden key", actionid = 3144 ,amount = 5, itemid = 9971}
}

local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
     if doPlayerRemoveItem(cid, amount, itemid , shopWindow[item].Price) then
         local thing = doPlayerAddItem(cid, shopWindow[item].ID, 1)
         doItemSetAttribute(thing, 'aid', shopWindow[item].Actionid)
         doDecayItem(thing)
         doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have bought a "..shopWindow[item].KeyName.." for "..shopWindow[item].Price.." gold.")
     else
         selfSay("You don't have enough money.", cid)
     end
     return true
end


function creatureSayCallback(cid, type, msg)
     if not npcHandler:isFocused(cid) then
         return false
     end

     if msgcontains(msg, 'trade') then
         for var, item in pairs(keys) do
             shopWindow[item.id] = {ID = item.id, Price = item.buy, KeyName = item.name, Actionid = item.actionid}
         end
         openShopWindow(cid, keys, onBuy, onSell)
     end
     return true
end

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


You using tfs 1.0?
 
Change the price at "buy = 5"
If you want it to trade it for items that don't have a money value, you can add it to this list.
Code:
shopWindow[item.id] = {ID = item.id, Price = item.buy, KeyName = item.name, Actionid = item.actionid}
Then indeed use doPlayerRemoveItem, although the parameters are: cid, itemid, count.. so without amount.
It will still show gold in the trade window though.
 
@Limos Pretty sure that function isnt supported in tfs 1.0?

Code:
doItemSetAttribute(thing, 'aid', shopWindow[item].Actionid)
 
https://github.com/otland/forgottenserver/blob/1.0/data/compat.lua#L459
To find TFS 1.0 functions, you can look in the compat.lua for the 0.2 function.
This way you can see how to do it as TFS 1.0 metatable function.

I know i'm having a look at it now ;) its this

Code:
function doSetItemText(uid, text)
   local item = Item(uid)
   if item == nil then
     return false
   end

   if text ~= "" then
     item:setAttribute(ITEM_ATTRIBUTE_TEXT, text)
   else
     item:removeAttribute(ITEM_ATTRIBUTE_TEXT)
   end
   return true
end

But i think she is saying you wants the items that the NPC sells to have those action ids and it wont do it if she is using tfs 1,0.
 
Change the price at "buy = 5"
If you want it to trade it for items that don't have a money value, you can add it to this list.
Code:
shopWindow[item.id] = {ID = item.id, Price = item.buy, KeyName = item.name, Actionid = item.actionid}
Then indeed use doPlayerRemoveItem, although the parameters are: cid, itemid, count.. so without amount.
It will still show gold in the trade window though.
aff this is last part and didn't work :S may you fix it to me please?
Code:
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 shopWindow = {}
local keys = {
     {id = 2088, buy = 20, name = "silver key", actionid = 3142, itemid =2157},
     {id = 2089, buy = 20, name = "copper key", actionid = 3143},
     {id = 2091, buy = 50, name = "golden key", actionid = 3144}
}

local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
     if doPlayerRemoveItem(cid, ID, shopWindow[item].Price) then
         local thing = doPlayerAddItem(cid, shopWindow[item].ID, 1)
         doItemSetAttribute(thing, 'aid', shopWindow[item].Actionid)
         doDecayItem(thing)
         doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You have bought a "..shopWindow[item].KeyName.." for "..shopWindow[item].Price.." gold.")
     else
         selfSay("You don't have enough money.", cid)
     end
     return true
end


function creatureSayCallback(cid, type, msg)
     if not npcHandler:isFocused(cid) then
         return false
     end

     if msgcontains(msg, 'trade') then
         for var, item in pairs(keys) do
        shopWindow[item.id] = {ID = item.id, Price = item.buy, KeyName = item.name, Actionid = item.actionid, ItemID = item.itemid}
         end
         openShopWindow(cid, keys, onBuy, onSell)
     end
     return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
EDITED i need this npc to sell items with action id and with item id like 2157 for like 10 etc
 
Code:
if doPlayerRemoveItem(cid, shopWindow[item].ItemID, shopWindow[item].Price) then
These items don't have a money value? You can do it like this but then you still see gold in the trade window.
I know i'm having a look at it now ;) its this

Code:
function doSetItemText(uid, text)
   local item = Item(uid)
   if item == nil then
     return false
   end

   if text ~= "" then
     item:setAttribute(ITEM_ATTRIBUTE_TEXT, text)
   else
     item:removeAttribute(ITEM_ATTRIBUTE_TEXT)
   end
   return true
end

But i think she is saying you wants the items that the NPC sells to have those action ids and it wont do it if she is using tfs 1,0.
Mera Mero is using TFS 0.3.6.
 
Code:
if doPlayerRemoveItem(cid, shopWindow[item].ItemID, shopWindow[item].Price) then
These items don't have a money value? You can do it like this but then you still see gold in the trade window.

Mera Mero is using TFS 0.3.6.

[QUOTE="and i've got another issue i need to make duration for that key to disappear after X time ,do you know how? TFS 0.3.6
Thanks otlanders :)[/QUOTE]

oh so awkward... i'm going to waddle away now.
 
Just a FYI incase someone does a search and looks for this thread... to make this script work with tfs 1.0 change

Code:
doItemSetAttribute(thing, 'aid', shopWindow[item].Actionid)
to
Code:
doSetItemActionId(thing, 'aid', shopWindow[item].Actionid)

=)
 
Code:
if doPlayerRemoveItem(cid, shopWindow[item].ItemID, shopWindow[item].Price) then
These items don't have a money value? You can do it like this but then you still see gold in the trade window.

Mera Mero is using TFS 0.3.6.
but the problem is where can i put id of these items which i will buy keys with it? lol
Just a FYI incase someone does a search and looks for this thread... to make this script work with tfs 1.0 change

Code:
doItemSetAttribute(thing, 'aid', shopWindow[item].Actionid)
to
Code:
doSetItemActionId(thing, 'aid', shopWindow[item].Actionid)

=)
mmm thx limos already solved it :p
 
i took this script and edited the money id to platinum coins for another npc
to make it sell a key for 1k and it all worked

but how do i add crystal coins in there so it does also accept 1cc
with crystal coins it says not enough money now
 

Similar threads

Back
Top