Ahh yeah I did 360 instead of 3600, fixed.
Ok this is working copy of userfunction, uses item Id or "gold" as the arg.
The name print is of course entire name and I think that is to long, not sure how to handle that, if you reduce how many letters are on window then it doesn't really tell you the name.
i.e. 5 letters, Major
Major First Aid Potion
Major Magic Potion
I reduced the numbers printed by time and items/hour using string.sub so prints maximum of 4 digits.
I feel my _itemsperhour is failing me, I am getting negative numbers when it should be 0. Either way the foundation for code is there, obviously need to add in checks to make sure the ID is correct and such. Also fix the items per hour.
Code: Select all
function setwindow(ID)
unregisterTimer("timedSetWindowName");
unregisterTimer("setwindow")
local _starttime = os.time()
--=== check for ID as an item ID ===--
if type(tonumber(ID)) == "number" then -- arg is item Id
local _name = GetIdName(ID)
local _startitem = inventory:itemTotalCount(ID)
local function _window()
local _timepassed = (os.time() - _starttime)/3600 -- total time in hours
local _printtime = string.sub(_timepassed,1,4)
local _gathereditems = inventory:itemTotalCount(ID) - _startitem -- total items aquired since starting
local _itemsperhour = string.sub((_gathereditems/_timepassed),1,4)
local _currenteggs = inventory:itemTotalCount(ID) -- golden eggs
setWindowName(getHwnd(),sprintf(player.Name.." Item name: ".._name.." per hour: "
.._itemsperhour.." Time passed: ".._printtime))
end
registerTimer("setwindow", secondsToTimer(30), _window);
end
--=== track in game gold ===--
if ID == "gold" then
local currentgold = RoMScript('GetPlayerMoney("copper");')
local function _window()
local _timepassed = (os.time() - _starttime)/3600
local _printtime = string.sub(_timepassed,1,4)
local _goldreceived = RoMScript('GetPlayerMoney("copper");') - currentgold
local _goldperhour = string.sub((_goldreceived/_timepassed),1,4)
setWindowName(getHwnd(),sprintf(player.Name.." Gold per hour: "
.._goldperhour.." Time passed: ".._printtime))
end
registerTimer("setwindow", secondsToTimer(30), _window);
end
end