CMD:ann(playerid, params[]) { new text[128], ann_b[][] = {"~f~", "~k~", "~o~"}; if(sscanf(params, "s[128]", text)) { SendClientMessage(playerid, -1, "Usage: /ann [text]"); return 1; } for(new i, find; i < sizeof(ann_b); i++) { if((find = strfind(text, ann_b[i], true), find) != -1) { SendClientMessage(playerid, -1, "Wrong!"); return 1; } } GameTextForAll(text, 10000, 4); return 1; }
CMD:announce(playerid, params[], help) { #pragma unused help if(PlayerInfo[playerid][pAdmin] < 2) return SCM(playerid, COLOR_RED, "You need to be admin level 2 to use this!"); new string[128],style; if(sscanf(params, "s[128]i",string,style)) return SCM(playerid, COLOR_RED, "Usage: /announce [Text] [Text Style 0-6]"); GameTextForAll(string,4000,style); return 1; } |
Be careful, using too many text colors or special characters in one gametext may crash every player the gametext is shown to. Additionally, avoid using an uneven usage of the ~ character. Example: ~~r~Hello, ~g~how are ~y~~you?~ |
CMD:ann(playerid, params[])
{
if(isnull(params)) // If the player did not enter parameters...
return SendClientMessage(playerid, -1, "Usage: /ann [text]"); // Send the player a usage message.
if(strfind(params, "~k~", true) != -1) // If we find a forbidden string in our text...
return SendClientMessage(playerid, -1, "Wrong!"); // Send the player an error message.
new count = 0; // Store the count of tildes (~) in this variable.
for(new i = 0, j = strlen(params); i < j; i++) // Loop through the string to count all the tildes (~).
{
if(params[i] == '~') // If the character is a tilde...
count++; // Add 1 to our count.
}
if((count % 2) != 0) // If the number of tildes in our message is odd...
return SendClientMessage(playerid, -1, "Odd number of tildes!"); // Send an error message to the player.
GameTextForAll(params, 10000, 4); // Send the game text to all players.
return 1;
}