AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   PlayTime Display (https://forums.alliedmods.net/showthread.php?t=140411)

Stylaa 10-11-2010 19:46

PlayTime Display
 
So i store the Secounds a User was on my Server in a mysql datebase

and if he writes

/playtime

it should display

You already spend 1 Hour 1 Minute and 1 Secound on this Server!

if have a code like this but it doesnt work
( secounds[id] = Secounds the User was on my Server from mysql db )

PHP Code:


public displaytime(id)
{

    new 
hours alltimesecs 3600
        
    
new tmp hours 3600
    
new mins alltimesecs tmp 60
        
    
new tmp2 mins 60
    
new secs alltimesecs tmp tmp2
        
    ColorChat
(idRED"%s Du warst bereits %s Stunden %s Minuten und %s Sekunden auf unserem Server",PREFIXhoursminssecs)




nikhilgupta345 10-11-2010 20:13

Re: PlayTime Display
 
Code:

public displaytime(id)
{

    new hours = (secounds[id] - (secounds[id] % 3600)) / 3600
   
    new temp = hours * 3600

    new mins = hours * 60

    new temp2 = mins * 60
       
    new seconds = secounds[id] - temp - temp2
   
    ColorChat(id, RED, "%s Du warst bereits %i Stunden %i Minuten und %i Sekunden auf unserem Server",PREFIX, hours, mins, seconds)

}

You say secounds[id] holds the current players play time, yet you never use it in that code, you use alltimesecs instead? I put secounds[id] to replace those. If it's really saved in alltimesecs, then go ahead and change them.

Also: You used %s for the integers, while it should've been %i.

%s = string
%i = integer
%f = float


See more here:http://www.cplusplus.com/reference/c...cstdio/printf/

Stylaa 10-11-2010 21:05

Re: PlayTime Display
 
Thanks found my mistake

My Code works now

PHP Code:


public displaytime(id)
{
 
    new 
hours = (secounds[id] - (secounds[id] % 3600)) / 3600
    
new mins = (secounds[id] - (hours*3600)) / 60
    
new seconds = (secounds[id] - (hours*3600) - (mins*60))
    
    
ColorChat(idRED"%s You spend already %i Hours %i Minutes und %i Secounds on our Server",PREFIXhoursminsseconds)




fysiks 10-12-2010 01:21

Re: PlayTime Display
 
Here is a much simpler conversion from seconds to hours minutes seconds:

PHP Code:

    new total secounds[id]
    new 
hours total 3600
    
new minutes total 3600 60
    
new seconds total 60 

Also, here is an example of formating it as HH:MM:SS,

PHP Code:

    server_print("%02d:%02d:%02d"hoursminutesseconds



All times are GMT -4. The time now is 10:18.

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