Welcome dear OTland users.
I have got 2 problems in scripts. I am begginer and .lua, but I do what I can do alone. This time I need some help. I was scripting the NPC and some quest until i spotted a problems.
The first is: The reward from the Quest must be packed in a bag I have no idea how to do it.
THE CODE:
It's the blue robe quest the problem is the script gives the items correct but not in bag( to backpack) how to fix it?(bag id:1987)
Second:
I would like to make a furniture shop. But I would like NPC to sell the furniture in packs. How to do it?
I was trying to change some script but its still not working like it should.
THE CODE:
I know it may be funny for you but belive me it is not so easy for begginers. Please help.
I have got 2 problems in scripts. I am begginer and .lua, but I do what I can do alone. This time I need some help. I was scripting the NPC and some quest until i spotted a problems.
The first is: The reward from the Quest must be packed in a bag I have no idea how to do it.
THE CODE:
Code:
function onUse(cid, item, frompos, item2, topos)
if item.uid == 10 then
queststatus = getPlayerStorageValue(cid,10)
if queststatus == -1 or queststatus == 0 then
doPlayerSendTextMessage(cid,22,"You have found a bag.")
item_uid = doPlayerAddItem(cid,2656,1)
item_uid = doPlayerAddItem(cid,2536,1)
item_uid = doPlayerAddItem(cid,2436,1)
setPlayerStorageValue(cid,10,1)
else
doPlayerSendTextMessage(cid,22,"It\'s empty.")
end
else
return 0
end
return 1
end
It's the blue robe quest the problem is the script gives the items correct but not in bag( to backpack) how to fix it?(bag id:1987)
Second:
I would like to make a furniture shop. But I would like NPC to sell the furniture in packs. How to do it?
I was trying to change some script but its still not working like it should.
THE CODE:
Code:
_delay = 1000
_topic = 0
_index = 0
_count = 0
_price = 0
_type = 0
_stack = false
_sub = -1
function getNext() nextPlayer = getQueuedPlayer() if (nextPlayer ~= nil) then if (getDistanceToCreature(nextPlayer) <= 3) then updateNpcIdle() setNpcFocus(nextPlayer) greet(nextPlayer) return else getNext() end end setNpcFocus(0) resetNpcIdle() end
function _selfSay(message) selfSay(message, _delay) updateNpcIdle() end
local function greet(cid)
_selfSay("Oh, please come in, " .. getCreatureName(cid) .. " What do you need?")
end
function onCreatureDisappear(cid)
if (getNpcFocus() == cid) then
_selfSay("Good bye.")
getNext()
else
unqueuePlayer(cid)
end
end
function onCreatureMove(cid, oldPos, newPos) if (getNpcFocus() == cid) then faceCreature(cid) end end
function onCreatureSay(cid, type, msg)
local messages =
{
{"job" , "I am selling furniture of all kinds. Do you need anything?"},
{"name" , "I am Meble. My goods are known all over Tibia."},
}
local shop =
{
}
if (getNpcFocus() == 0) then
if ((msgcontains("hi|hello", msg) and getDistanceToCreature(cid) <= 3)) then
updateNpcIdle()
setNpcFocus(cid)
greet(cid)
end
elseif (getNpcFocus() ~= cid) then
if ((msgcontains("hi|hello", msg) and getDistanceToCreature(cid) <= 3)) then
_selfSay("Sorry " .. getCreatureName(cid) .. " I am already talking to a customer. Wait a moment.")
queuePlayer(cid)
end
else
if (msgcontains("bye|farewell", msg)) then
_selfSay("Good bye.")
getNext()
return false
end
if not msgcontains(msg, "buy") and not msgcontains(msg, "sell") then
for i, a in ipairs(messages) do
if msgcontains(a[1], msg) then
_selfSay(a[2])
return true
end
end
end
if msgcontains(msg, "chair") then
if getCount(msg) == nil or getCount(msg) < 2 then
_count = 1
_price = 20
_selfSay("Do you want to buy a wooden chair for 20 gold?")
_topic = 3
return true
elseif getCount(msg) > 1 then
_count = getCount(msg)
_price = _count * 20
_selfSay("Do you want to buy " .. _count .. "chairs for " .. _price .. "?")
_topic = 3
return true
end
end
if msgcontains(msg, "yes") and _topic == 3 then
if doPlayerRemoveMoney(cid, _price) then
_selfSay("Here you are.")
for i = 1, _count do
doPlayerAddItem(cid, 1650, 1)
end
_topic = 0
return true
else
_selfSay("Come back, when you have enough money.")
_topic = 0
return true
end
elseif _topic == 3 then
_selfSay("Hmm, but next time.")
_topic = 0
return true
end
for i, a in ipairs(shop) do
if msgcontains(msg, a[1]) and not msgcontains(msg, "sell") and a[5] > 0 then
if getCount(msg) > 1 then
_count = getCount(msg)
_type = a[2]
_price = a[5] * _count
_stack = a[3]
_sub = a[6]
txt = "Do you want to buy " .. _count .. " " .. a[1] .. a[8] .. " for " .. _price .. " gold?"
elseif getCount(msg) == nil or getCount(msg) < 2 then
_count = 1
_type = a[2]
_price = a[5]
_stack = a[3]
_sub = a[6]
txt = "Do you want to buy " .. a[7] .. " " .. a[1] .. " for " .. a[5] .. " gold?"
end
_index = i
_topic = 1
_selfSay(txt)
return true
elseif msgcontains(msg, a[1]) and msgcontains(msg, "sell") and a[4] > 0 then
if getCount(msg) > 1 then
_count = getCount(msg)
_type = a[2]
_price = a[4] * _count
_stack = a[3]
_sub = a[6]
txt = "Do you want to sell " .. _count .. " " .. a[8] .." for " .. _count * a[4] .. " gold?"
elseif getCount(msg) == nil or getCount(msg) < 2 then
_count = 1
_type = a[2]
_price = a[4]
_stack = a[3]
_sub = a[6]
txt = "Do you want to sell " .. a[7] .. " " .. a[1] .. " for " .. a[4] .. " gold?"
end
_index = i
_topic = 2
_selfSay(txt)
return true
end
end--end loop
if _topic == 1 or _topic == 2 then
if _topic == 1 and msgcontains(msg, "yes") then
if doPlayerRemoveMoney(cid, _price) == 1 then
if _stack then
doPlayerAddItem(cid, _type, _count)
else
for i = 1, _count do
doPlayerAddItem(cid, _type)
end
end
_selfSay("Here you are.")
_topic = 0
return true
else
_selfSay("You have not enough money.")
_topic = 0
return false
end
elseif _topic == 2 and msgcontains(msg, "yes") then
if getPlayerItemCount(cid, _type) >= _count then
if doPlayerRemoveItem(cid, _type, _count) == 1 then
doPlayerAddMoney(cid, _price)
_selfSay("Thank you.")
_topic = 0
end
return false
elseif (_count == 1 and getPlayerItemCount(cid, _type) < 1) then
_selfSay("You don't have one.")
_topic = 0
return false
else
_selfSay("You do not have that many.")
_topic = 0
return false
end
else
_selfSay("Hmm, but next time.")
_topic = 0
end
end
end
end
function onThink()
if (getNpcFocus() ~= 0) then
if (isNpcIdle() or getDistanceToCreature(getNpcFocus()) > 3) then
_selfSay("Good bye.")
getNext()
end
end
end
I know it may be funny for you but belive me it is not so easy for begginers. Please help.