Author Topic: [ADDED] Adding Stopwatch to CITPhone  (Read 2573 times)

Offline Anwar

  • Senior Community Member
  • ****
  • Posts: 47
  • Registered: 07/07/2012
    YearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYears
  • Group: USNS
  • Ingame: CMCO-Anwar#USNS
  • Squad: 404
[ADDED] Adding Stopwatch to CITPhone
« on: 12 06, 2014, 04:20:57 pm »
So, my suggestion is to add stopwatch in CITPhone (B) because we may need it in trainings, sometimes I make specific time to make chemicals in it so I need a stopwatch, and if I will use my mobile, I just waste battery, I am not sure if this was suggested before, but give me your opinions

Community opinion:
This should be helpful as you said, especially for training purposes and other RP things. One thing though, can we have the option to save the  the time period of the stopwatch so we can do comparisons at the end of a training or just to see how quick a car can go around the map etc. via different routes?
Anyway Upvoted as it would be useful.

Show content
Well a simple stopwatch can contain a Reset feature, start feature, stop feature and close feature. If we use setTimer function, its minimum value is 50ms so it is possible in efficient way but if we use onClientPreRender, we can have it in better way like, we can count even 1ms.

I made this:
Code: Lua
  1. local sw, sh = guiGetScreenSize()
  2. main_wnd = guiCreateWindow((sw/5 - 539/5), (sh/5 - 285/5), 214, 220, "CIT - Stopwatch", false)
  3.     guiWindowSetSizable(main_wnd, false)
  4.     guiSetAlpha(main_wnd, 0.92)
  5. watch_lbl = guiCreateLabel(9, 24, 195, 53, "Seconds: \nMinute(s): \nHour(s): \nMilliseconds: ", false, main_wnd)
  6.     guiSetFont(watch_lbl, "default-bold-small")
  7. start_btn = guiCreateButton(9, 79, 195, 33, "Start", false, main_wnd)
  8.     guiSetFont(start_btn, "default-bold-small")
  9. stop_btn = guiCreateButton(9, 112, 195, 33, "Stop", false, main_wnd)
  10.     guiSetFont(stop_btn, "default-bold-small")
  11. reset_btn = guiCreateButton(9, 145, 195, 33, "Reset", false, main_wnd)
  12.     guiSetFont(reset_btn, "default-bold-small")
  13. close_btn = guiCreateButton(9, 178, 195, 33, "Close", false, main_wnd)
  14.     guiSetFont(close_btn, "default-bold-small")
  15.         guiSetProperty(close_btn, "NormalTextColour", "FFFF0000")    
  16. guiSetVisible(main_wnd, false)
  17.  
  18. local milisec = 0
  19. local second = 0
  20. local minute = 0
  21. local hour = 0
  22. local handled = false
  23.  
  24. function startFixing()
  25.         guiSetText(watch_lbl,"Seconds: "..second.."\nMinute(s): "..minute.."\nHour(s): "..hour.."\nMilliseconds: "..milisec)
  26. end
  27. addEventHandler("onClientResourceStart",root, startFixing)
  28.  
  29. addCommandHandler("stopwatch",function()
  30.         guiSetVisible(main_wnd,true)
  31.         showCursor(true)
  32.         guiSetEnabled(reset_btn, false)
  33.         guiSetEnabled(stop_btn, false)
  34. end)
  35.  
  36. function startTimer()
  37.         timing = setTimer(startTime, 50, 0)
  38.         guiSetEnabled(start_btn,false)
  39.         guiSetEnabled(stop_btn,true)
  40.         guiSetEnabled(reset_btn,true)
  41. end
  42. addEventHandler("onClientGUIClick", start_btn, startTimer, false)
  43.  
  44. function stopTimer()
  45.         killTimer(timing)
  46.         guiSetEnabled(stop_btn,false)
  47.         guiSetEnabled(start_btn,true)
  48.         guiSetEnabled(reset_btn,true)
  49. end
  50. addEventHandler("onClientGUIClick", stop_btn, stopTimer, false)
  51.  
  52. function resetTimer()
  53.         if (timing) then killTimer(timing) else return end
  54.         milisec = 0
  55.         second = 0
  56.         minute = 0
  57.         hour = 0
  58.         guiSetText(watch_lbl,"Seconds: "..second.."\nMinute(s): "..minute.."\nHour(s): "..hour.."\nMilliseconds: "..milisec)
  59. end
  60. addEventHandler("onClientGUIClick", reset_btn, resetTimer, false)
  61.  
  62. function closeGui()
  63.         if (timing) then killTimer(timing) else return end
  64.         guiSetVisible(main_wnd,false)
  65.         showCursor(false)
  66.         guiSetEnabled(stop_btn,false)
  67.         guiSetEnabled(start_btn,true)
  68.         guiSetEnabled(reset_btn,true)
  69. end
  70. addEventHandler("onClientGUIClick", close_btn, closeGui, false)
  71.  
  72. function startTime()
  73.         handled=true
  74.         if(milisec==1000)then
  75.                 milisec=0
  76.                 second=second+1
  77.                 if(second==59)then
  78.                         second=0
  79.                         minute=minute+1
  80.                         if(minute==59)then
  81.                                 hour=hour+1
  82.                         end
  83.                 end
  84.         else
  85.                 milisec=milisec+50
  86.         end
  87.         guiSetText(watch_lbl,"Seconds: "..second.."\nMinute(s): "..minute.."\nHour(s): "..hour.."\nMilliseconds: "..milisec)
  88. end
  89.  
  90. addEventHandler("onClientResourceStop",root,function()
  91.         removeEventHandler("onClientPreRender",root,startTime)
  92. end)
  93.  

Unfortunately, its unacceptable by Arran so I thought if someone's gonna make this feature, he might get help by this. Upvoting the suggestion anyways.

