Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function isFocused(cid, t)
- for i, v in pairs(t) do
- if(v == cid) then
- return true
- end
- end
- return false
- end
- function addFocus(cid, t)
- if(not isFocused(cid, t)) then
- table.insert(t, cid)
- end
- end
- function removeFocus(cid, t)
- for i, v in pairs(t) do
- if(v == cid) then
- table.remove(t, i)
- break
- end
- end
- end
- function lookAtFocus(t)
- for i, v in pairs(t) do
- if(isPlayer(v)) then
- doNpcSetCreatureFocus(v)
- return
- end
- end
- doNpcSetCreatureFocus(0)
- end
- function msgcontains(msg, ...)
- local function checkstring(msg, key)
- return (" " .. msg .. " "):find("%s+" .. key .. "[%s%p]+") and true or false
- end
- for _, key in ipairs(arg) do
- if checkstring(tostring(msg):lower(), tostring(key):lower()) then
- return true
- end
- end
- return false
- end
- local focuses = {}
- function onCreatureDisappear(cid)
- if isFocused(cid, focuses) then
- removeFocus(cid, focuses)
- if isPlayer(cid) then
- closeShopWindow(cid)
- end
- end
- end
- local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpack,sellPrice,price,buyPrice)
- local it = items[item]
- for i,v in pairs(it) do
- print(i,v)
- end
- end
- local onSell = function(cid, item, subType, amount, ignoreCap, inBackpacks)
- return
- end
- function onCreatureSay(cid, type,msg)
- items = {}
- if msgcontains(msg, "hi", "hello") and not isFocused(cid, focuses) and getDistanceToCreature(cid) < 4 then
- selfSay("Hiho " .. getCreatureName(cid)..". Say {offers} to see my offers.", cid)
- addFocus(cid, focuses)
- selfFocus(cid)
- elseif msgcontains(msg, "offers") and isFocused(cid, focuses) then
- selfSay("Here are the places that I can take you.", cid)
- text = "--==## id | Price | name | ##==-- \n"
- for index, info in pairs(readyResellerItems()) do
- local itemname = getItemDescriptionsById(info.itemid).name
- text = ""..text.."\n".. info.item_uid.." | ".. info.price.." | ".. itemname .."."
- items[info.item_uid] = {id = info.itemid, price = info.price, info.playerid}
- end
- text = ""..text.."\n \n Para comprar diga (buy + id do o item)."
- doPlayerPopupFYI(cid, text)
- elseif msgcontains(msg, "buy") and isFocused(cid, focuses) then
- local item = tonumber(string.find (msg, "(.%d)"))
- print(item)
- item = items[item]
- print(item)
- elseif msgcontains(msg, "bye") and isFocused(cid, focuses) then
- selfSay("Goodbye!", cid)
- closeShopWindow(cid)
- removeFocus(cid, focuses)
- lookAtFocus(focuses)
- end
- end
- function onThink()
- for _, focus in pairs(focuses) do
- if not isCreature(focus) then
- removeFocus(focus, focuses)
- else
- local distance = getDistanceTo(focus) or 5
- if distance > 4 then
- selfSay("Hmpf!", focus)
- closeShopWindow(focus)
- removeFocus(focus, focuses)
- end
- end
- end
- lookAtFocus(focuses)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement