Ir para conteúdo

Monitorando todos os trades do servidor (Trade log)


larissaots

Posts Recomendados

Créditos à Anonimo e Animal Park.

 

Objetivo

O script consiste em criar um log .txt em data/logs/trades mostrando quais itens foram passados entre os jogadores dentro do seu servidor

 

Tutorial

Em data/creaturescripts/scripts/ crie um arquivo .lua chamado: checktrades.lua e dentro coloque:

local servers = {[0] = 'server1', [1] = 'server2', [2] = 'server3'}

local function getType(item)
return (item.type > 0) and item.type or 1
end

Log = {}
Log.__index = Log

function Log.create()
local t = {}
setmetatable(t, Log)
t.file = servers[getConfigValue("worldId")] .. "/" .. os.date("%B-%d-%Y", os.time()) .. ".txt"
t.str, t.cstr, t.con = '', '', 0
return t
end

function Log:write()
local f = io.open("data/logs/trades/" .. self.file, "a+")
if not f then return false end
f:write(self.str)
f:close()
end

function Log:containerString()
self.cstr = ''
for i = 1, self.con do
self.cstr = self.cstr .. '-> '
end
end

function Log:addContainer()
self.con = self.con + 1
self:containerString()
end

function Log:closeContainer()
self.con = self.con - 1
self:containerString()
end

function Log:setLine(txt)
self.str = self.str .. self.cstr .. txt .. '\n'
end

function Log:kill()
self.file, self.cstr, self.str, self.con = "", "", "", -1
end

function onTradeAccept(cid, target, item, targetItem)
local this = Log.create()
local name, tname = getCreatureName(cid), getCreatureName(target)

this:setLine("Trade between " .. name .. " and " .. tname .. " || [" .. os.date("%d/%m/%Y %H:%M:%S") .. "]")

local function logging(cid, item)
this:setLine(getCreatureName(cid) .. " traded:")
local function scanContainer(cid, uid)
for k = (getContainerSize(uid) - 1), 0, -1 do
local tmp = getContainerItem(uid, k)
this:setLine(getItemNameById(tmp.itemid) .. " x " .. getType(tmp) .. " || itemid: " .. tmp.itemid)
if isContainer(tmp.uid) then
this:addContainer()
scanContainer(cid, tmp.uid)
this:closeContainer()
end
end
end

this:setLine(getItemNameById(item.itemid) .. " x " .. getType(item) .. " || itemid: " .. item.itemid) 
if isContainer(item.uid) then
this:addContainer()
scanContainer(cid, item.uid)
this:closeContainer()
end
end

logging(cid, item)
logging(target, targetItem)
this:setLine("END OF THIS TRADE --------------\n")
this:write()
this:kill()
return true
end

Em data/creaturescripts adicione no creaturescripts.xml a seguinte linha:

<event type="trade" name="tradeCheck" event="script" value="checktrades.lua"/>

Em data/creaturescripts/scripts/ abra o arquivo login.lua e adicione:

registerCreatureEvent(cid, "tradeCheck")

Pronto, agora você poderá monitorar os trades em seu servidor!

Link para o comentário
Compartilhar em outros sites

  • 3 weeks later...
  • 1 year later...

não funfa pra DxP por nao ter a funçao creature event.trade nas sources ;/: acho ne kk pq ficou dando esse erro

 

[Error - CreatureEvent::configureEvent] No valid type for creature event.trade

Link para o comentário
Compartilhar em outros sites

  • Diretor
Em 04/07/2016 at 16:11, samlecter disse:

Funciona em TFS 0.4 ? Caso não funcione, poderia adaptar para funcionar?

 

24 minutos atrás, Josegvb disse:

não funfa pra DxP por nao ter a funçao creature event.trade nas sources ;/: acho ne kk pq ficou dando esse erro

 

[Error - CreatureEvent::configureEvent] No valid type for creature event.trade

 

Tenta por MOD

 

Logs na database:

Spoiler

Na database execute esta Query:

CREATE TABLE players_trade (        id    INTEGER NOT NULL,        world_id INTEGER NOT NULL,        player_id INTEGER NOT NULL,        target_id INTEGER NOT NULL,        player_items  INTEGER NOT NULL,        target_items  INTEGER NOT NULL,        date     INTEGER NOT NULL,PRIMARY KEY ( id ));

