-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added first version. * Trade window not working.
- Loading branch information
0 parents
commit 76580a9
Showing
2 changed files
with
779 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.