RandomMessages.inc - Easier random messages! - Emmet_ - 13.10.2014
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
Re: RandomMessages.inc - Easier random messages! -
Rudy_ - 13.10.2014
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?
Re: RandomMessages.inc - Easier random messages! - Emmet_ - 13.10.2014
Most of the time, random messages are always sent in the same time interval. Maybe I could add a "delay" parameter or something.
Re: RandomMessages.inc - Easier random messages! -
Blunt - 13.10.2014
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.
Re: RandomMessages.inc - Easier random messages! -
Rudy_ - 13.10.2014
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.
Re: RandomMessages.inc - Easier random messages! -
Evocator - 13.10.2014
Does this support color embedding within the message?
Re: RandomMessages.inc - Easier random messages! - Emmet_ - 13.10.2014
Quote:
Originally Posted by Ralfie
Does this support color embedding within the message?
|
Yeah, it should work fine.
Re: RandomMessages.inc - Easier random messages! -
IDarkness - 13.10.2014
Good job
Respuesta: RandomMessages.inc - Easier random messages! -
Swedky - 14.10.2014
Good job emmet
Re: RandomMessages.inc - Easier random messages! -
alex10 - 14.10.2014
Very nice