Na pasta mods crie um arquivo.xml e coloque isto dentro:

Spoiler

<?xml version="1.0" encoding="UTF-8"?>  

<mod name="Trade Log" version="1.0" author="Vodkart" contact="none.com" enabled="yes">  

<config name="TradeLog_func"><![CDATA[

function natural(number)

local n = number - math.floor(number)

return n >= 0.5 and math.ceil(number) or math.floor(number)

end

function containerItemsToString(cont)

   local s = ""

   for _ = 0, getContainerSize(cont) - 1 do

      local item = getContainerItem(cont, _)

      s = s..",".. item.itemid

      if isContainer(item.uid) and getContainerSize(item.uid) > 0 then

         s = s..":1"..containerItemsToString(item.uid)

      else

         s = s..":".. natural(getItemWeight(item.uid)/getItemWeightById(item.itemid))

      end

   end

   return s

end

]]></config>

<event type="login" name="TradeRegister" event="script"><![CDATA[

function onLogin(cid)

registerCreatureEvent(cid, "TradeLog")

    return true

    end]]></event>      

<event type="tradeaccept" name="TradeLog" event="script"><![CDATA[

domodlib('TradeLog_func')

function onTradeAccept(cid, target, item, targetItem)

if (not isPlayer(cid)) or (not isPlayer(target)) then return false end

local items1,items2 = ""..item.itemid,""..targetItem.itemid

items1 = isContainer(item.uid) and getContainerSize(item.uid) > 0 and items1..":1"..containerItemsToString(item.uid) or items1 ..":".. natural(getItemWeight(item.uid)/getItemWeightById(item.itemid))

items2 = isContainer(targetItem.uid) and getContainerSize(targetItem.uid) > 0 and items2 ..":1"..containerItemsToString(targetItem.uid) or items2 ..":".. natural(getItemWeight(targetItem.uid)/getItemWeightById(targetItem.itemid))

db.query("INSERT INTO `players_trade` (`world_id`, `player_id`, `target_id`, `player_items`, `target_items`, `date`) VALUES ('".. getConfigValue("worldId") .."', '".. getPlayerGUID(cid) .."', '".. getPlayerGUID(target) .."', '".. items1 .."', '".. items2 .."', '".. os.time() .."');")

return true

end

]]></event>

</mod>

 

Se for TFS 0.3.6 - troque db.query por db.executeQuery

Logs por txt:

Na pasta mods crie um arquivo .xml e cole isto dentro:

Spoiler

<?xml version="1.0" encoding="UTF-8"?>  

<mod name="Trade Log" version="1.0" author="Vodkart" contact="none.com" enabled="yes">  

<config name="TradeLog_func"><![CDATA[

function natural(number)

local n = number - math.floor(number)

return n >= 0.5 and math.ceil(number) or math.floor(number)

end

function containerItemsToString(cont)

   local s = ""

   for _ = 0, getContainerSize(cont) - 1 do

      local item = getContainerItem(cont, _)

      s = s..",".. item.itemid

      if isContainer(item.uid) and getContainerSize(item.uid) > 0 then

         s = s..":1"..containerItemsToString(item.uid)

      else

         s = s..":".. natural(getItemWeight(item.uid)/getItemWeightById(item.itemid))

      end

   end

   return s

end

]]></config>

<event type="login" name="TradeRegister" event="script"><![CDATA[

function onLogin(cid)

registerCreatureEvent(cid, "TradeLog")

    return true

    end]]></event>      

<event type="tradeaccept" name="TradeLog" event="script"><![CDATA[

domodlib('TradeLog_func')

function onTradeAccept(cid, target, item, targetItem)

if (not isPlayer(cid)) or (not isPlayer(target)) then return false end

local items1,items2 = ""..item.itemid,""..targetItem.itemid

items1 = isContainer(item.uid) and getContainerSize(item.uid) > 0 and items1..":1"..containerItemsToString(item.uid) or items1 ..":".. natural(getItemWeight(item.uid)/getItemWeightById(item.itemid))

items2 = isContainer(targetItem.uid) and getContainerSize(targetItem.uid) > 0 and items2 ..":1"..containerItemsToString(targetItem.uid) or items2 ..":".. natural(getItemWeight(targetItem.uid)/getItemWeightById(targetItem.itemid))

f = io.open("data/logs/Trades.txt", "a+")

f:write("World: ".. getConfigValue("worldId") .." -  "..getPlayerName(cid).." Traded: [".. items1 .."] for [".. items2 .."] With Player "..getPlayerName(target)..". At " .. os.date("%d %B %Y - %X.", os.time()) .."\n\n----------------------------------------------------------\n")

f:close()

return true

end

]]></event>

