samp.directory
← Scripts et bibliothèques

rsetiawan7/samp-realtime-clock

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

Bibliothèque★ 4mis à jour sept. 2021OtherPawnsampctl
Ouvrir sur GitHub

Installer avec sampctl

sampctl package install rsetiawan7/samp-realtime-clock

Lance ceci dans le dossier de ton projet. sampctl télécharge le paquet et ce dont il dépend.

L’essayer dans le compilateur Pawn →

Ajoute ses fichiers include, avec les bibliothèques dont il dépend, au compilateur Pawn de ton navigateur, prêts à être inclus dans un script.

Dépend de 1 paquet

Utilisé par 1 paquet

README.md

samp-realtime-clock

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

Cette page est construite à partir de ce que GitHub publie sur le dépôt. samp.directory n’héberge pas le code. Signaler un problème avec cette fiche

rsetiawan7/samp-realtime-clock : Bibliothèque SA-MP | samp.directory