#1 2008-12-01 16:18:21

GoD Trojca

Moderator

9772290
Skąd: Belgia
Zarejestrowany: 2008-11-27
Posty: 43
Login :: God Trojca
Świat :: TibiaTower
Level :: 666

NPC Sprzedający bp potionów

przed tym wszystkim chcę poweidzieć że skrypt nie jest mój i że działa pod 8.1. To jadziem:

Otwieramy data/npc/scripts/lib/npcsystem/modules.lua

Szukamy:
Cytat:

Spoiler:

SHOPMODULE_BUY_ITEM = 2

Pod tym dodajemy:
Cytat:

Spoiler:

SHOPMODULE_BUY_CONTAINER = 3

Szukamy:
Cytat:

Spoiler:

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

I PRZED tym dodajemy:
Cytat:

Spoiler:

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

Szukamy:
Cytat:

Spoiler:

if(parameters.eventType == SHOPMODULE_SELL_ITEM) then
tmpName = node:getKeywords()[2]

Za tym dodajemy:
Cytat:

Spoiler:

elseif(parameters.eventType == SHOPMODULE_BUY_CONTAINER) then
tmpName = node:getKeywords()[3]

Szukamy:
Cytat:

Spoiler:

if(parameters.eventType == SHOPMODULE_SELL_ITEM) then
local msg = module.npcHandler:getMessage(MESSAGE_SELL)
msg = module.npcHandlerarseMessage(msg, parseInfo)
selfSay(msg)

I za dodajemy:
Cytat:

Spoiler:

elseif(parameters.eventType == SHOPMODULE_BUY_CONTAINER) then
local msg = module.npcHandler:getMessage(MESSAGE_BUY)
msg = module.npcHandlerarseMessage(msg, parseInfo)
selfSay(msg)

teraz szukamy:
Cytat:

Spoiler:

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.npcHandlerarseMessage(msg, parseInfo)
selfSay(msg)
else
local msg = module.npcHandler:getMessage(MESSAGE_NOTHAVEITEM)
msg = module.npcHandlerarseMessage(msg, parseInfo)
selfSay(msg)
end

I pod dodajemy:
Cytat:

Spoiler:

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.npcHandlerarseMessage(msg, parseInfo)
selfSay(msg)
else
local msg = module.npcHandler:getMessage(MESSAGE_NEEDMOREMONEY )
msg = module.npcHandlerarseMessage(msg, parseInfo)
selfSay(msg)
end
Wchodzimy w data/global.lua

Szukamy:

Spoiler:

Cytat:
function doPlayerBuyItem(cid, itemid, count, cost, charges)
if(doPlayerRemoveMoney(cid, cost) == TRUE) then
return doPlayerGiveItem(cid, itemid, count, charges)
end
return LUA_ERROR
end

Dodajemy za tym:
Cytat:

Spoiler:

function doPlayerbuyContainer(cid, container, itemid, charges, cost, count)
if doPlayerRemoveMoney(cid, cost) == TRUE then
for i = 1, count do
local backpack = doPlayerAddItem(cid, container, 1)
for x = 1, 20 do
doAddContainerItem(backpack, itemid, charges)
end
end
return LUA_NO_ERROR
end
return LUA_ERROR
end

Jeśli ktoś chce sobie zrobić NPC mający już funckję sprzedawania potionów to tutaj ma skrypt:
Cytat:

Spoiler:

<?xml version="1.0"?>

<npc name="Marian Potionek" script="data/npc/scripts/potiony.lua" access="3" lookdir="2" autowalk="25">
<mana now="800" max="800"/>
<health now="200" max="200"/>
<look type="130" head="114" body="112" legs="76" feet="39" addons="1"/>
</npc>

W data/npc/scripts tworzymy plik potiony.lua i wklejamy:
Cytat:

Spoiler:

local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)



-- OTServ event handling functions start
function onCreatureAppear(cid) npcHandlernCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandlernCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandlernCreatureSay(cid, type, msg) end
function onThink() npcHandlernThink() end
-- OTServ event handling functions end

local shopModule = ShopModule:new()
npcHandler:addModule(shopModule)

shopModule:buyContainer({'bp mp'}, 2000, 7620, 1000, 20, 'Backpack of Mana Potions')
shopModule:buyContainer({'bp hp'}, 2000, 7618, 1000, 20, 'Backpack of Health Potions')
shopModule:buyContainer({'bp smp'}, 2000, 7589, 2200, 20, 'Backpack of Strong Mana Potions')
shopModule:buyContainer({'bp shp'}, 2000, 7588, 2200, 20, 'Backpack of Strong Health Potions')
shopModule:buyContainer({'bp gmp'}, 2000, 7590, 4400, 20, 'Backpack of Great Mana Potions')
shopModule:buyContainer({'bp ghp'}, 2000, 7591, 4400, 20, 'Backpack of Great Health Potions')
npcHandler:addModule(FocusModule:new())

Jak ktoś chce, żeby potiony znikały po użyciu wchodzi w skrypt potionów

Szuka:
Cytat:

Spoiler:

doTransformItem(item.uid, emptyPot)

Zastępuje:
Cytat:

Spoiler:

doRemoveItem(item.uid,1)

Ostatnio edytowany przez GoD Trojca (2008-12-01 16:22:12)

Offline

 

Stopka forum

RSS
Powered by PunBB
© Copyright 2002–2008 PunBB
Polityka cookies - Wersja Lo-Fi


Darmowe Forum | Ciekawe Fora | Darmowe Fora
GotLink.plnhw fliplife kołdra amz