</mod>

 

Testado em TFS 0.4.

Editado por nedroesdoksdja
Link para o comentário
Compartilhar em outros sites

1 hora atrás, Yan Liima disse:

 

 

Tenta por MOD

 

Logs na database:

  Mostrar conteúdo oculto

Na database execute esta Query:

CREATE TABLE players_trade (        id    INTEGER NOT NULL,        world_id INTEGER NOT NULL,        player_id INTEGER NOT NULL,        target_id INTEGER NOT NULL,        player_items  INTEGER NOT NULL,        target_items  INTEGER NOT NULL,        date     INTEGER NOT NULL,PRIMARY KEY ( id ));

Na pasta mods crie um arquivo.xml e coloque isto dentro:

  Mostrar conteúdo oculto

<?xml version="1.0" encoding="UTF-8"?>  

<mod name="Trade Log" version="1.0" author="Vodkart" contact="none.com" enabled="yes">  

<config name="TradeLog_func"><![CDATA[

function natural(number)

local n = number - math.floor(number)

return n >= 0.5 and math.ceil(number) or math.floor(number)

end

function containerItemsToString(cont)

   local s = ""

   for _ = 0, getContainerSize(cont) - 1 do

      local item = getContainerItem(cont, _)

      s = s..",".. item.itemid

      if isContainer(item.uid) and getContainerSize(item.uid) > 0 then

         s = s..":1"..containerItemsToString(item.uid)

      else

         s = s..":".. natural(getItemWeight(item.uid)/getItemWeightById(item.itemid))

      end

   end

   return s

end

]]></config>

<event type="login" name="TradeRegister" event="script"><![CDATA[

function onLogin(cid)

registerCreatureEvent(cid, "TradeLog")

    return true

    end]]></event>      

<event type="tradeaccept" name="TradeLog" event="script"><![CDATA[

domodlib('TradeLog_func')

function onTradeAccept(cid, target, item, targetItem)

if (not isPlayer(cid)) or (not isPlayer(target)) then return false end

local items1,items2 = ""..item.itemid,""..targetItem.itemid

items1 = isContainer(item.uid) and getContainerSize(item.uid) > 0 and items1..":1"..containerItemsToString(item.uid) or items1 ..":".. natural(getItemWeight(item.uid)/getItemWeightById(item.itemid))

items2 = isContainer(targetItem.uid) and getContainerSize(targetItem.uid) > 0 and items2 ..":1"..containerItemsToString(targetItem.uid) or items2 ..":".. natural(getItemWeight(targetItem.uid)/getItemWeightById(targetItem.itemid))

db.query("INSERT INTO `players_trade` (`world_id`, `player_id`, `target_id`, `player_items`, `target_items`, `date`) VALUES ('".. getConfigValue("worldId") .."', '".. getPlayerGUID(cid) .."', '".. getPlayerGUID(target) .."', '".. items1 .."', '".. items2 .."', '".. os.time() .."');")

return true

end

]]></event>

</mod>

 

Logs por txt

Na pasta mods crie um arquivo .xml e cole isto dentro:

  Mostrar conteúdo oculto

<?xml version="1.0" encoding="UTF-8"?>  

<mod name="Trade Log" version="1.0" author="Vodkart" contact="none.com" enabled="yes">  

<config name="TradeLog_func"><![CDATA[

function natural(number)

local n = number - math.floor(number)

return n >= 0.5 and math.ceil(number) or math.floor(number)

end

function containerItemsToString(cont)

   local s = ""

   for _ = 0, getContainerSize(cont) - 1 do

      local item = getContainerItem(cont, _)

      s = s..",".. item.itemid

      if isContainer(item.uid) and getContainerSize(item.uid) > 0 then

         s = s..":1"..containerItemsToString(item.uid)

      else

         s = s..":".. natural(getItemWeight(item.uid)/getItemWeightById(item.itemid))

      end

   end

   return s

end

]]></config>

