Raised This Month: $51 Target: $400
 12% 

ConvertFloatToSeconds Stock (Useful for Songs)


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 11-22-2017 , 11:06   ConvertFloatToSeconds Stock (Useful for Songs)
Reply With Quote #1

Today, I was making a Song Player and my array of Songs had a dimension just for the music length, most of people don't know the exact length of a song in seconds so they write it in a 'float' form (Example 3:15), the way YouTube displays it. So I was in need of a stock that would Convert that 'float' length to seconds but couldn't find any, that's why I'm posting this stock here so other's can find what they need.

3:15

3 = Number of minutes.
15 = Number of seconds.

Stock:

PHP Code:
ConvertFloatToSeconds( const Float:fTime )
{
    new 
iSecondsiMinutesszExtraSeconds], iExtraSecondsszString];

    
float_to_strfTimeszStringcharsmaxszString ) );

    
szExtraSeconds] = szString];
    
addszExtraSecondscharsmaxszExtraSeconds ), szString] );

    
iExtraSeconds str_to_numszString] );

    
iMinutes floatroundfTimefloatround_floor );

    
iSeconds iMinutes 60;

    return 
iSeconds += iExtraSeconds;

The reason I needed this stock was that to make the song more relaxable by lowering the volume of the game sounds when the music started and letting the player feel the music. So I needed this stock to create a task to be executed when music would end and increase the game volume of the player again.

Usage of the stock:

PHP Code:
#define MUSIC_LENGTH 3.15

set_taskfloatConvertFloatToSecondsMUSIC_LENGTH ), "OnTaskEndSong"id_) ); 
Test Logs:
Code:
L 11/22/2017 - 16:52:21: [DEBUG] Old Float Value: 3.14 | New Converted Value: 194 L 11/22/2017 - 16:52:21: [DEBUG] Old Float Value: 0.26 | New Converted Value: 26 L 11/22/2017 - 16:52:21: [DEBUG] Old Float Value: 3.06 | New Converted Value: 186
__________________

Last edited by edon1337; 12-26-2017 at 06:30.
edon1337 is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:01.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode