[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
#2

Nice, Great work
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);
What if i want to have 2 'AddRandomMessage' with different times?
Reply
#3

Most of the time, random messages are always sent in the same time interval. Maybe I could add a "delay" parameter or something.
Reply
#4

Should add an id to the time interval editing, would make it alot more easier to understand and manage the random messages.
Код:
SetMessageInterval(messageid,time)
EDIT: It is great work though, appreciate this release.
Reply
#5

Quote:
Originally Posted by Emmet_
Посмотреть сообщение
Most of the time, random messages are always sent in the same time interval. Maybe I could add a "delay" parameter or something.
By having that, You can have different Random messages for different players.
Reply
#6

Does this support color embedding within the message?
Reply
#7

Quote:
Originally Posted by Ralfie
Посмотреть сообщение
Does this support color embedding within the message?
Yeah, it should work fine.
Reply
#8

Good job
Reply
#9

Good job emmet
Reply
#10

Very nice
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)