Jump to content

[Sistema] Trade Points


Recommended Posts

  • Diretor

tradepoints by yan.png

#Introdução

Reparei que muitas pessoas estão atrás desse sistema que o DBOBR & 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:

Spoiler

NPC:

npc.png

Item no trade:

trade1.png

Sucesso na troca:

trade2.pngtrade3.png

ERROR:

trade4.pngtrade5.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:

Spoiler

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/creaturescript/tradepoints.lua:

Spoiler

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:

Spoiler

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á:

Spoiler

---- 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

 

 

TAG:

<talkaction words="!sellpoints;/sellpoints" event="script" value="trade_points.lua"/>

 

Prontinho xD

Agradecimentos ao Junior(lordzetros) por ajudar na função scanContainer e ao @VitorSubhi

Link to comment
Share on other sites

  • 5 months later...

[4/2/2020 17:47:1] >>> Loading creaturescripts... [Error - Event::checkScript] Event onTradeAccept not found (data/creaturescripts/scripts/tradepoints.lua)
[4/2/2020 17:47:1] [Error - Event::checkScript] Event onTradeRequest not found (data/creaturescripts/scripts/tradepoints.lua)

Link to comment
Share on other sites

×
×
  • Create New...