Ir para conteúdo
Banner com Efeitos

[NPC] Fixando BUG de o NPC comprar itens equipados nos slots(corpo)!

Featured Replies

Postado
  • Este é um post popular.

Em alguns servidores a função 'doPlayerRemoveItem' não tem o parâmetro 'ignoreEquipped', fazendo com que o jogador acabe vendendo os itens que estão nos slots(equipados).

 

Esta função(gambiarra) serve para que o jogador ao vender itens no npc, o mesmo só compre itens que estiverem dentro da bp.

 

 

Primeiramente coloque essas duas funções na lib do seu ot caso você não tenha:

 

https://pastebin.com/raw/BfRLcrLA

 

 

agora vá em \data\npc\lib\npcsystem e abra o seu modules.lua 

 

substitua essa função:

 

	-- Callback onSell() function. If you wish, you can change certain Npc to use your onSell().
	function ShopModule:callbackOnSell(cid, itemid, subType, amount, ignoreCap, inBackpacks)
		if(self.npcHandler.shopItems[itemid] == nil) then
			error("[ShopModule.onSell]", "items[itemid] == nil")
			return false
		end

		if(self.npcHandler.shopItems[itemid].sellPrice == -1) then
			error("[ShopModule.onSell]", "Attempt to sell a non-sellable item")
			return false
		end

		local parseInfo = {
			[TAG_PLAYERNAME] = getPlayerName(cid),
			[TAG_ITEMCOUNT] = amount,
			[TAG_TOTALCOST] = amount * self.npcHandler.shopItems[itemid].sellPrice,
			[TAG_ITEMNAME] = self.npcHandler.shopItems[itemid].realName
		}

		if(subType < 1) then
			subType = -1
		end

		if(doPlayerRemoveItem(cid, itemid, amount, subType)) then
			local msg = self.npcHandler:getMessage(MESSAGE_SOLD)
			msg = self.npcHandler:parseMessage(msg, parseInfo)
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg)
			doPlayerAddMoney(cid, amount * self.npcHandler.shopItems[itemid].sellPrice)
			if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
				self.npcHandler.talkStart[cid] = os.time()
			else
				self.npcHandler.talkStart = os.time()
			end
			return true
		else
			local msg = self.npcHandler:getMessage(MESSAGE_NEEDITEM)
			msg = self.npcHandler:parseMessage(msg, parseInfo)
			doPlayerSendCancel(cid, msg)
			if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
				self.npcHandler.talkStart[cid] = os.time()
			else
				self.npcHandler.talkStart = os.time()
			end
			return false
		end
	end

 

por esta:

 

    -- Callback onSell() function. If you wish, you can change certain Npc to use your onSell().
function ShopModule:callbackOnSell(cid, itemid, subType, amount, ignoreCap, inBackpacks)
	if(self.npcHandler.shopItems[itemid] == nil) then
		error("[ShopModule.onSell]", "items[itemid] == nil")
		return false
	end	
	if(self.npcHandler.shopItems[itemid].sellPrice == -1) then
		error("[ShopModule.onSell]", "Attempt to sell a non-sellable item")
		return false
	end
	local parseInfo = {
		[TAG_PLAYERNAME] = getPlayerName(cid),
		[TAG_ITEMCOUNT] = amount,
		[TAG_TOTALCOST] = amount * self.npcHandler.shopItems[itemid].sellPrice,
		[TAG_ITEMNAME] = self.npcHandler.shopItems[itemid].realName
	}
	if(subType < 1) then
		subType = -1
	end
	if getPlayerSlotItem(cid, CONST_SLOT_BACKPACK).itemid ~= 0 then
		local bp = getPlayerSlotItem(cid, CONST_SLOT_BACKPACK)
		local z = getContainerItemsById(bp, itemid)
		if #z >= amount then
			for i = 1, amount do
				doRemoveItem(z[i].uid)
			end
			local msg = self.npcHandler:getMessage(MESSAGE_SOLD)
			msg = self.npcHandler:parseMessage(msg, parseInfo)
			doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, msg)
			doPlayerAddMoney(cid, amount * self.npcHandler.shopItems[itemid].sellPrice)
			if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
				self.npcHandler.talkStart[cid] = os.time()
			else
				self.npcHandler.talkStart = os.time()
			end
			return true
		else
			local msg = self.npcHandler:getMessage(MESSAGE_NEEDITEM)
			msg = self.npcHandler:parseMessage(msg, parseInfo)
			doPlayerSendCancel(cid, msg)
			if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
				self.npcHandler.talkStart[cid] = os.time()
			else
				self.npcHandler.talkStart = os.time()
			end
			return false
		end
	else
		doPlayerSendCancel(cid, "I only buy items that are inside a BackPack")
		if(NPCHANDLER_CONVBEHAVIOR ~= CONVERSATION_DEFAULT) then
			self.npcHandler.talkStart[cid] = os.time()
		else
			self.npcHandler.talkStart = os.time()
		end				
		return false
	end
end

 

vodkart_logo.png

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

 

DISCORDvodkart#6090

 

  • Respostas 8
  • Visualizações 2.7k
  • Created
  • Última resposta

Top Posters In This Topic

Most Popular Posts

  • acho esse problema nao ocorre na tfs 1.3 alias se ocorrer a função q remove item ja tem parâmetro pra solucionar player:removeItem(itemId, count[, subType = -1[, ignoreEquipped = false]])  

  • Irei teste e mando o papo aqui! obrigado por disponibilizar!

  • Nossa, já tinha visto esse tópico mas não comentei. Parabéns pela dedicação Vodk, sempre ajudando as pessoas com scripts e soluções, muito nobre!

Postado

Irei teste e mando o papo aqui! obrigado por disponibilizar!

 

 

 

 

 

                                                                                                                                                     tumblr_nwmv2z4VEM1ujiquxo1_100.gif.2db64bb36f0f565e68ff2a90cb98f439.gif.59f4c4cf234d2f6906621cac0553a862.gif

https://github.com/italoxxx1

 

  • 3 weeks later...
Postado
Em 29/10/2020 em 08:03, diegokenshin disse:

tfs 1.3?

 

acho esse problema nao ocorre na tfs 1.3

alias se ocorrer a função q remove item ja tem parâmetro pra solucionar

player:removeItem(itemId, count[, subType = -1[, ignoreEquipped = false]])

 

Discord: Naze#3578

 

Ter Linux Dentro de Windows com Acesso 'localhost' para testes e +

AutoLoot Otimizado Direto na Source (tfs 0.4/otx)

 

// Pirataria é crime, original é roubo, compartilhar é legal.

 

tumblr_muk78tEwDQ1qah4nko1_500.gif

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

Quem Está Navegando 0

  • Nenhum usuário registrado visualizando esta página.

Estatísticas dos Fóruns

  • Tópicos 96.9k
  • Posts 519.7k

Informação Importante

Confirmação de Termo