AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Help this code right? (https://forums.alliedmods.net/showthread.php?t=242680)

Toallin 06-22-2014 22:28

Help this code right?
 
PHP Code:

public ShowHud(taskid)
{
    new 
id taskid-TASK_HUD
    
    
if(!is_user_alive(id)) return;
        
    new 
iTime[9]
    
get_time("%H:%M"iTimecharsmax(iTime))
    new 
Hora str_to_num(iTime)

        
set_hudmessage(01282550.010.2206.00.9)
    
ShowSyncHudMsg(idHud"Time: %s %s"iTimeHora >= 00 && Hora 12 "AM" "PM")



YamiKaitou 06-22-2014 22:40

Re: Help this code right?
 
Have you tested it yet?

Toallin 06-23-2014 00:11

Re: Help this code right?
 
If I tried I get the PM time but I have not proven if I miss AM wondering why if it was okay if I fix an error.

YamiKaitou 06-23-2014 00:41

Re: Help this code right?
 
iTime does not contain just the hour, it also contains the minutes. str_to_num should only be used when the only thing the string contains only numbers.

To better help you, look at http://www.cplusplus.com/reference/ctime/strftime/ to see what you can format using get_time

Toallin 06-23-2014 20:48

Re: Help this code right?
 
and this would otherwise?

PHP Code:

public ShowHud(taskid

    new 
id taskid-TASK_HUD 
     
    
if(!is_user_alive(id)) return; 
         
    new 
iHours[3], iMinutes[3]
    
get_time("%H"iHourscharsmax(iHours)) 
    
get_time("%M"iMinutescharsmax(iMinutes))
    new 
Hora str_to_num(iTime

        
set_hudmessage(01282550.010.2206.00.9
    
ShowSyncHudMsg(idHud"Time: %s:%s %s"iHoursiMinutesHora >= 00 && Hora 12 "AM" "PM"



fysiks 06-23-2014 22:22

Re: Help this code right?
 
Quote:

Originally Posted by Toallin (Post 2156333)
and this would otherwise?

PHP Code:

public ShowHud(taskid

    new 
id taskid-TASK_HUD 
     
    
if(!is_user_alive(id)) return; 
         
    new 
iHours[3], iMinutes[3]
    
get_time("%H"iHourscharsmax(iHours)) 
    
get_time("%M"iMinutescharsmax(iMinutes))
    new 
Hora str_to_num(iTime

        
set_hudmessage(01282550.010.2206.00.9
    
ShowSyncHudMsg(idHud"Time: %s:%s %s"iHoursiMinutesHora >= 00 && Hora 12 "AM" "PM"



What happens when you test it?

YamiKaitou 06-24-2014 01:11

Re: Help this code right?
 
Code:

get_time("%I:%M %p", iTime, charsmax(iTime))


All times are GMT -4. The time now is 21:09.

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