This image would be good if this feature gets added in iPhone.
« Last Edit: 14 06, 2014, 01:32:24 pm by Arran »

Offline Egekan

  • eggplant
  • Outstanding Community Member
  • *****
  • Posts: 1479
  • Registered: 31/08/2011
    YearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYears
  • Group: SAPD
  • Ingame: Egekan
Re: Adding Stopwatch to CITPhone
« Reply #1 on: 12 06, 2014, 04:57:23 pm »
Yeah it will be useful for me too. I always use my mobile phone while farming like you so I waste my battery too. As you know there is already a watch in B, stopwatch can be in same things witg it I mean stopwatch can be placed near it.

Offline VazZ

  • The Outrageous
  • Honorable
  • *****
  • Posts: 167
  • Registered: 08/09/2012
    YearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYears
  • Group: ILC
  • Ingame: GOVH-Vazz|ILC|
Re: Adding Stopwatch to CITPhone
« Reply #2 on: 12 06, 2014, 05:01:08 pm »
To stop the desperate use of "phone battery" as the only argument for why this should be added ingame:

http://onlineclock.net/
http://stopwatch.onlineclock.net/
http://countdown.onlineclock.net/

Has in-built alarm sound, so you can use it for farming as well. Just minimize MTA for 4 seconds, not that hard >.<. Anyways, upvoted cause I don't care
Industry and Landwork Company

since 28.10.2013

“In view of the fact that God limited the intelligence of man, it seems unfair that he did not also limit his stupidity.”
- Konrad Adenauer

Are you group leader or founder? Rent GMP now

Offline Egekan

  • eggplant
  • Outstanding Community Member
  • *****
  • Posts: 1479
  • Registered: 31/08/2011
    YearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYears
  • Group: SAPD
  • Ingame: Egekan
Re: Adding Stopwatch to CITPhone
« Reply #3 on: 12 06, 2014, 05:41:21 pm »
To stop the desperate use of "phone battery" as the only argument for why this should be added ingame:

http://onlineclock.net/
http://stopwatch.onlineclock.net/
http://countdown.onlineclock.net/

Has in-built alarm sound, so you can use it for farming as well. Just minimize MTA for 4 seconds, not that hard >.<. Anyways, upvoted cause I don't care


Well there are some people in CIT, if they minimize MTA SA they won't be able to return back to game. My friend has this problem. I am pretty sure there are more people who have this problem. Also it is useful for players. Why there is clock in CIT phone? Is it hard to mnimize MTA and look at the windows clock and return the game? Why there is translator in CIT phone? is it hard to minimize MTA and open a translator? They added becuase they are useful things, stopwatch is useful thing too.

Offline Lynx

  • Regular Community Member
  • ***
  • Posts: 137
  • EX.Overseer of FBI
  • Registered: 28/07/2012
    YearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYears
  • Group: FBI
  • Ingame: OVS-Lynx[FBI]
  • Squad: InternalAffairs
Re: Adding Stopwatch to CITPhone
« Reply #4 on: 13 06, 2014, 02:03:35 pm »
This should be helpful as you said, especially for training purposes and other RP things. One thing though, can we have the option to save the  the time period of the stopwatch so we can do comparisons at the end of a training or just to see how quick a car can go around the map etc. via different routes?
Anyway Upvoted as it would be useful.

•FBI affiliation since 24/8/12 (8.5 years)
•Director (15/8/2013 - 10/2/2014)
•Overseer (10/2/2014 - 29/5/17)
•Honourable (29/5/17 - Present )

Offline Ryan.

  • Honorable
  • *****
  • Posts: 104
  • Skillers™
  • Registered: 28/06/2012
    YearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYears
Re: Adding Stopwatch to CITPhone
« Reply #5 on: 14 06, 2014, 11:14:46 am »
Well a simple stopwatch can contain a Reset feature, start feature, stop feature and close feature. If we use setTimer function, its minimum value is 50ms so it is possible in efficient way but if we use onClientPreRender, we can have it in better way like, we can count even 1ms.
« Last Edit: 14 06, 2014, 01:09:51 pm by Arran »
I am not "Ex." anything, I have proudly served this community as: SK Founder,
 Developer, L3 staff, L2 staff, Supporter, Minister of Fairness, PAM, CB, PC, SO, Senior Community Member and of course, a rule abiding player. Peace.

Offline Arran

  • Administrator
  • ******
  • Posts: 5640
  • Registered: 20/11/2010
    YearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYearsYears
  • Ingame: [CIT]Arran
Re: Adding Stopwatch to CITPhone
« Reply #6 on: 14 06, 2014, 01:27:44 pm »
Well a simple stopwatch can contain a Reset feature, start feature, stop feature and close feature. If we use setTimer function, its minimum value is 50ms so it is possible in efficient way but if we use onClientPreRender, we can have it in better way like, we can count even 1ms.

I told you why you couldn't use onClient/Pre/Render even this timer will suffer a similar problem but not as bad. Your script assumes that they have a good frame rate and therefore everything will trigger at exactly the right time. If someone has a low FPS like 10, the 50ms timers won't execute after 50ms they'd execute twice in one go, every 100ms (10 FPS means screen refreshes every 100ms) hopefully though with the timer system they should still execute meaning that in the long run the time won't actually get desynced from the real time. Your on render system would DEFINITELY have got desynced on a low (or high) FPS.

I had to fix some flaws in your script, bad format, strange GUI position and failure to dereference to timer variable after killing the timer. Other than that though it was easy to add to the server. Oh and you couldn't close the GUI without starting the timer first.
« Last Edit: 14 06, 2014, 01:31:18 pm by Arran »
Proof You Are so Much More Than What You Realise
Authority is not truth. Truth is authority.