hi!
i hope you don't mind, i modified your userfunction a little, added some trivial info to the gold window title, and prettified the time and gold amound to be more human readable.
here is the code in case you want to integrate the functions, or if you know better code to do this stuff:
Code: Select all
--=== Developed by Lisa ===--
--=== Inspired by many ===--
--=== version 1.3 ===--
--=== Call the function ===--
--=== in WP onload ===--
function setwindow(ID)
unregisterTimer("timedSetWindowName");
unregisterTimer("setwindow")
local _starttime = os.time()
local function _humantime(iseconds)
local seconds = iseconds
if seconds == 0 then
--return nil;
return "00:00";
--return "H00:M00:S00";
else
hours = string.format("%02.f", math.floor(seconds/3600));
mins = string.format("%02.f", math.floor(seconds/60 - (hours*60)));
secs = string.format("%02.f", math.floor(seconds - hours*3600 - mins *60));
return hours..":"..mins
--return "H"..hours..":M"..mins..":S"..secs
end
end
local function prettynumber(bnumber)
local pretty = bnumber
while true do
pretty, k = string.gsub(pretty, "^(-?%d+)(%d%d%d)", '%1,%2')
if (k==0) then
break
end
end
return pretty
end
--=== track in game gold ===--
if ID == "gold" then
local currentgold = RoMScript('GetPlayerMoney("copper");')
local function _window()
local _charname = string.sub(player.Name,1,7)
local _timepassed = (os.time() - _starttime)/3600
local _printtime = _humantime(os.time() - _starttime)
local _goldreceived = RoMScript('GetPlayerMoney("copper");') - currentgold
local _goldperhour = string.sub((_goldreceived/_timepassed),1,8)
local updatedgold = RoMScript('GetPlayerMoney("copper");')
setWindowName(getHwnd(),sprintf(_charname..": Total gold: "..prettynumber(updatedgold).." Gold per hour: "
..prettynumber(_goldperhour).." Time passed: ".._printtime))
end
registerTimer("setwindow", secondsToTimer(30), _window);
elseif ID == "hp" then
local function _window()
setWindowName(getHwnd(),sprintf(player.Name.." Max HP: "..player.MaxHP.." Actual HP: "..player.HP))
end
registerTimer("setwindow", secondsToTimer(1), _window);
else
local _itemname
--=== ID as item name or item ID ===--
if type(tonumber(ID)) == "number" then -- arg is item Id
_itemname = string.sub(GetIdName(ID),1,10)
else
_itemname = string.sub(ID,1,10)
end
local _startitem = inventory:itemTotalCount(ID)
local function _window()
local _charname = string.sub(player.Name,1,7)
local _timepassed = (os.time() - _starttime)/3600 -- total time in hours
local _printtime = _humantime(os.time() - _starttime)
local _gathereditems = inventory:itemTotalCount(ID) - _startitem -- total items aquired since starting
local _itemsperhour = string.sub((_gathereditems/_timepassed),1,4)
local _currentitems = inventory:itemTotalCount(ID)
setWindowName(getHwnd(),sprintf(_charname..". ".._itemname..": "
.._currentitems.." (".._itemsperhour.."/h) Time(h): ".._printtime))
--setWindowName(getHwnd(),sprintf("1234567890123456789012345678901234567890123"))
end
registerTimer("setwindow", secondsToTimer(36), _window);
yrest(1000)
_window()
end
end
also, could you please make a possibility to pause this timer, because i saw that if the refreshing moment (at the end of the 30 sec cycle) coincides with a loading screen, the script throws an error at this line: local _goldreceived = RoMScript('GetPlayerMoney("copper");') - currentgold
so before the moment this occures i could put a pause on the timer, and resume on the next waypoint. no problem if the MM window loses this title for that moment. important is for it to keep the values to resume later.
or to auto pause while waitForLoadingScreen() is active
thanks for the script!