- Joined
- Aug 6, 2007
- Messages
- 1,767
- Reaction score
- 36
Oke for the people who really needed it, here's my ADVANCED BuyContainer i could have make it with cap+slot check but i'm simply to lazy:thumbup:
Lets start! follow this exactly!
Modules.lua
After:
Add:
Before:
Add:
After:
Add
After
Add
Add
Global.lua
Before
Add
And u are done!!! How to use this new npc functions? like this =)
dont forget to edit the ids of shopModule:buyContainer({'bp sd'}, Backpack, Rune, Prise, Charges, 'Backpack of sudden death') in runes.lua (line 26) or it will bug.
Runes.lua
The only way u can really thank me is giving me rep+!, SO i know for what i am doing it for:blink:
Lets start! follow this exactly!
Minor Bug fix: Thank you tala for fixing it
Cap check was made by slawkens
Modules.lua
After:
Code:
SHOPMODULE_BUY_ITEM = 2
Add:
Code:
SHOPMODULE_BUY_CONTAINER = 3
Before:
Code:
function ShopModule:addBuyableItem(names, itemid, cost, charges, realname)
for i, name in pairs(names) do
local parameters = {
itemid = itemid,
cost = cost,
eventType = SHOPMODULE_BUY_ITEM,
module = self
}
if(realname ~= nil) then
parameters.realname = realname
end
if(isItemRune(itemid) == TRUE or isItemFluidContainer(itemid) == TRUE) then
parameters.charges = charges
end
keywords = {}
table.insert(keywords, name)
local node = self.npcHandler.keywordHandler:addKeyword(keywords, ShopModule.tradeItem, parameters)
node:addChildKeywordNode(self.yesNode)
node:addChildKeywordNode(self.noNode)
end
end
Add:
Code:
function ShopModule:buyContainer(names, container, itemid, cost, charges, realname)
for i, name in pairs(names) do
local parameters = {
container = container,
itemid = itemid,
cost = cost,
charges = charges,
eventType = SHOPMODULE_BUY_CONTAINER,
module = self
}
if(realname ~= nil) then
parameters.realname = realname
end
if(isItemRune(itemid) == TRUE or isItemFluidContainer(itemid) == TRUE) then
parameters.charges = charges
end
keywords = {}
table.insert(keywords, name)
local node = self.npcHandler.keywordHandler:addKeyword(keywords, ShopModule.tradeItem, parameters)
node:addChildKeywordNode(self.yesNode)
node:addChildKeywordNode(self.noNode)
end
end
After:
Code:
if(parameters.eventType == SHOPMODULE_SELL_ITEM) then
tmpName = node:getKeywords()[2]
Add
Code:
elseif(parameters.eventType == SHOPMODULE_BUY_CONTAINER) then
tmpName = node:getKeywords()[3]
After
Code:
if(parameters.eventType == SHOPMODULE_SELL_ITEM) then
local msg = module.npcHandler:getMessage(MESSAGE_SELL)
msg = module.npcHandler:parseMessage(msg, parseInfo)
selfSay(msg)
Add
Code:
elseif(parameters.eventType == SHOPMODULE_BUY_CONTAINER) then
local msg = module.npcHandler:getMessage(MESSAGE_BUY)
msg = module.npcHandler:parseMessage(msg, parseInfo)
selfSay(msg)
Code:
After
Code:
if(parentParameters.eventType == SHOPMODULE_SELL_ITEM) then
local ret = doPlayerSellItem(cid, parentParameters.itemid, module.amount, parentParameters.cost*module.amount)
if(ret == LUA_NO_ERROR) then
local msg = module.npcHandler:getMessage(MESSAGE_ONSELL)
msg = module.npcHandler:parseMessage(msg, parseInfo)
selfSay(msg)
else
local msg = module.npcHandler:getMessage(MESSAGE_NOTHAVEITEM)
msg = module.npcHandler:parseMessage(msg, parseInfo)
selfSay(msg)
end
Code:
elseif(parentParameters.eventType == SHOPMODULE_BUY_CONTAINER) then
local ret = doPlayerbuyContainer(cid, parentParameters.container, parentParameters.itemid, parentParameters.charges, parentParameters.cost*module.amount, module.amount)
if(ret == LUA_NO_ERROR) then
local msg = module.npcHandler:getMessage(MESSAGE_ONBUY)
msg = module.npcHandler:parseMessage(msg, parseInfo)
selfSay(msg)
elseif(ret == LUA_ERROR) then
local msg = module.npcHandler:getMessage(MESSAGE_NEEDMOREMONEY)
msg = module.npcHandler:parseMessage(msg, parseInfo)
selfSay(msg)
else
local msg = module.npcHandler:getMessage(MESSAGE_NEEDMORESPACE)
msg = module.npcHandler:parseMessage(msg, parseInfo)
selfSay(msg, cid)
end
Global.lua
Before
Code:
function doPlayerBuyItem(cid, itemid, count, cost, charges)
if(doPlayerRemoveMoney(cid, cost) == TRUE) then
return doPlayerGiveItem(cid, itemid, count, charges)
end
return LUA_ERROR
end
Add
Code:
function doPlayerBuyItemContainer(cid, container, itemid, charges, cost, count)
if getPlayerFreeCap(cid) > (getItemWeightById(itemid, 20)*count + getItemWeightById(container, count)) then
if doPlayerRemoveMoney(cid, cost) == TRUE then
for i = 1, count do
local containerItem = doPlayerAddItem(cid, container, 1)
for x = 1, 20 do
doAddContainerItem(containerItem, itemid, charges)
end
end
return LUA_NO_ERROR
end
else
return
end
return LUA_ERROR
end
And u are done!!! How to use this new npc functions? like this =)
dont forget to edit the ids of shopModule:buyContainer({'bp sd'}, Backpack, Rune, Prise, Charges, 'Backpack of sudden death') in runes.lua (line 26) or it will bug.
Runes.lua
Code:
-- OTServ event handling functions start
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
-- OTServ event handling functions end
local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)
shopModule:addBuyableItem({'light wand', 'lightwand'}, 2163, 500, 'magic light wand')
shopModule:addBuyableItem({'heavy magic missile'}, 2311, 125, 10, 'heavy magic missile rune')
shopModule:addBuyableItem({'great fireball'}, 2304, 180, 4, 'great fireball rune')
shopModule:addBuyableItem({'explosion'}, 2313, 250, 6, 'explosion rune')
shopModule:addBuyableItem({'ultimate healing'}, 2273, 175, 2, 'ultimate healing rune')
shopModule:addBuyableItem({'sudden death'}, 2268, 325, 2, 'sudden death rune')
shopModule:addBuyableItem({'blank'}, 2260, 10, 'blank rune')
shopModule:buyContainer({'bp sd'}, Backpack, Rune, Price, Charges, 'Backpack of sudden death')
shopModule:buyContainer({'bp uh'}, 2003, 2273, 1, 1, 'Backpack of ultimate healing')
shopModule:buyContainer({'bp ih'}, 2003, 2265, 300, 1, 'Backpack of intense healing')
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
The only way u can really thank me is giving me rep+!, SO i know for what i am doing it for:blink:
Last edited: