Ir para conteúdo
  • Cadastre-se

Posts Recomendados

Versão: 8.70

TFS testado: 0.4 (Crystal Server)

Bem, eu modifiquei essa função para servidores 8.70.

Em lib/050-funcion.lua adicione depois do END na ultima linha:


function customCallbackOnBuy(cid, itemid, subType, amount, ignoreCap, inBackpacks, shopWindow)

	local shopItem, npcHandler = nil, NpcHandler

	for _, item in ipairs(shopWindow) do

		if not item.subType then

			item.subType = (isItemFluidContainer(item.id) == TRUE or isItemStackable(item.id) == TRUE) and 0 or 1

		end

		if(item.id == itemid and (item.subType == subType)) then

			shopItem = item

			break

		end

	end


	if(shopItem == nil) then

		error("[ShopModule.onBuy]", "Item not found on shopItems list")

		return false

	end


	if(shopItem.buy < 0) then

		error("[ShopModule.onSell]", "Attempt to purchase an item which is only sellable")

		return false

	end


	local backpack, totalCost = 1988, amount * shopItem.buy

	if(inBackpacks) then

		totalCost = isItemStackable(itemid) == TRUE and totalCost + 20 or totalCost + (math.max(1, math.floor(amount / getContainerCapById(backpack))) * 20)

	end


	if(getPlayerMoney(cid) < totalCost) then

		doPlayerSendCancel(cid, npcHandler:parseMessage(npcHandler:getMessage(MESSAGE_NEEDMONEY), {[TAG_PLAYERNAME] = getPlayerName(cid), [TAG_ITEMCOUNT] = amount, [TAG_TOTALCOST] = totalCost, [TAG_ITEMNAME] = shopItem.name}))

		return false

	end


	local subType = shopItem.subType or isItemFluidContainer(itemid) == TRUE and 0 or 1

	local a, b = doNpcSellItem(cid, itemid, amount, subType, ignoreCap, inBackpacks, backpack)

	if(a < amount) then

		local msgId = MESSAGE_NEEDMORESPACE

		if(a == 0) then

			msgId = MESSAGE_NEEDSPACE

		end


		doPlayerSendCancel(cid, npcHandler:parseMessage(npcHandler:getMessage(msgId), {[TAG_PLAYERNAME] = getPlayerName(cid), [TAG_ITEMCOUNT] = amount, [TAG_TOTALCOST] = totalCost, [TAG_ITEMNAME] = shopItem.name, [TAG_ITEMCOUNT] = a}))


		if(a > 0) then

			doPlayerRemoveMoney(cid, ((a * shopItem.buy) + (b * 20)))

			return true

		end


		return false

	end

	doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, npcHandler:parseMessage(npcHandler:getMessage(MESSAGE_BOUGHT), {[TAG_PLAYERNAME] = getPlayerName(cid), [TAG_ITEMCOUNT] = amount, [TAG_TOTALCOST] = totalCost, [TAG_ITEMNAME] = shopItem.name}))

	doPlayerRemoveMoney(cid, totalCost)


	return true

end


function customCallbackOnSell(cid, itemid, subType, amount, ignoreCap, inBackpacks, shopWindow)

	local shopItem, npcHandler, subType = nil, NpcHandler, subType or 0

	for _, item in ipairs(shopWindow) do

		item.subType = not item.subType and 0 or item.subType

		if(item.id == itemid and (isItemFluidContainer(itemid) == FALSE or isItemFluidContainer(itemid) == TRUE and item.subType == subType)) then

			shopItem = item

			break

		end

	end


	if(shopItem == nil) then

		error("[ShopModule.onBuy]", "Item not found on shopItems list")

		return false

	end


	if(shopItem.sell < 0) then

		error("[ShopModule.onSell]", "Attempt to sell an item which is only buyable")

		return false

	end


	if(doPlayerRemoveItem(cid, itemid, amount, isItemFluidContainer(itemid) == TRUE and subType or isItemStackable(itemid) == TRUE and amount or 1) == TRUE) then

		doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, npcHandler:parseMessage(npcHandler:getMessage(MESSAGE_SOLD), {[TAG_PLAYERNAME] = getPlayerName(cid), [TAG_ITEMCOUNT] = amount, [TAG_TOTALCOST] = amount * shopItem.sell, [TAG_ITEMNAME] = shopItem.name}))

		doPlayerAddMoney(cid, amount * shopItem.sell)


		return true

	end

	doPlayerSendCancel(cid, npcHandler:parseMessage(npcHandler:getMessage(MESSAGE_NEEDITEM), {[TAG_PLAYERNAME] = getPlayerName(cid), [TAG_ITEMCOUNT] = amount, [TAG_TOTALCOST] = amount * shopItem.sell, [TAG_ITEMNAME] = shopItem.name}))


	return false

