qwer85 Posted December 5, 2007 Posted December 5, 2007 (edited) Hello everyone,I need a little help. I'm writing a plugin which retrieves information from Half-Life Dediated Server using UDP. Everything is going well. I've already got names and current frags. But I found a problem to convert time coded into packet as float32 into time format.Here is what I have:Name / Frags / TimeAfer - 8 - 970ABF44 (For example I know that he is playing about 25 minutes)ONIGA - 1 - 492B4F43Pro ATF | dRum - 1 - 353F9444Pylua - 1 - 91C9FC42oLd sCh0oL.> MaJlgeP - 36 - 83439C44maks - 6 - 83599C44PORTER - 19 - 0FAF9844St0p - 27 - 0B4E9C44hiiakimaro - 8 - 32213744Happy - 4 - 94D0D543The time should be like: HH:MM:SSCan anyone help me? Edited December 5, 2007 by qwer85
piccaso Posted December 5, 2007 Posted December 5, 2007 (edited) Thats just how float's look in memory #include <winapi.au3> ; Raw $s = "970ABF44" ; Correct endian $s = StringMid($s,7,2) & StringMid($s,5,2) & StringMid($s,3,2) & StringMid($s,1,2) ; Convert $n = _WinAPI_IntToFloat (Dec($s)) ConsoleWrite($n & @CRLF) i'd assume that the output is in seconds... Edited December 5, 2007 by piccaso CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map
qwer85 Posted December 5, 2007 Author Posted December 5, 2007 (edited) Thanks a lot, but how do i convert seconds into hour:minute:second format?[EDIT]I made foll script and it seems to work:#include <WinAPI.au3> ConsoleWrite(_TimeConversion("970ABF44") & @CRLF) Func _TimeConversion($s_TimeAsFloat32) ;DONT FORGET TO ADD #include <WinAPI.au3> ! ! ! $s_Endian = StringMid($s_TimeAsFloat32,7,2) & StringMid($s_TimeAsFloat32,5,2) & StringMid($s_TimeAsFloat32,3,2) & StringMid($s_TimeAsFloat32,1,2) $f_TimeInSec = _WinAPI_IntToFloat(Dec($s_Endian)) $i_Hours = Int($f_TimeInSec / 3600) $i_Mins = Int(($f_TimeInSec - ($i_Hours * 3600)) / 60) $i_Sec = Int($f_TimeInSec - (($i_Mins * 60) + ($i_Hours * 3600))) Return $i_Hours & ":" & $i_Mins & ":" & $i_Sec EndFunc Edited December 5, 2007 by qwer85
piccaso Posted December 6, 2007 Posted December 6, 2007 You dont have to wrap your mind around date calculations, there are udf's for that too: #include <WinAPI.au3> #include <Date.au3> ConsoleWrite(_TimeConversion("970ABF44") & @CRLF) Func _TimeConversion($s_TimeAsFloat32) ; Using: WinAPI.au3, Date.au3 Local $s_Endian, $n_TimeInSec, $i_Hours, $i_Mins, $i_Sec $s_Endian = StringMid($s_TimeAsFloat32, 7, 2) & StringMid($s_TimeAsFloat32, 5, 2) _ & StringMid($s_TimeAsFloat32, 3, 2) & StringMid($s_TimeAsFloat32, 1, 2) $n_TimeInSec = _WinAPI_IntToFloat (Dec($s_Endian)) _TicksToTime($n_TimeInSec * 1000, $i_Hours, $i_Mins, $i_Sec) Return $i_Hours & ":" & $i_Mins & ":" & $i_Sec EndFunc I know, i'm too late CoProc Multi Process Helper libraryTrashBin.nfshost.com store your AutoIt related files here!AutoIt User Map
qwer85 Posted December 7, 2007 Author Posted December 7, 2007 (edited) My script is a bit faster, but big thank to you anyway Edited December 7, 2007 by qwer85
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now