Can we optimize it? I think I can reduce the code size but unsure. After almost the year of sleeping I forgot most of the amxx scripting
PHP Code:
// enums could be renamed later (because of my weird fantasy)
enum _:eNotifyType {
DONT_SHOW = 0,
ID_ONLY = 1,
NAME_ONLY = 2,
EVERYTHING = 3,
}
enum _:ePrintDestination {
CHAT_AND_CON = 0,
CHAT_ONLY = 1,
CONSOLE_ONLY = 2,
}
/**
* Shows specified text
*
* @param szInput Text message to show
* @param iSender Function executor's ID
* @param showUserInfo What info about executor should be shown
* @param szPluginName Plugin name (leave blank but then this stock will be useless) // it is useless anyway :)
* @param print_destination Where to show this message
*
* @noreturn
*/
stock __notify_everyone(const szInput[] /* 192 max? */, iSender = -1, eNotifyType:showUserInfo, const szPluginName[], ePrintDestination:print_destination)
{
new szOutput[256], szTemp[MAX_NAME_LENGTH]
if(!szInput[0])
{
log_amx("Warning! There's nothing to send to players")
return PLUGIN_HANDLED
}
if(szPluginName[0])
formatex(szOutput, charsmax(szOutput), "[%s] ", szPluginName)
if(!iSender) // if id is not passed then show nothing anyway
showUserInfo = DONT_SHOW
switch(showUserInfo)
{
case DONT_SHOW:
{
formatex(szTemp, charsmax(szTemp), "")
}
case ID_ONLY:
{
formatex(szTemp, charsmax(szTemp), "(ID: %i) ", iSender)
}
case NAME_ONLY:
{
new szName[MAX_NAME_LENGTH]
get_user_name(iSender, szName, charsmax(szName))
formatex(szTemp, charsmax(szTemp), "%s ", szName)
}
case EVERYTHING:
{
new szName[MAX_NAME_LENGTH]
get_user_name(iSender, szName, charsmax(szName))
formatex(szTemp, charsmax(szTemp), "%s (ID: %i) ", szName, iSender)
}
}
add(szOutput, charsmax(szOutput), szTemp)
add(szOutput, charsmax(szOutput), szInput)
new players[MAX_PLAYERS], playerCount
get_players(players, playerCount)
switch(print_destination)
{
case CHAT_AND_CON:
{
new player
for(new i; i < playerCount; i++)
{
player = players[i]
console_print(player, "%s", szOutput)
client_print(player, print_chat, "%s", szOutput)
}
}
case CHAT_ONLY:
{
for(new i; i < playerCount; i++)
{
client_print(players[i], print_chat, "%s", szOutput)
}
}
case CONSOLE_ONLY:
{
for(new i; i < playerCount; i++)
{
console_print(players[i], "%s", szOutput)
}
}
}
}
__________________