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!