Skip to content

Commit

Permalink
v0.1
Browse files Browse the repository at this point in the history
Added first version.
* Trade window not working.
  • Loading branch information
diasreuf committed Aug 23, 2020
0 parents commit 76580a9
Show file tree
Hide file tree
Showing 2 changed files with 779 additions and 0 deletions.
107 changes: 107 additions & 0 deletions OtNpcSystem/functions.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
--[[
* OtNpcSystem v0.1
* by Robson Dias (diasreuf@gmail.com)
* Based in "Advanced NPC System by Jiddo"
]]--

function doNpcSellItem(cid, itemid, amount, subType, ignoreCap, inBackpacks, backpack)

local amount = amount or 1
local subType = subType or 0
local item = 0
if isItemStackable(itemid) then
if inBackpacks then
stuff = doCreateItemEx(backpack, 1)
item = doAddContainerItem(stuff, itemid, math.min(100, amount))
else
stuff = doCreateItemEx(itemid, math.min(100, amount))
end
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 table.contains({(getContainerCapById(backpack) * b), amount}, i) then
if doPlayerAddItemEx(cid, container, ignoreCap) ~= RETURNVALUE_NOERROR then
b = b - 1
break
end

a = i
if amount > i then
container = doCreateItemEx(backpack, 1)
b = b + 1
end
end
end
return a, b
end

for i = 1, amount do -- normal method for non-stackable items
local item = doCreateItemEx(itemid, subType)
if doPlayerAddItemEx(cid, item, ignoreCap) ~= RETURNVALUE_NOERROR then
break
end
a = i
end

return a, 0
end

function doPlayerTakeItem(cid, itemid, count)
if getPlayerItemCount(cid,itemid) < count then
return false
end

while count > 0 do
local tempcount = 0
if isItemStackable(itemid) then
tempcount = math.min (100, count)
else
tempcount = 1
end

local ret = doPlayerRemoveItem(cid, itemid, tempcount)
if ret ~= false then
count = count - tempcount
else
return false
end
end

if count ~= 0 then
return false
end
return true
end

function doPlayerSellItem(cid, itemid, count, cost)
if doPlayerTakeItem(cid, itemid, count) == true then
if not doPlayerAddMoney(cid, cost) then
error('Could not add money to ' .. getPlayerName(cid) .. '(' .. cost .. 'gp)')
end
return true
end
return false
end

function doPlayerBuyItemContainer(cid, containerid, itemid, count, cost, charges)
if not doPlayerRemoveMoney(cid, cost) then
return false
end

for i = 1, count do
local container = doCreateItemEx(containerid, 1)
for x = 1, getContainerCapById(containerid) do
doAddContainerItem(container, itemid, charges)
end

if doPlayerAddItemEx(cid, container, true) ~= RETURNVALUE_NOERROR then
return false
end
end
return true
end
Loading

0 comments on commit 76580a9

Please sign in to comment.