Skip to content

rsetiawan7/samp-realtime-clock

Repository files navigation

samp-realtime-clock

sampctl

A library that sync your world time to your hour and minute for all players.

You can control the world time whatever you like with some of short functions.

Installation

Simply install to your project:

sampctl package install rsetiawan7/samp-realtime-clock

Include in your code and begin using the library:

#include <realtime-clock>

Usage

  • Update your server info's worldtime when the time's changed.
public OnWorldTimeUpdate(hour, minute)
{
  // Update the server info's worldtime.
  new
    str[16]
  ;

  format(str, sizeof(str), "worldtime %02d:%02d", hour, minute);
  SendRconCommand(str);
}
  • Change interval of the time update to 1 minute in GTA SA = 30 seconds.
// Set the interval and restart the timer.
RealTime_SetInterval(30000);
  • Sync your current time with server time.
RealTime_Sync(true);

// Called after sync done.
public OnWorldTimeUpdate(hour, minute)
{
  return 1;
}
  • Stop the time change and set the world time to always night.
// Stop the time first.
RealTime_StopTime();

// Then, set the world time to 00:00 and don't start the timer again.
RealTime_SetWorldTime(0, 0, false);
  • Make player's interior brighter if he's in the interior.
public OnPlayerInteriorChange(playerid, newinteriorid, oldinteriorid)
{
  if (newinteriorid != 0)
  {
    // Freeze the player's time.
    RealTime_FreezeForPlayer(playerid);
    // Set player's time to 1:00 PM
    SetPlayerTime(13, 0);
    // Set player's weather to extra sunny.
    SetPlayerWeather(playerid, 0);
  }
  else
  {
    // Freeze the player's time.
    RealTime_UnfreezeForPlayer(playerid);
    // Sync the player's time with current time.
    RealTime_SyncPlayerWorldTime(playerid);
    // Revert back the player's weather to current weather.
    // This part depends on your code.
  }
  return 1;
}

Functions

// Set each of player's world time with current time.
void:RealTime_UpdatePlayerWorldTime();

// Get current hour.
RealTime_GetHour();

// Get current minute.
RealTime_GetMinute();

// Get current interval of time.
RealTime_GetInterval();

// Set current hour to specific hour.
void:RealTime_SetHour(hour, bool:broadcast = true);

// Set current minute to specific minute.
void:RealTime_SetMinute(minute, bool:broadcast = true);

// Stop updating time. (more likely freeze the current time)
void:RealTime_StopTime();

// Start (again if you already stopped before) to updating time.
void:RealTime_StartTime();

// Sync current time with server time.
void:RealTime_Sync(server_time = true);

// Set interval of time changer (in millisecond).
void:RealTime_SetInterval(interval, bool:restart_timer = true);

// Set current time with hour and minute.
void:RealTime_SetWorldTime(hour, minute, bool:restart_timer = true, bool:broadcast = true);

// Sync current player to current time.
RealTime_SyncPlayerWorldTime(playerid);

// Check if the player's time is frozen or not.
RealTime_IsPlayerFreezed(playerid);

// Freeze player's time.
RealTime_FreezeForPlayer(playerid);

// Unfreeze player's time.
RealTime_UnfreezeForPlayer(playerid);

Callbacks

// Called every the time updated.
public OnWorldTimeUpdate(hour, minute)
{
  // Do something here ...
}

You can view example of usage this library on filterscripts/realtime_clock.pwn.

Testing

To test, simply run the package:

sampctl package run

About

A library that you can control your world time to specific hour and minute for all players.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages