ScriptUO

Official ScriptUO EasyUO Scripts => Scripting Chat => Topic started by: Cerveza on September 28, 2010, 09:08:10 AM

Title: Anyone have a timer sub?
Post by: Cerveza on September 28, 2010, 09:08:10 AM
Something that could be used like this:

Code: [Select]
set %starttime #sCnt

script stuff
gosub TimeCounterUpperSubThatCervWants
event ExMsg #charID 3 0 Script has been running for #RESULT

sub TimeCounterUpperSubThatCervWants
this is what I want right here...
return

So I can just set the beginning time of a script and send that to the sub which will return the Hours:Minutes:Seconds that it's been running. "Script has been running for 1:26:33"
Title: Re: Anyone have a timer sub?
Post by: TrailMyx on September 28, 2010, 09:12:27 AM
Check out the CLAw.  I even have a sub that breaks down the timer into HH:MM:SS
Title: Re: Anyone have a timer sub?
Post by: Cerveza on September 28, 2010, 09:21:55 AM
That's what I'm looking for. Something I can send the start #sCnt to and have it return elapsed time since in the HH:MM:SS format.
Title: Re: Anyone have a timer sub?
Post by: TrailMyx on September 28, 2010, 09:26:48 AM
Here's the sub:

Code: [Select]
;-------------------------------------------------------------------------------
; %1 = input - Time to convert
; #RESULT -  Time converted to #:##:## format
sub ConvertTimeHourMinSec
  namespace push
  namespace local ctime
  set !hourpart %1 / 3600
  set !secpart ( %1 % 3600 ) % 60
  set !minpart ( ( %1 % 3600 ) / 60 )
  
  if !hourpart >= 10
    set #RESULT !hourpart , :
  else
    set #RESULT 0 , !hourpart , :
  if !minpart < 10
    set #RESULT #RESULT , 0
  set #RESULT #RESULT , !minpart , :
  if !secpart < 10
    set #RESULT #RESULT , 0
  set #RESULT #RESULT , !secpart
  namespace pop
return #RESULT

Just send it your #SCNT - %starttime.

And here it is for OEUO:

Code: [Select]
---------------------------------------------------------------
function ConvertTimeHourMinSec(t)
  local hourpart = math.floor(t / 3600)
  local secpart = math.floor(( t % 3600 ) % 60)
  local minpart = math.floor(( t % 3600 ) / 60)
  local rval = ""
  if hourpart >= 10 then
    rval = hourpart..":"
  else
    rval = "0"..hourpart..":"
  end
  if minpart < 10 then
    rval = rval.."0"
  end
  rval = rval..minpart..":"
  if secpart < 10 then
    rval = rval.."0"
  end
  return rval..secpart
end
Title: Re: Anyone have a timer sub?
Post by: Cerveza on September 28, 2010, 09:49:59 AM
This will work well with what I'm doing...

Code: [Select]
sub weight_check_send
  set %weight_to_send ( #maxWeight - %weightoffset )
  if #weight <= %weight_to_send
    return

  finditem %leather C_ , #backpackID
  set %hidecount ( %hidecount + #findStack )
  gosub SendItems %leather

  set %runtime ( #sCnt - %start_time )
  gosub ConvertTimeHourMinSec %runtime

  event ExMsg #charID 3 0 %hidecount hides / #RESULT minutes
return

I could even do a hides per hour LOL. Well... maybe I couldn't.... :(
Title: Re: Anyone have a timer sub?
Post by: Tidus on September 28, 2010, 10:01:52 AM
you could.  you just have to use your scnt and then divide by how many hides you collected.

convert your scnt to minutes.     math..  (minutes/hides)/60 = HPH


edit: well actually my math might be wrong...  my brain is now fizzling.

edit2: (minutes*hides)/60

bah never mind..  i suck at math.
Title: Re: Anyone have a timer sub?
Post by: Cerveza on September 28, 2010, 10:05:27 AM
LOL I may play with it... make a pop up menu that shows a meter with hides per hour? Nah... heh. I may put it in the event exMsg though.
Title: Re: Anyone have a timer sub?
Post by: Tidus on September 28, 2010, 10:08:33 AM
oh oh oh..i think i got the math.    Minutes/60 = %hour         %hides/%hour = HPM  LMAO
Title: Re: Anyone have a timer sub?
Post by: Endless Night on September 28, 2010, 10:13:58 AM
Heres what i do   Returns  Days:Hrs:Mins:secs

Code: [Select]
sub ENs_CalculateRunningTime ; %1=ScriptStartTime
  set %Runningtime #scnt - %1
  set %RunningTimedays  %RunningTime / 86400
  set !X %RunningTime - ( %runningtimedays * 86400 )
  set %RunningTimeHrs  %RunningTime / 3600
  set !X %RunningTime - ( %runningtimehrs * 3600 )
  set %RunningTimeMins !x / 60
  set %RunningTimeSecs !x - ( %RunningTimeMins * 60 )
  set %RunningTimeText %RunningTimeDays , : , %RunningTimeHrs , : , %RunningTimeMins , : , %RunningTimeSecs
Return %runningtimeText
Title: Re: Anyone have a timer sub?
Post by: Cerveza on September 28, 2010, 10:16:12 AM
I'll have to use that one EN, since I already have a TM sub in. I want to spread the thanks!
Title: Re: Anyone have a timer sub?
Post by: 12TimesOver on September 28, 2010, 10:23:11 AM
oh oh oh..i think i got the math.    Minutes/60 = %hour         %hides/%hour = HPM  LMAO
LOL

You finally got it - "hides/(Minutes/60)=hidesperhour"

For example, 1000 hides in 300 minutes:

1000/(300/60) = 1000/5 = 200 hides per hour

X
Title: Re: Anyone have a timer sub?
Post by: manwinc on September 28, 2010, 10:33:15 AM
Lol, it took me a while to get the timer working for my miners menu. Not Gonna Lie! Lol was like GRRRRRRRRRRRRRRRRRRRR
Title: Re: Anyone have a timer sub?
Post by: Cerveza on September 28, 2010, 10:48:43 AM
I could use this coding...

Code: [Select]
if #sCnt = ( %start_time + 3600 )
  display ok It's been an hour, how many hides have you sent?$That's your damn hides per hour, YO
Title: Re: Anyone have a timer sub?
Post by: TrailMyx on September 28, 2010, 10:50:47 AM
I'll have to use that one EN, since I already have a TM sub in. I want to spread the thanks!

I'm kinda anal when it comes to formatting.  I want it to read: 9:02:04 instead of 9:2:4.  ;)
Title: Re: Anyone have a timer sub?
Post by: TrailMyx on September 28, 2010, 11:02:59 AM
Useful for those who want to do the WHATEVER/HR. computations and show the decimal results:

Code: [Select]
;-------------------------------------------------------------------------------
sub TM_DecimalDivision
  namespace push
  namespace local DEC
  for !i 1 %3
  {
    if !i = 1
      set !places 10
    else
      set !places !places * 10
  }
  set !val ( %1 * !places ) / %2
  set !whole !val / !places
  set !dec !val % !places
  set #RESULT !whole , #dot , !dec
  namespace pop
return #RESULT

Used in my MIB/Hr for example:

Code: [Select]
set %val_dec %mibcount * 3600
set %time #SCNT - %programstarttime
gosub TM_DecimalDivision %val_dec %time 3 ; 3 decimal places
set %formattedmibperhour MIB/hr.: , #SPC , #RESULT

Title: Re: Anyone have a timer sub?
Post by: Tidus on September 28, 2010, 11:04:20 AM
all i have to say is... your subs make me feel like a mouse next to a cat....
Title: Re: Anyone have a timer sub?
Post by: TrailMyx on September 28, 2010, 11:09:49 AM
all i have to say is... your subs make me feel like a mouse next to a cat....

Well, that's why I share them for everyone to see.  I probably thought through that one for an hour at one point.  No sense making everyone go through that mental exercise.  Plus I'm a nice cat; I only play with the mice and refrain from eating them..
Title: Re: Anyone have a timer sub?
Post by: 12TimesOver on September 28, 2010, 12:11:52 PM
No sense making everyone go through that mental exercise
The mental exercise is my favorite part, even if I'm not good at it ;)

X
Title: Re: Anyone have a timer sub?
Post by: Endless Night on September 28, 2010, 12:46:52 PM
I'll have to use that one EN, since I already have a TM sub in. I want to spread the thanks!

I'm kinda anal when it comes to formatting.  I want it to read: 9:02:04 instead of 9:2:4.  ;)

LOL TM... but actually it would be 365:9:2:4  .. incase your script actually runs for a whole year