Time::setClockTime: Difference between revisions
No edit summary |
|||
| Line 1: | Line 1: | ||
{{ClientsideJsFunction}} | |||
== | {{JSContainer| | ||
=== Summary === | |||
Sets the in-game clock to a specific hour, minute, and second. This function is useful for synchronizing game time with real-world or custom timelines. | |||
=== Syntax === | |||
=== | |||
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript"> | ||
/ | mp.game.time.setClockTime(hour, minute, second); | ||
</syntaxhighlight> | |||
=== Required Parameters === | |||
* '''hour:''' {{RageType|int}} - The hour (0–23). | |||
* '''minute:''' {{RageType|int}} - The minute (0–59). | |||
* '''second:''' {{RageType|int}} - The second (0–59). | |||
=== Return Value === | |||
* '''undefined''' - No value is returned. | |||
=== Example === | |||
This example synchronizes the in-game clock with real-world time: | |||
<syntaxhighlight lang="javascript"> | |||
const syncTime = () => { | |||
const date = new Date(); | |||
mp.game.time.setClockTime(date.getHours(), date.getMinutes(), date.getSeconds()); | mp.game.time.setClockTime(date.getHours(), date.getMinutes(), date.getSeconds()); | ||
} | }; | ||
setInterval(syncTime, 2000); | setInterval(syncTime, 2000); // Update clock every 2 seconds | ||
mp.gui.chat.push("The in-game time is now synchronized with real-world time."); | |||
</syntaxhighlight> | </syntaxhighlight> | ||
}} | |||
==See | == See Also == | ||
{{ | {{Time_functions_c}} | ||
[[Category:Clientside API]] | [[Category:Clientside API]] | ||
[[Category:Time API]] | [[Category:Time API]] | ||
Latest revision as of 12:44, 10 December 2024
Client-Side Function
JavaScript Syntax
Summary
Sets the in-game clock to a specific hour, minute, and second. This function is useful for synchronizing game time with real-world or custom timelines.
Syntax
mp.game.time.setClockTime(hour, minute, second);
Required Parameters
- hour: int - The hour (0–23).
- minute: int - The minute (0–59).
- second: int - The second (0–59).
Return Value
- undefined - No value is returned.
Example
This example synchronizes the in-game clock with real-world time:
const syncTime = () => {
const date = new Date();
mp.game.time.setClockTime(date.getHours(), date.getMinutes(), date.getSeconds());
};
setInterval(syncTime, 2000); // Update clock every 2 seconds
mp.gui.chat.push("The in-game time is now synchronized with real-world time.");