end

Como usar:

openShopWindow(cid, items,

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

customCallbackOnBuy(cid, itemid, subType, amount, ignoreCap, inBackpacks, items)

end

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

customCallbackOnSell(cid, itemid, subType, amount, ignoreCap, inBackpacks, items)

end

Exemplos:

elseif msgcontains(msg, 'trade') and getPlayerStorageValue(cid, STORAGE_ID) >= 1 then

local items = {

{name='lump of dirt', id=10609, sell=15},

{name='carrion worm fang', id=11192, sell=25},

{name='gland', id=8971, sell=35},

{name='slingshot', id=5907, buy=50000},

}

STORAGE_ID: É o storageid que o player precisa ter para dar trade com o NPC, caso não queira, basta retirar ficando assim:

elseif msgcontains(msg, 'trade') >= 1 then

local items = {

{name='lump of dirt', id=10609, sell=15},

{name='carrion worm fang', id=11192, sell=25},

{name='gland', id=8971, sell=35},

{name='slingshot', id=5907, buy=50000},

}

Bem, é isso ae, como é minha primeira função que estou postando, meu tópico deve estar um lixo!

Créditos: TFS 70%

Subyth 30%

Link para o post
Compartilhar em outros sites

Não entendo muito .Lua

Explique oque a função faz para nós.

Expliquei, é porque eu editei agora, apertei TAB e o fórum enviou o tópico kkk

Bem, mais expliquei ai, se não entendeu me fala novamente que eu poderei explicar detalhadamente :D

Link para o post
Compartilhar em outros sites


elseif msgcontains(msg, 'trade') >= 1 then

local items = {

{name='lump of dirt', id=10609, sell=15},

{name='carrion worm fang', id=11192, sell=25},

{name='gland', id=8971, sell=35},

{name='slingshot', id=5907, buy=50000},

}

Você pode adicionar o trade system em um npc que da missão exemplo: Task system. Assim é bem melhor doque fazer:

shopModule:addSellableItem({'dragon scale mail', 'dsm'},				  2492, 40000,    'dragon scale mail')

shopModule:addSellableItem({'dwarven armor', 'dwarven armor'},		    2503, 30000,    'dwarven armor')

shopModule:addSellableItem({'golden armor', 'golden armor'},			  2466, 20000,    'golden armor')

shopModule:addSellableItem({'leopard armor', 'leopard armor'},		    3968, 1000,	 'leopard armor')

shopModule:addSellableItem({'mammoth fur cape', 'mfc'},				   7463, 6000,	 'mammoth fur cape')

que no caso, é bem mais chato!

E você também pode adicionar getPlayerStorageValue(cid, STORAGE_ID) para que o player só possa comprar se possuir tal storagevalue, irá ser ótimo para Djinn's npc's.

Link para o post
Compartilhar em outros sites

Entendi, o bom é que as possibilidades de criação são infinitas, não é só para djinn's shop rs.

Que bom que vocÊ entendeu :D

Isso mesmo, essa é a ideia da função ;x

Link para o post
Compartilhar em outros sites

elseif msgcontains(msg, 'trade') >= 1 then
lol?
elseif msgcontains(msg, 'trade') then

também não entendi muito bem a função '-', ela já não existia? esse tipo de script eu costumava fazer tal...

Editado por Vodkart (veja o histórico de edições)

vodkart_logo.png

[*Ninguém será digno do sucesso se não usar suas derrotas para conquistá-lo.*]

 

DISCORDvodkart#6090

 

Link para o post
Compartilhar em outros sites

elseif msgcontains(msg, 'trade') >= 1 then
lol?
elseif msgcontains(msg, 'trade') then

também não entendi muito bem a função '-', ela já não existia? esse tipo de script eu costumava fazer tal...

Eu que errei na hora de explicar, esqueci de tira o >= 1 CTRL + C e +V na hora de explicar é tenso kkkk

Tipo, eu não sei se tinha, pelo menos no meu 8.70 não tinha, eu adicionei mais apareçeu milhares de erros (2) kkk mais bem, eu corrigir e trouxe para cá, como não tem créditos, coloquei do TFS mesmo ;x

Link para o post
Compartilhar em outros sites

Participe da conversa

Você pode postar agora e se cadastrar mais tarde. Se você tem uma conta, faça o login para postar com sua conta.

Visitante
Responder

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emojis são permitidos.

×   Seu link foi automaticamente incorporado.   Mostrar como link

×   Seu conteúdo anterior foi restaurado.   Limpar o editor

×   Não é possível colar imagens diretamente. Carregar ou inserir imagens do URL.

  • Quem Está Navegando   0 membros estão online

    Nenhum usuário registrado visualizando esta página.

×
×
  • Criar Novo...

Informação Importante

Confirmação de Termo