Ir para conteúdo

Featured Replies

  • Respostas 20
  • Visualizações 3.4k
  • Created
  • Última resposta

Top Posters In This Topic

Posted Images

Postado
Em 05/05/2019 em 15:32, Yan Liima disse:

1653830680_tradepointsbyyan.png.c475d473ea7d596da87f9104e0a4ae82.png

#Introdução

Reparei que muitas pessoas estão atrás desse sistema que o DBOBR e NTOBR usa, e atualmente o VitorSubhi postou um, porém é necessário modificar as sources. Apesar de achar o dele bem melhor, estarei deixando este meu sistema(não é necessário mexer nas sources).

 

#Funcionamente

O jogador vai até um NPC e compra um papel, após ter comprado ele pode estar dando trade nesse papel e negociando com algum jogador em troca de qualquer item. Ao finalizar a negociação, os points são transferidos/removidos(caso houver points na conta). Também é possivel comprar o papel por comando, estarei disponibilizando ambos para vocês.

 

#Alguns prints:

  Ocultar conteúdo

NPC:

npc.thumb.png.9f9b1ebf1415c07ab286a3bc7623ba35.png

Item no trade:

trade1.png.884e3809207b3f348423b60309dfe6b4.png

Sucesso na troca:

trade2.png.de467cabadcb5eb63920ab6938192c89.pngtrade3.png.d77ae271aefd54b46890dbab909f9e9f.png

ERROR:

trade4.png.bf5e80b0f4a07ce07bcb31b8e12997cb.pngtrade5.png.9b409580074ccbfac101d36a72b01166.png

 

Estarei deixando o script para vocês em inglês, modifique como quiser ;D

Então vamos lá...

#Instalação

Em data/lib crie um arquivo chamado tradepoints.lua cole isto dentro:

  Ocultar conteúdo


function scanContainer(item, tables)
    if isContainer(item.uid) then
        for i = 0, getContainerSize(item.uid) do
            local item_ct = getContainerItem(item.uid, i)
            if (item_ct) then
            if isContainer(item.uid) then
                scanContainer(item_ct, tables)
            end
            table.insert(tables, item_ct.itemid)
         end
      end
   end
end

function getAccountPointsTrade(cid)
	local Points = 0
	local Result = db.getResult("SELECT `premium_points` FROM `accounts` WHERE `name` = '"..getPlayerAccount(cid).."'")
	if Result:getID() ~= -1 then
		Points = Result:getDataInt("premium_points")
	end
	return tonumber(Points)
end

function doAccountAddPointsTrade(cid, count)
	return db.query("UPDATE `accounts` SET `premium_points` = '".. getAccountPointsTrade(cid) + count .."' WHERE `name` = '"..getPlayerAccount(cid).."'")
end

function doAccountRemovePointsTrade(cid, count)
	return db.query("UPDATE `accounts` SET `premium_points` = '".. getAccountPointsTrade(cid) - count .."' WHERE `name` = '"..getPlayerAccount(cid).."'")
end

 

 

Em data/creaturescripts/tradepoints.lua:

  Ocultar conteúdo


local ItemID = 1964 -- ID do papel

function PremmyPoints(item)
	return tonumber(getItemAttribute(item.uid, "points"))
end

function Success(fromplayer, toplayer, points)
   if getPlayerItemCount(toplayer, ItemID) >= 1 and getAccountPointsTrade(fromplayer) >= points then
    	doAccountRemovePointsTrade(fromplayer, points)
		doPlayerRemoveItem(toplayer, ItemID, 1)
		doAccountAddPointsTrade(toplayer, points)
		doPlayerSendTextMessage(toplayer, MESSAGE_STATUS_WARNING, "Transfer successfully, you can now use the ".. points .." premium points in our site shop!")
		doPlayerSendTextMessage(fromplayer, MESSAGE_STATUS_WARNING, "Was removed ".. points .." premium points of your account")
		return true
	end
end

function onTradeAccept(cid, target, item, targetItem)
	if isPlayer(cid) and isPlayer(target) then
	  if (item.itemid == ItemID and targetItem.itemid == ItemID) then
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You can not trade points for points, close the current trade, and try again.")
			doPlayerSendTextMessage(target, MESSAGE_STATUS_WARNING, "You can not trade points for points, close the current trade, and try again.")
			return false
      	end
       if item.itemid == ItemID then
			local points = PremmyPoints(item)
		if getAccountPointsTrade(cid) >= points then
			addEvent(Success, 1, cid, target, points)
		    else
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You do not have ".. points .." premium points to perform this procedure.")
			doPlayerSendTextMessage(target, MESSAGE_STATUS_WARNING, "The buyer does not have ".. points .." premium points to perform this procedure.")
			return false
			end
		end
		if targetItem.itemid == ItemID then
			local points = PremmyPoints(targetItem)
		if getAccountPointsTrade(target) >= points then
			addEvent(Success, 1, target, cid, points)
            else
			doPlayerSendTextMessage(target, MESSAGE_STATUS_WARNING, "You do not have ".. points .." premium points to perform this procedure.")
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "The buyer does not have ".. points .." premium points to perform this procedure.")
			return false
			end
		end
	end
	return true
end

function onTradeRequest(cid, target, item)
local tabela = {}
local black_list = {ItemID}
    scanContainer(item,tabela)
	for i = 1, #black_list do
		if isInArray(tabela, black_list[i]) then
			doPlayerSendTextMessage(cid, MESSAGE_STATUS_WARNING, "You can not place the premmy trade document in this trade, this document can only be used in trade outside containers (bag, backpack, etc).")
			return false
		end
	end
	return true
