Very nice, added to the scriptuse a recursive container search:
Lua:function searchContainer(container, items) items = items or {} for i = container:getSize()-1, 0, -1 do local item = container:getItem(i) if item:getType():isContainer() then searchContainer(item, items) else items[#items+1] = item end end return items end
function Player:onTradeAccept(target, item, targetItem)
file = io.open('data/logs/trade.log',"a")
file:write(""..os.date("%c")..": "..self:getName().." traded:")
if item:isContainer() then
local pitems = searchContainer(item)
for i = 1, #pitems do
file:write(string.format(' %s (%s)(%s),'...
function Player:onTradeAccept(target, item, targetItem)
local currenttime = tonumber(os.date("%H%M", os.time()))
file = io.open('data/logs/tradelog.txt',"w")
file:write(""..currenttime..": "..player:getName().." traded "..item:getName().." for "..targetItem:getName().." with "..target:getName()...".")
file:close()
return true
end
In events/scripts/player.lua put
I don't know if it will work and I don't think 0.4 has onTradeAcceptLua:function Player:onTradeAccept(target, item, targetItem) local currenttime = tonumber(os.date("%H%M", os.time())) file = io.open('data/logs/tradelog.txt',"w") file:write(""..currenttime..": "..player.." traded "..item.." for "..targetItem.." with "..target..".") file:close() return true end
That's one thing I couldn't be bothered to doif it's a container it'll need description of items inside
function Player:onTradeAccept(target, item, targetItem)
local currenttime = tonumber(os.date("%H%M", os.time()))
file = io.open('data/logs/tradelog.txt',"w")
file:write(""..currenttime..": "..self:getName().." traded")
if item:isContainer() then
local pitems = item:getItemHoldingCount()
for i, pitems do
file:write(" "..item:getItem(i):getName()..",")
end
else
file:write(" "..item:getName().."")
end
file:write(" with "..target:getName().." for")
if targetItem:isContainer() then
local titems = targetItem:getItemHoldingCount()
for i, titems do
file:write(" "..targetItem:getItem(i):getName()..",")
end
else
file:write(" "..targetItem:getName()..".")
end
file:close()
return true
end
i have erro 1That's one thing I couldn't be bothered to do
EDIT:
I don't know if this will work or what it will look like:
Lua:function Player:onTradeAccept(target, item, targetItem) local currenttime = tonumber(os.date("%H%M", os.time())) file = io.open('data/logs/tradelog.txt',"w") file:write(""..currenttime..": "..player.." traded") if item:isContainer() then for i, #item:getItemHoldingCount() do file:write(" "..item:getItem(i)..",") end else file:write(" "..item.."") end file:write(" with "..target.." for") if targetItem:isContainer() then for i, #targetItem:getItemHoldingCount() do file:write(" "..targetItem:getItem(i)..",") end else file:write(" "..targetItem..".") end file:close() return true end
[Warning - Events::load] Can not load script: player.luaTry above, updated
That's one thing I couldn't be bothered to do
EDIT:
I don't know if this will work or what it will look like:
Lua:function Player:onTradeAccept(target, item, targetItem) local currenttime = tonumber(os.date("%H%M", os.time())) file = io.open('data/logs/tradelog.txt',"w") file:write(""..currenttime..": "..self:getName().." traded") if item:isContainer() then local pitems = item:getItemHoldingCount() for i, #pitems do file:write(" "..item:getItem(i):getName()..",") end else file:write(" "..item:getName().."") end file:write(" with "..target:getName().." for") if targetItem:isContainer() then local titems = targetItem:getItemHoldingCount() for i, #titems do file:write(" "..targetItem:getItem(i):getName()..",") end else file:write(" "..targetItem:getName()..".") end file:close() return true end
Eeuuuuughhhhhhh thats what you call overthinking (or not reading about functions properly and just whacking them in).. fixed'getItemHoldingCount()' returns just a number not items table.
[Warning - Events::load] Can not load script: player.luaEeuuuuughhhhhhh thats what you call overthinking (or not reading about functions properly and just whacking them in).. fixed
Thanks a lot
EDIT:
Is there a function that returns the items contained in the container and will it return items in the container within the container?
How would you go about doing that?
Eeuuuuughhhhhhh thats what you call overthinking (or not reading about functions properly and just whacking them in).. fixed
Thanks a lot
EDIT:
Is there a function that returns the items contained in the container and will it return items in the container within the container?
How would you go about doing that?
Eeuuuuughhhhhhh thats what you call overthinking (or not reading about functions properly and just whacking them in).. fixed
Thanks a lot
EDIT:
Is there a function that returns the items contained in the container and will it return items in the container within the container?
How would you go about doing that?
function searchContainer(container, items)
items = items or {}
for i = container:getSize()-1, 0, -1 do
local item = container:getItem(i)
if item:getType():isContainer() then
searchContainer(item, items)
else
items[#items+1] = item
end
end
return items
end
local items = searchContainer(item)
where i add it ?use a recursive container search:
Lua:function searchContainer(container, items) items = items or {} for i = container:getSize()-1, 0, -1 do local item = container:getItem(i) if item:getType():isContainer() then searchContainer(item, items) else items[#items+1] = item end end return items end
Lua:local items = searchContainer(item)
Very nice, added to the scriptuse a recursive container search:
Lua:function searchContainer(container, items) items = items or {} for i = container:getSize()-1, 0, -1 do local item = container:getItem(i) if item:getType():isContainer() then searchContainer(item, items) else items[#items+1] = item end end return items end
function Player:onTradeAccept(target, item, targetItem)
file = io.open('data/logs/trade.log',"a")
file:write(""..os.date("%c")..": "..self:getName().." traded:")
if item:isContainer() then
local pitems = searchContainer(item)
for i = 1, #pitems do
file:write(string.format(' %s (%s)(%s),', pitems[i]:getName(), pitems[i]:getId(), pitems[i]:getCount() > 1 and pitems[i]:getCount()))
end
else
file:write(string.format(' %s (%s)(%s),', item:getName(), item:getId(), item:getCount() > 1 and item:getCount()))
end
file:write(" with "..target:getName().." for:")
if targetItem:isContainer() then
local titems = searchContainer(targetItem)
for i = 1, #titems do
file:write(string.format(' %s (%s)(%s),', titems[i]:getName(), titems[i]:getId(), titems[i]:getCount() > 1 and titems[i]:getCount()))
end
else
file:write(string.format(' %s (%s)(%s).', targetItem:getName(), targetItem:getId(), targetItem:getCount() > 1 and targetItem:getCount()))
end
file:write('\n-------------------------\n\n')
file:close()
return true
end
I made some changes:
Lua:function Player:onTradeAccept(target, item, targetItem) file = io.open('data/logs/trade.log',"a") file:write(""..os.date("%c")..": "..self:getName().." traded:") if item:isContainer() then local pitems = searchContainer(item) for i = 1, #pitems do file:write(string.format(' %s (%s)(%s),', pitems[i]:getName(), pitems[i]:getId(), pitems[i]:getCount() > 1 and pitems[i]:getCount())) end else file:write(string.format(' %s (%s)(%s),', item:getName(), item:getId(), item:getCount() > 1 and item:getCount())) end file:write(" with "..target:getName().." for:") if targetItem:isContainer() then local titems = searchContainer(targetItem) for i = 1, #titems do file:write(string.format(' %s (%s)(%s),', titems[i]:getName(), titems[i]:getId(), titems[i]:getCount() > 1 and titems[i]:getCount())) end else file:write(string.format(' %s (%s)(%s).', targetItem:getName(), targetItem:getId(), targetItem:getCount() > 1 and targetItem:getCount())) end file:write('\n-------------------------\n\n') file:close() return true end
Code:Thu Apr 20 12:12:18 2017: Knight traded: soul orb (5944)(6), with Druid for: giant sword (2393)(false). ------------------------- Thu Apr 20 12:12:48 2017: Knight traded: platinum coin (2152)(78), with Druid for: lightning boots (7893)(false). -------------------------
But someone can help me with this (false) if count is 1, want to looks like:
Code:Thu Apr 20 12:12:48 2017: Knight traded: platinum coin (2152)(78), with Druid for: lightning boots (7893).