<event type="login" name="TradeRegister" event="script"><![CDATA[

function onLogin(cid)

registerCreatureEvent(cid, "TradeLog")

    return true

    end]]></event>      

<event type="tradeaccept" name="TradeLog" event="script"><![CDATA[

domodlib('TradeLog_func')

function onTradeAccept(cid, target, item, targetItem)

if (not isPlayer(cid)) or (not isPlayer(target)) then return false end

local items1,items2 = ""..item.itemid,""..targetItem.itemid

items1 = isContainer(item.uid) and getContainerSize(item.uid) > 0 and items1..":1"..containerItemsToString(item.uid) or items1 ..":".. natural(getItemWeight(item.uid)/getItemWeightById(item.itemid))

items2 = isContainer(targetItem.uid) and getContainerSize(targetItem.uid) > 0 and items2 ..":1"..containerItemsToString(targetItem.uid) or items2 ..":".. natural(getItemWeight(targetItem.uid)/getItemWeightById(targetItem.itemid))

f = io.open("data/logs/Trades.txt", "a+")

f:write("World: ".. getConfigValue("worldId") .." -  "..getPlayerName(cid).." Traded: [".. items1 .."] for [".. items2 .."] With Player "..getPlayerName(target)..". At " .. os.date("%d %B %Y - %X.", os.time()) .."\n\n----------------------------------------------------------\n")

f:close()

return true

end

]]></event>

</mod>

 

Testado em TFS 0.4.

 

apos fazer isso, o trade buga e sempre q for aceitar fica dando "trade cancelled"

e no log aparesce:

[06/07/2016 11:45:19] [Error - CreatureScript Interface] 

[06/07/2016 11:45:19] buffer:onTradeAccept

[06/07/2016 11:45:19] Description: 

[06/07/2016 11:45:19] [string "loadBuffer"]:5: attempt to call global 'natural' (a nil value)

[06/07/2016 11:45:19] stack traceback:

[06/07/2016 11:45:19]     [string "loadBuffer"]:5: in function <[string "loadBuffer"]:2>

 

Link para o comentário
Compartilhar em outros sites

  • Diretor
1 hora atrás, Josegvb disse:

 

apos fazer isso, o trade buga e sempre q for aceitar fica dando "trade cancelled"

e no log aparesce:

[06/07/2016 11:45:19] [Error - CreatureScript Interface] 

[06/07/2016 11:45:19] buffer:onTradeAccept

[06/07/2016 11:45:19] Description: 

[06/07/2016 11:45:19] [string "loadBuffer"]:5: attempt to call global 'natural' (a nil value)

[06/07/2016 11:45:19] stack traceback:

[06/07/2016 11:45:19]     [string "loadBuffer"]:5: in function <[string "loadBuffer"]:2>

 

 

LoL estranho... Testei em TFS 0.3.6 e 0.4 e obtive sucesso nos dois.

Link para o comentário
Compartilhar em outros sites

  • 2 years later...

log vai aparecer na pasta data/logs ??? @Yan Liima

 

 

Em 06/07/2016 em 11:25, Yan Liima disse:

 

 

Tenta por MOD

 

Logs na database:

  Ocultar conteúdo

Na database execute esta Query:



CREATE TABLE players_trade (        id    INTEGER NOT NULL,        world_id INTEGER NOT NULL,        player_id INTEGER NOT NULL,        target_id INTEGER NOT NULL,        player_items  INTEGER NOT NULL,        target_items  INTEGER NOT NULL,        date     INTEGER NOT NULL,PRIMARY KEY ( id ));

Na pasta mods crie um arquivo.xml e coloque isto dentro:

  Mostrar conteúdo oculto

<?xml version="1.0" encoding="UTF-8"?>  

<mod name="Trade Log" version="1.0" author="Vodkart" contact="none.com" enabled="yes">  

