[Include] RandomMessages.inc - Easier random messages!
#1

RandomMessages.inc

What is this?
I've seen some poorly optimized random message scripts and I decided to create an include that makes it easier!

Features
  • You can add random messages with ease!
  • Ability to add your own replacement functions.
  • Toggle random messages for specific players.
Here's an example of a random message that is sent every 30 seconds:

pawn Код:
// Set the interval to 30 seconds (30000 ms).
SetMessageInterval(30000);

// Add a random message to the queue.
AddRandomMessage("Make sure you visit our forums for more information!", 0xFFFFFFFF);
Replacements
You can even add your own text replacements!

pawn Код:
Replace->$name(playerid, string[], size) {
    GetPlayerName(playerid, string, MAX_PLAYER_NAME);
}

Replace->$money(playerid, string[], size) {
    format(string, size, "%d", GetPlayerMoney(playerid));
}

AddRandomMessage("Hey there [$name], you currently have [$money]!", 0xFFFFFFFF);
Output:

pawn Код:
Hey there Emmet_Jones, you currently have $50000!
Disable for players
You can also disable random messages from being sent to players:

pawn Код:
SetRandomMessagesForPlayer(playerid, false);
If disabled, random messages will not be automatically sent to the player. This is useful for scripters that wish to show the random message somewhere else, like a textdraw! An example can be seen below.

Callback
This library includes one callback:

pawn Код:
public OnRandomInterval()
{
    return 1;
}
This callback is only called when "SetMessageInterval" is used. It will be called each time the time interval has passed.

This is useful for displaying random messages in textdraws, game text, etc.

pawn Код:
public OnPlayerConnect(playerid)
{
    // This will disable automatic messages from being sent automatically.
    SetRandomMessagesForPlayer(playerid, false);
}

public OnRandomInterval()
{
    // This allows the scripter to show random messages elsewhere.
    // For example, showing the random message in a textdraw!
 
    new
        messageid = GetRandomMessageID(),
        string[128];
 
    for (new i = 0; i < MAX_PLAYERS; i ++)
    {
        if (IsPlayerConnected(i))
        {
            GetRandomMessageOutput(i, messageid, string, sizeof(string));

            // Do something with "string"!
        }
    }
}
If there are no random messages in the queue, this callback will not be called.

Functions
A list of functions for documentation purposes:

pawn Код:
// Add a random message to the queue.
native AddRandomMessage(const message[], color = -1);

// Sets the random message time interval (time = ms).
native SetMessageInterval(time);

// Conditional check to check for valid messages.
native IsValidRandomMessage(messageid);

// Enable or disable random messages for a player.
native SetRandomMessagesForPlayer(playerid, bool:status);

// Returns true if random messages are disabled for the player.
native bool:GetRandomMessagesForPlayer(playerid);

// Returns a random message in the queue (INVALID_MESSAGE_ID if none exist).
native GetRandomMessageID();

// Sends a random message to a player.
native SendRandomMessage(playerid, messageid);

// Generates the output for a random message (useful for textdraw displays, etc).
native GetRandomMessageOutput(playerid, messageid, dest[], size = sizeof(dest));

// Returns the total amount of random messages.
native GetTotalRandomMessages();
Download
http://pastebin.com/zZ16y5Ks
Reply


Messages In This Thread
RandomMessages.inc - Easier random messages! - by Emmet_ - 13.10.2014, 12:19
Re: RandomMessages.inc - Easier random messages! - by Rudy_ - 13.10.2014, 12:54
Re: RandomMessages.inc - Easier random messages! - by Emmet_ - 13.10.2014, 13:00
Re: RandomMessages.inc - Easier random messages! - by Blunt - 13.10.2014, 13:04
Re: RandomMessages.inc - Easier random messages! - by Rudy_ - 13.10.2014, 13:29
Re: RandomMessages.inc - Easier random messages! - by Evocator - 13.10.2014, 17:50
Re: RandomMessages.inc - Easier random messages! - by Emmet_ - 13.10.2014, 18:03
Re: RandomMessages.inc - Easier random messages! - by IDarkness - 13.10.2014, 20:10
Respuesta: RandomMessages.inc - Easier random messages! - by Swedky - 14.10.2014, 18:35
Re: RandomMessages.inc - Easier random messages! - by alex10 - 14.10.2014, 18:42

Forum Jump:


Users browsing this thread: 1 Guest(s)