• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[General] List of timestamps, minimum and maximum time per player problem

Status
Not open for further replies.
Can someone help me solve a problem in wc3 scripting?
I want to put a timestamp in a timestamp list [for each player] and then pick the maximum and minimum time and display in a multiboard rows (the maximum and the minimum time of each player)

' When a hero carries an item or is inside an area he is being watched how much time he does that before an enemy hero kills him. So each timestamp is put inside a timestamp list or whatever and we get teh maximum and and the minimum time the owner of the hero did that, then we display in in the multiboard. '

Any ideas how to do this is minimum coding/Triggers?
 
Last edited:
Level 39
Joined
Feb 27, 2007
Messages
5,016
Start a timer on map init with a very long duration. Use Timer - Elapsed Time as a time stamp whenever a unit picks up or drops the item (or enters/leaves the area). Save the pick up time and total time held in two arrays indexed by player number. When a unit drops the item or leaves, subtract the start time from the current time and add it to the total time.
 
maybe i'm thinking of making the time in seconds.
and maybe this is a solution:
Code:
________________________________
(trigger)(event for drop) :
drops++ (loop's cap = drops)
timestamps_array[drops] = curent_time
for A from 1 to (drops - 1): // -1 because I compare two values
   set Current_Min = min(A,A+1)
// this filters the minimum time, 2 by 2 on each iteration
set for multiboard in column 10 row (player number) text Current_Min
set current_time[] = 0
(same for max)
________________________________
(trigger)each second:
if hero has item:
  current_time[]++
________________________________
 
Last edited:
Level 39
Joined
Feb 27, 2007
Messages
5,016
I'm not sure I fully comprehend your method but it sounds like it would work. The way you search for a min is not efficient. Just save the current lowest in a temp variable (and the index it corresponds to) then compare vs that number:
  • Set LowVal = timestamps_array[1]
  • Set LowIndex = 1
  • For each (Integer A) from 1 to drops do (Actions)
    • Loop - Actions
      • If (All conditions are true) then do (then actions) else do (else actions)
        • If - Conditions
          • timestamps_array[(Integer A)] less than LowVal
        • Then - Actions
          • Set LowVal = timestamps_array[(Integer A)]
          • Set LowIndex = (Integer A)
        • Else - Actions
  • -------- now LowVal is always the lowest value in the array --------
There's also this GameClock library I wrote 10 years ago:
JASS:
library GameClock initializer Init
   //============================================================================================
   // GameClock library (Version 1.02)
   //   by Pyrogasm (4/14/09)
   //
   // - The purpose of this library is to give a standardized platform for tracking
   //   the current duration of a game using a global timer and TimerGetElapsed().
   //
   // - The output can either be a real number (with which you may do whatever you
   //   want), or a string in the format HH:MM:SS.
   //
   // - The boolean "Exact" determines if the output should be the full elapsed time,
   //   or if it should be truncated, showing the time as a clock would.
   //
   // - If you know that you will only ever use exact or truncated values, you can
   //   shorten GetElapsedGameTime into one line to make it inline-friendly and save
   //   yourself a few nanoseconds of code execution.
   //
   // - Version 1.00: Release
   // - Version 1.01: Removed some documentation, removed unnecessary loops, altered
   //                 GAME_LENGTH
   // - Version 1.02: Inlined CreateTimer() call, removed example library
   //============================================================================================

   globals
       private constant real GAME_LENGTH = 36000.00 //10 hours
       private constant real GAME_SPEED = 1.00 //Might be changed if game speed is altered with UI files

       //The point of no return
       private timer Clock = CreateTimer()
   endglobals

   function GetElapsedGameTime takes boolean Exact returns real
       local real E = TimerGetElapsed(Clock)*GAME_SPEED

       if not Exact then
           set E = R2I(E)
       endif

       return E
   endfunction

   function GetElapsedGameTimeString takes boolean Exact returns string
       local real E = TimerGetElapsed(Clock)*GAME_SPEED
       local integer H = 0
       local integer M = 0
       local string S
       
       set H = R2I(E/3600.00)
       set E = E-3600.00*H

       set M = R2I(E/60.00)
       set E = E-60.00*M


       if H < 10 then
           set S = "0" + I2S(H) + ":"
       else
           set S = I2S(H) + ":"
       endif

       if M < 10 then
           set S = S + "0" + I2S(M) + ":"
       else
           set S = I2S(M) + ":"
       endif

       if E < 10 then
           set S = S + "0"
       endif

       if Exact then
           set S = S + R2S(E)
       else
           set S = S + I2S(R2I(E))
       endif


       return S
   endfunction


   private function Init takes nothing returns nothing
       call TimerStart(Clock, GAME_LENGTH, false, null)
   endfunction
endlibrary
 
Status
Not open for further replies.
Top