<config name="TradeLog_func"><![CDATA[

function natural(number)

local n = number - math.floor(number)

return n >= 0.5 and math.ceil(number) or math.floor(number)

end

function containerItemsToString(cont)

   local s = ""

   for _ = 0, getContainerSize(cont) - 1 do

      local item = getContainerItem(cont, _)

      s = s..",".. item.itemid

      if isContainer(item.uid) and getContainerSize(item.uid) > 0 then

         s = s..":1"..containerItemsToString(item.uid)

      else

         s = s..":".. natural(getItemWeight(item.uid)/getItemWeightById(item.itemid))

      end

   end

   return s

end

]]></config>

<event type="login" name="TradeRegister" event="script"><![CDATA[

function onLogin(cid)

registerCreatureEvent(cid, "TradeLog")

    return true

    end]]></event>      

<event type="tradeaccept" name="TradeLog" event="script"><![CDATA[

domodlib('TradeLog_func')

function onTradeAccept(cid, target, item, targetItem)

if (not isPlayer(cid)) or (not isPlayer(target)) then return false end

local items1,items2 = ""..item.itemid,""..targetItem.itemid

items1 = isContainer(item.uid) and getContainerSize(item.uid) > 0 and items1..":1"..containerItemsToString(item.uid) or items1 ..":".. natural(getItemWeight(item.uid)/getItemWeightById(item.itemid))

items2 = isContainer(targetItem.uid) and getContainerSize(targetItem.uid) > 0 and items2 ..":1"..containerItemsToString(targetItem.uid) or items2 ..":".. natural(getItemWeight(targetItem.uid)/getItemWeightById(targetItem.itemid))

db.query("INSERT INTO `players_trade` (`world_id`, `player_id`, `target_id`, `player_items`, `target_items`, `date`) VALUES ('".. getConfigValue("worldId") .."', '".. getPlayerGUID(cid) .."', '".. getPlayerGUID(target) .."', '".. items1 .."', '".. items2 .."', '".. os.time() .."');")

return true

end

]]></event>

</mod>

 

Se for TFS 0.3.6 - troque db.query por db.executeQuery

Logs por txt:

Na pasta mods crie um arquivo .xml e cole isto dentro:

  Ocultar conteúdo

<?xml version="1.0" encoding="UTF-8"?>  

<mod name="Trade Log" version="1.0" author="Vodkart" contact="none.com" enabled="yes">  

<config name="TradeLog_func"><![CDATA[

function natural(number)

local n = number - math.floor(number)

return n >= 0.5 and math.ceil(number) or math.floor(number)

end

function containerItemsToString(cont)

   local s = ""

   for _ = 0, getContainerSize(cont) - 1 do

      local item = getContainerItem(cont, _)

      s = s..",".. item.itemid

      if isContainer(item.uid) and getContainerSize(item.uid) > 0 then

         s = s..":1"..containerItemsToString(item.uid)

      else

         s = s..":".. natural(getItemWeight(item.uid)/getItemWeightById(item.itemid))

      end

   end

   return s

end

]]></config>

<event type="login" name="TradeRegister" event="script"><![CDATA[

function onLogin(cid)

registerCreatureEvent(cid, "TradeLog")

    return true

    end]]></event>      

<event type="tradeaccept" name="TradeLog" event="script"><![CDATA[

domodlib('TradeLog_func')

function onTradeAccept(cid, target, item, targetItem)

if (not isPlayer(cid)) or (not isPlayer(target)) then return false end

local items1,items2 = ""..item.itemid,""..targetItem.itemid

items1 = isContainer(item.uid) and getContainerSize(item.uid) > 0 and items1..":1"..containerItemsToString(item.uid) or items1 ..":".. natural(getItemWeight(item.uid)/getItemWeightById(item.itemid))

items2 = isContainer(targetItem.uid) and getContainerSize(targetItem.uid) > 0 and items2 ..":1"..containerItemsToString(targetItem.uid) or items2 ..":".. natural(getItemWeight(targetItem.uid)/getItemWeightById(targetItem.itemid))

f = io.open("data/logs/Trades.txt", "a+")

f:write("World: ".. getConfigValue("worldId") .." -  "..getPlayerName(cid).." Traded: [".. items1 .."] for [".. items2 .."] With Player "..getPlayerName(target)..". At " .. os.date("%d %B %Y - %X.", os.time()) .."\n\n----------------------------------------------------------\n")

f:close()

return true

end

]]></event>

</mod>

 

Testado em TFS 0.4.

 

Link para o comentário
Compartilhar em outros sites

×
×
  • Criar Novo...