• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Plugin] SmartEvents - a plugin for timed events
#1
SmartEvents
SA-MP/OMP plugin for managing timed player events: Mute, Jail, VIP, etc.

How it works
When creating an event you need to specify:
  • Event name
  • Callback - called once when the time expires. If the remaining time is more than 24 hours, the callback isn't added to the queue until the next server restart, which optimizes performance.
  • Time type - there are two types:
    • false - offline: time counts down even when the player isn't on the server. Saved once when the event is assigned.
    • true - online: time counts down only while the player is on the server. Saved when assigned and every time the player disconnects.
Crash protection
Even for online events, data loss on crash isn't a problem.
When an event is assigned, the necessary data is written to a temporary table, and it's removed when the player disconnects.
If the server crashes, the data stays there.
On restart the plugin checks the temporary table, calculates the difference between the saved time and the current startup time, and updates the main table.

Requirements
  • Automatic server restart once a day (present on all decent servers)
  • An auto-restart-on-crash script (present by default on all hosting providers; set up manually on a VPS)

Data storage
All data is stored in an SQLite database at scriptfiles/SmartEvents.db.

Integration
Call two functions in your gamemode - one after login, another after registration:

Code:
public OnPlayerLogin(playerid)
{
    // Your account loading
    cache_get_value_name_int(0, "ID", PlayerInfo[playerid][pID]);

    SE_OnPlayerLogin(playerid, PlayerInfo[playerid][pID]);
}

public OnPlayerSignIn(playerid)
{
    // When the player has registered
    PlayerInfo[playerid][pID] = cache_insert_id();
    SE_OnPlayerSignIn(playerid, PlayerInfo[playerid][pID]);
}

Usage example
Code:
new SE:gPlayerMute;
new SE:gPlayerJail;

public OnGameModeInit()
{
    SE_SetLanguage("en");
    gPlayerMute = SE_AddEvent("mute", "OnMuteExpired", true); // online - in-game time only
    gPlayerJail = SE_AddEvent("jail", "OnJailExpired", true); // online - in-game time only
}

CMD:mute(playerid, params[])
{
    SE_SetPlayerEvent(targetid, gPlayerMute, SE_MinutesToSeconds(30));
    SendClientMessage(targetid, -1, "You have been muted for 30 minutes");
}

CMD:unmute(playerid, params[])
{
    SE_RemovePlayerEvent(targetid, gPlayerMute);
    SendClientMessage(targetid, -1, "Your mute has been removed");
}

CMD:jail(playerid, params[])
{
    SE_SetPlayerEvent(targetid, gPlayerJail, SE_HoursToSeconds(1));
    SendClientMessage(targetid, -1, "You have been jailed for 1 hour");
}

public OnPlayerText(playerid, text[])
{
    if (SE_IsPlayerEventActive(playerid, gPlayerMute))
    {
        SendClientMessage(playerid, -1, "You are muted");
        return 0;
    }
    return 1;
}

public OnPlayerSpawn(playerid)
{
    if (SE_IsPlayerEventActive(playerid, gPlayerJail))
    {
        SetPlayerPos(playerid, x, y, z);
    }
    return 1;
}

SE_Event:OnMuteExpired(playerid)
{
    SendClientMessage(playerid, -1, "Your mute has expired");
}

SE_Event:OnJailExpired(playerid)
{
    SetPlayerPos(playerid, x, y, z);
    SendClientMessage(playerid, -1, "Your jail time has expired");
}

Why is this better than subtracting and saving every second?

DB queries: Tick & Save - every second per player / SmartEvents - on assignment + on disconnect
Callback calls: Tick & Save - every second / SmartEvents - once, on expiration

Benchmark
100 players with a 5-hour mute and 15 reconnects per player (reconnect for the plugin only).
[Image: Benchmark.png]


Documentation >> https://github.com/i-Saibot/SmartEvents/wiki
Release >> https://github.com/i-Saibot/SmartEvents/releases
  Reply


Messages In This Thread
SmartEvents - a plugin for timed events - by email.d.value - 2 hours ago

Forum Jump: