Legal esse sistema ![]()
- Fórum
- OTServ
- Recursos
- Scripting
- Globalevents e Spells
- Monitorando todos os trades do servidor (Trade log)
Monitorando todos os trades do servidor (Trade log)
Por larissaots, 29 de mai. de 2015 em Globalevents e Spells
info
Grupo: Campones
Registrado: 06/11/11
Posts: 93
Reputação: 0
Char no Tibia: Deprex

Editado Junho 18 por damiaotorres
info
Grupo: Barão
Registrado: 07/03/08
Posts: 231
Reputação: +17
Gênero: Masculino

Não tem para TFS 0.4 ?
info
Grupo: Visconde
Registrado: 08/12/15
Posts: 309
Reputação: +133
Gênero: Masculino

Funciona em TFS 0.4 ? Caso não funcione, poderia adaptar para funcionar?
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
info
Grupo: Diretor
Registrado: 12/05/12
Posts: 818
Reputação: +578
Gênero: Masculino
Char no Tibia: [ADM] Night

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:
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:
<?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:
<?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 Julho 6 por nedroesdoksdja
1 hora atrás, Yan Liima disse:
Tenta por MOD
Logs na database:
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:
<?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:
<?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>
info
Grupo: Diretor
Registrado: 12/05/12
Posts: 818
Reputação: +578
Gênero: Masculino
Char no Tibia: [ADM] Night

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.
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:
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:
<?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:
<?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.
info
Grupo: Diretor
Registrado: 12/05/12
Posts: 818
Reputação: +578
Gênero: Masculino
Char no Tibia: [ADM] Night

53 minutos atrás, bilaux disse:
Sim, data/logs/Trades.txt.
isso conta, itens de alavanca ou só trade de player para player ??
11 horas atrás, Yan Liima disse:Sim, data/logs/Trades.txt.
info
Grupo: Diretor
Registrado: 12/05/12
Posts: 818
Reputação: +578
Gênero: Masculino
Char no Tibia: [ADM] Night

1 hora atrás, bilaux disse:isso conta, itens de alavanca ou só trade de player para player ??
itens de alavanca? ksks só trade de player para player mesmo.






info
Grupo: Banidos
Registrado: 07/04/13
Posts: 648
Reputação: +163
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 endEm data/creaturescripts adicione no creaturescripts.xml a seguinte linha:
Em data/creaturescripts/scripts/ abra o arquivo login.lua e adicione:
Pronto, agora você poderá monitorar os trades em seu servidor!