It looks like you should look into studying how to use strings in this language because everything you've done with the string variables in that code is incorrect. One thing that isn't usually mentioned is that you should never return a string from a function in an AMX Mod X plugin. "output" string should be passed as an argument with an accompanying length input (strings are always passed by reference into functions). Take a look at other [working] plugins that use strings that are passed into and out of functions.
For the math part, you can use the following code to get hours, minutes, and seconds. Make sure that you you convert your string (which contains a number of seconds) with str_to_num() so
iSeconds = str_to_num(szMyString).
Quote:
Originally Posted by fysiks
Use the following code for calculating hours, minutes, and seconds:
Code:
iSeconds = 12345 // your time source in seconds
iHours = iSeconds / 3600
iMinutes = iSeconds % 3600 / 60
iSeconds = iSeconds % 60
|
A quick example of how I might do something like this (so you're not just randomly searching around though I still recommend learning the basics of strings):
Code:
new szSeconds[32], szSecondsFormatted[14]
FormatTimeFromSeconds(str_to_num(szSeconds), szSecondsFormatted, charsmax(szSecondsFormatted))
// szSecondsFormatted now contains the formatted time string in the "hh:mm:ss" format
stock FormatTimeFromSeconds(iSeconds, szSecondsFormatted[], len)
{
iHours = iSeconds / 3600
iMinutes = iSeconds % 3600 / 60
iSeconds = iSeconds % 60
format(szSecondsFormatted, len, "%02d:%02d:%02d", iHours, iMinutes, iSeconds)
}
__________________