Raised This Month: $51 Target: $400
 12% 

Solved need help in optimization [weird coding]


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 01-20-2022 , 09:34   need help in optimization [weird coding]
Reply With Quote #1

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 = -1eNotifyType: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(szOutputcharsmax(szOutput), "[%s] "szPluginName)
    
    if(!
iSender// if id is not passed then show nothing anyway
        
showUserInfo DONT_SHOW
    
    
switch(showUserInfo)
    {
        case 
DONT_SHOW:
        {
            
formatex(szTempcharsmax(szTemp), "")
        }
        case 
ID_ONLY:
        {
            
formatex(szTempcharsmax(szTemp), "(ID: %i) "iSender)
        }
        case 
NAME_ONLY:
        {
            new 
szName[MAX_NAME_LENGTH]
            
get_user_name(iSenderszNamecharsmax(szName))
            
formatex(szTempcharsmax(szTemp), "%s "szName)
        }
        case 
EVERYTHING:
        {
            new 
szName[MAX_NAME_LENGTH]
            
get_user_name(iSenderszNamecharsmax(szName))
            
formatex(szTempcharsmax(szTemp), "%s (ID: %i) "szNameiSender)
        }
    }
    
    
add(szOutputcharsmax(szOutput), szTemp)
    
add(szOutputcharsmax(szOutput), szInput)
    
    new 
players[MAX_PLAYERS], playerCount
    get_players
(playersplayerCount)
    
    switch(
print_destination)
    {
        case 
CHAT_AND_CON:
        {
            new 
player
            
            
for(new iplayerCounti++)
            {
                
player players[i]
                
console_print(player"%s"szOutput)
                
client_print(playerprint_chat"%s"szOutput)
            }
        }
        case 
CHAT_ONLY:
        {
            for(new 
iplayerCounti++)
            {
                
client_print(players[i], print_chat"%s"szOutput)
            }
        }
        case 
CONSOLE_ONLY:
        {
            for(new 
iplayerCounti++)
            {
                
console_print(players[i], "%s"szOutput)
            }
        }
    }

__________________
Now working on: Side Weapons (Very lazy, tbh)
Avatar source: https://bit.ly/3BAk19g
Discord: kww#9951

Last edited by kww; 01-20-2022 at 12:00.
kww is offline
 



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 17:48.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode