-- Include the Advanced NPC System dofile(getDataDir() .. 'npc/lib/npcsystem/npcsystem.lua') function selfIdle() following = false attacking = false selfAttackCreature(0) target = 0 end function selfSayChannel(cid, message) return selfSay(message, cid, false) end function selfMoveToCreature(id) if(not id or id == 0) then return end local t = getCreaturePosition(id) if(not t.x or t.x == nil) then return end selfMoveTo(t.x, t.y, t.z) return end function getNpcDistanceToCreature(id) if(not id or id == 0) then selfIdle() return nil end local c = getCreaturePosition(id) if(not c.x or c.x == 0) then return nil end local s = getCreaturePosition(getNpcId()) if(not s.x or s.x == 0 or s.z ~= c.z) then return nil end return math.max(math.abs(s.x - c.x), math.abs(s.y - c.y)) end function doMessageCheck(message, keyword, dollar) local message, keyword = message:lower(), keyword:lower() if(type(keyword) == "table") then return table.isStrIn(keyword, message) end return message:find(keyword) and not message:find('(%w+)' .. keyword) and (not dollar or not message:find(keyword .. '(%w+)')) end function doNpcSellItem(cid, itemid, amount, subType, ignoreCap, inBackpacks, backpack) if exhaustion.get(cid, 9876) then doPlayerSendCancel(cid, 'You can purchase items only once per second.') return -1, 0 end local amount, subType, ignoreCap, inBackpacks, item = amount or 1, subType or 0, false, false, 0 if isItemStackable(itemid) then local stuff if(inBackpacks) then stuff = doCreateItemEx(backpack, 1) doAddContainerItem(stuff, itemid, amount) else stuff = doCreateItemEx(itemid, amount) end exhaustion.set(cid, 9876, 1) return doPlayerAddItemEx(cid, stuff, ignoreCap) ~= RETURNVALUE_NOERROR and 0 or amount, 0 end local a = 0 if(inBackpacks) then local container, b = doCreateItemEx(backpack, 1), 1 for i = 1, amount do local item = doAddContainerItem(container, itemid, subType) if(itemid == ITEM_PARCEL) then doAddContainerItem(item, ITEM_LABEL) end if(isInArray({(getContainerCapById(backpack) * b), amount}, i) == TRUE) then if(doPlayerAddItemEx(cid, container, ignoreCap) ~= RETURNVALUE_NOERROR) then b = b - 1 -- break end a = i -- a = a + i if(amount > i) then container = doCreateItemEx(backpack, 1) b = b + 1 end end end exhaustion.set(cid, 9876, 1) return a, b end for i = 1, amount do -- normal method for non-stackable items local item = doCreateItemEx(itemid, subType) if(itemid == ITEM_PARCEL) then doAddContainerItem(item, ITEM_LABEL) end if(doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR) then break end a = i end exhaustion.set(cid, 9876, 1) return a, 0 end function doRemoveItemIdFromPos (id, n, position) local thing = getThingFromPos({x = position.x, y = position.y, z = position.z, stackpos = 1}) if(thing.itemid == id) then doRemoveItem(thing.uid, n) return true end return false end function getNpcName() return getCreatureName(getNpcId()) end function getNpcPos() return getCreaturePosition(getNpcId()) end function selfGetPosition() local t = getNpcPos() return t.x, t.y, t.z end msgcontains = doMessageCheck moveToPosition = selfMoveTo moveToCreature = selfMoveToCreature selfMoveToPosition = selfMoveTo selfGotoIdle = selfIdle isPlayerPremiumCallback = isPremium doPosRemoveItem = doRemoveItemIdFromPos doNpcBuyItem = doPlayerRemoveItem doNpcSetCreatureFocus = selfFocus getNpcCid = getNpcId getDistanceTo = getNpcDistanceTo getDistanceToCreature = getNpcDistanceToCreature