end

 

 

TAG:


<event type="tradeaccept" name="Trade_Points" event="script" value="tradepoints.lua"/>
<event type="traderequest" name="Trade_Points_Request" event="script" value="tradepoints.lua"/>

login.lua


registerCreatureEvent(cid, "Trade_Points")
registerCreatureEvent(cid, "Trade_Points_Request")

NPC XML:


<?xml version="1.0" encoding="UTF-8"?>
<npc name="Frodo" script="data/npc/scripts/trade_points.lua" walkinterval="2000" floorchange="0" access="5" level="1" maglevel="1">
	<health now="150" max="150"/>
	<look type="275" head="114" body="113" legs="113" feet="113" corpse="2212"/>
	<parameters>
		<parameter key="module_shop" value="1" />
		<parameter key="message_greet" value="Hello |PLAYERNAME|. I sell some utensils and Premium Points Transfer for you to transfer points to other players, remember to buy use '10' to 10 points." />
	</parameters>
</npc>

Data/npc/scripts/trade_points.lua:

  Ocultar conteúdo


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

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

function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end

local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid

---- CONFIG ----
local ItemID = 1964 -- ID do papel
local money = 10000 -- Custo para comprar o Papel(em gold coin)
local min,max = 10, 110 -- Valor minimo e maximo do points em papel
----  FIM ----

	if talkState[cid] == nil or talkState[cid] == 0 then
		points = tonumber(msg)
		if (points ~= nil) and (points>=min and points<=max) then
			selfSay("You can purchase a premium point transfer document that will transfer ".. points .." premium points, right?", cid)
			talkState[talkUser] = 1
		else
			selfSay("I can only sell documents that transfer premium points between "..min.." and "..max..".", cid)
			talkState[talkUser] = 0
		end
	elseif talkState[cid] == 1 then
		if msgcontains(msg, 'yes') then
		if doPlayerRemoveMoney(cid, money) then
			local Paper = doCreateItemEx(ItemID)
			doItemSetAttribute(Paper, "name", "".. points .." premium points transfer Paper")
			doItemSetAttribute(Paper, "points", points)
			selfSay("You got one ".. getItemNameById(ItemID) .." so good ".. points .." premium points, it was a pleasure doing business with you.", cid)
			doPlayerAddItemEx(cid, Paper, true)
			talkState[talkUser] = 0
		else
			selfSay("You do not have enough money!", cid)
			talkState[talkUser] = 0
		  end
		else
		selfSay('OK then!', cid)
		talkState[talkUser] = 0
	   end
	end
	return true
end

npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())

 

 

Caso queira que a compra do papel seja feita por talkactions, aqui está:

  Ocultar conteúdo


---- CONFIG ----
local itemID = 1964 -- ID do papel
local money = 10000 -- Custo para comprar o Papel(em gold coin)
local min,max = 10, 110 -- Valor minimo e maximo do points em papel
---- FIM ----

function onSay(cid, words, param)
	local name,points = "%s premium points transfer Paper",getAccountPointsTrade(cid)
	if param == "" or not tonumber(param) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, use only numbers.") return true
	elseif not doPlayerRemoveMoney(cid, money) then	
	doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "You do not have enough money!") return true
	elseif tonumber(param) < min or tonumber(param) > max then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, in between "..min.." and "..max.." points.") return true
	elseif points < tonumber(param) then
		doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Sorry, but you only have "..points.." Premium Points.") return true
	end
	local item = doPlayerAddItem(cid, itemID,1) 
	doItemSetAttribute(item, "name", name:format(tonumber(param)))
	doItemSetAttribute(item, "points", param)
	doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE,"You have received a paper with "..param.." Premium Points.")
	return true
end

 

 

Prontinho xD

Agradecimentos ao @lordzetros por ajudar na função scanContainer.

obs: testado em TFS 0.4

 

pra PDA??

  • 4 weeks later...
  • 2 years later...
Postado

Perdão por reviver esse tópico mas há alguma chance de você ter ele adaptado pra Znote?

Consegui refazer:
 

function scanContainer(item, tables)
    if isContainer(item.uid) then
        for i = 0, getContainerSize(item.uid) do
            local item_ct = getContainerItem(item.uid, i)
            if (item_ct) then
            if isContainer(item.uid) then
                scanContainer(item_ct, tables)
            end
            table.insert(tables, item_ct.itemid)
         end
      end
   end
end

function getAccountPointsTrade(cid)
	local Points = 0
	local Result = db.getResult("SELECT `points` FROM `znote_accounts` WHERE `account_id` = " .. getPlayerAccountId(cid) .. " LIMIT 1")
	if Result:getID() ~= -1 then
		Points = Result:getDataInt("points")
	end
	return tonumber(Points)
end

function doAccountAddPointsTrade(cid, count)
	return db.query("UPDATE `znote_accounts` SET `points` = ".. getAccountPointsTrade(cid) + count .." WHERE `account_id` = " .. getPlayerAccountId(cid) .. " LIMIT 1")
end

function doAccountRemovePointsTrade(cid, count)
	return db.query("UPDATE `znote_accounts` SET `points` = ".. getAccountPointsTrade(cid) - count .." WHERE `account_id` = " .. getPlayerAccountId(cid) .. " LIMIT 1")
end

 

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

VlVKQKC.png&key=d5c17620ae9567a1f898dd7a

 

 

 

  • 532144234_Logo_NTO_BLOOD_Finish_HIM_By_Antonio_Luckas(3).png.fd58d1af125a7e82ccdd751637e9ca93.png

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.6k

Informação Importante

Confirmação de Termo