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

New line for each command used


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
N3v3rM1nd
Junior Member
Join Date: Apr 2021
Old 07-10-2021 , 13:20   New line for each command used
Reply With Quote #1

Hi, i have this code block
PHP Code:
public plugin_init() register_clcmd("say""cmd_hud_say")

..

public 
cmd_hud_say(id)
{
    new 
szArg[6], szText[192]
    
read_argv(1szArgcharsmax(szArg))
    
read_args(szTextcharsmax(szText))
    
remove_quotes(szText)

    
get_user_name(idg_player_data[id][szAdminName], charsmax(g_player_data[][szAdminName]))

    if(
function_get_flags(id) & ADMIN_ACCESS_CHAT || function_get_flags(id) & ROOT_ACCESS)
    {
        if(
szArg[0] == '@')
        {
            
set_hudmessage(1441441440.050.506.06.00.50.15, -1)
            
show_hudmessage(0"%s: %s"g_player_data[id][szAdminName], szText
        }
        
    }
    else
    {
        
client_print_color(idid"%s No acces."TAG)
        
console_print(id"%s No acces."TAG)
        return 
PLUGIN_HANDLED
    
}
    return 
PLUGIN_HANDLED

what can i do for every time someone use the command, the hud message to be shown on a new line?

Last edited by N3v3rM1nd; 07-10-2021 at 13:21.
N3v3rM1nd is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 07-10-2021 , 13:43   Re: New line for each command used
Reply With Quote #2

PHP Code:

public cmd_hud_say(id)
{
    new 
szArg[6], szText[192]
    
read_argv(1szArgcharsmax(szArg))
    
read_args(szTextcharsmax(szText))
    
remove_quotes(szText)

    
get_user_name(idg_player_data[id][szAdminName], charsmax(g_player_data[][szAdminName]))

    if(
function_get_flags(id) & ADMIN_ACCESS_CHAT || function_get_flags(id) & ROOT_ACCESS)
    {
        if(
szArg[0] == '@')
        {
            const  
MAX_LINES_SHIFTING 4;
            static 
iLine 0;
            new 
szTag[MAX_LINES_SHIFTING];
            
            if(
iLine )
            {
                for(new 
i=0iLinei++) szTag[i] = '^n';
            }
            
            
iLine = ++iLine MAX_LINES_SHIFTING;
            
set_hudmessage(1441441440.050.506.06.00.50.15, -1);
            
show_hudmessage(0"%s%s: %s"szTagg_player_data[id][szAdminName], szText);
        }
        
    }
    else
    {
        
client_print_color(idid"%s No acces."TAG)
        
console_print(id"%s No acces."TAG)
        return 
PLUGIN_HANDLED
    
}
    return 
PLUGIN_HANDLED 
here you go static variables in functions are very useful.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
N3v3rM1nd
Junior Member
Join Date: Apr 2021
Old 07-10-2021 , 13:50   Re: New line for each command used
Reply With Quote #3

Quote:
Originally Posted by Natsheh View Post
PHP Code:

public cmd_hud_say(id)
{
    new 
szArg[6], szText[192]
    
read_argv(1szArgcharsmax(szArg))
    
read_args(szTextcharsmax(szText))
    
remove_quotes(szText)

    
get_user_name(idg_player_data[id][szAdminName], charsmax(g_player_data[][szAdminName]))

    if(
function_get_flags(id) & ADMIN_ACCESS_CHAT || function_get_flags(id) & ROOT_ACCESS)
    {
        if(
szArg[0] == '@')
        {
            const  
MAX_LINES_SHIFTING 4;
            static 
iLine 0;
            new 
szTag[MAX_LINES_SHIFTING];
            
            if(
iLine )
            {
                for(new 
i=0iLinei++) szTag[i] = '^n';
            }
            
            
iLine = ++iLine MAX_LINES_SHIFTING;
            
set_hudmessage(1441441440.050.506.06.00.50.15, -1);
            
show_hudmessage(0"%s%s: %s"szTagg_player_data[id][szAdminName], szText);
        }
        
    }
    else
    {
        
client_print_color(idid"%s No acces."TAG)
        
console_print(id"%s No acces."TAG)
        return 
PLUGIN_HANDLED
    
}
    return 
PLUGIN_HANDLED 
here you go static variables in functions are very useful.
Is working like a charm, but how can i get rid of "@", is kinda annoying
PHP Code:
public cmd_hud_say(id)
{
    new 
szArg[6], szText[192]
    
read_argv(1szArgcharsmax(szArg))
    
read_args(szTextcharsmax(szText))
    
remove_quotes(szText)

    
get_user_name(idg_player_data[id][szAdminName], charsmax(g_player_data[][szAdminName]))

    if(
function_get_flags(id) & ADMIN_ACCESS_CHAT || function_get_flags(id) & ROOT_ACCESS)
    {
        if(
szArg[0] == '@')
        {
            const 
MAX_LINES_SHIFTING 4;
            static 
iLine 0;
            new 
szTag[MAX_LINES_SHIFTING];
            
            if(
iLine )
            {
                for(new 
i=0iLinei++) szTag[i] = '^n';
            }
            
            
iLine = ++iLine MAX_LINES_SHIFTING;
            
set_hudmessage(1441441440.050.506.06.00.50.15, -1);
            
show_hudmessage(0"%s^n%s: %s"szTagg_player_data[id][szAdminName], szText);
        }
        else return 
PLUGIN_CONTINUE
        
    
}
    else
    {
        
client_print_color(idid"%s No acces."TAG)
        
console_print(id"%s No acces."TAG)
        return 
PLUGIN_HANDLED
    
}
    return 
PLUGIN_HANDLED


Last edited by N3v3rM1nd; 07-10-2021 at 14:00.
N3v3rM1nd is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 07-10-2021 , 14:00   Re: New line for each command used
Reply With Quote #4

well it depended on your if logic there here you go fixed.


PHP Code:

public cmd_hud_say(id)
{
    new 
szArg[6];
    
read_argv(1szArgcharsmax(szArg));

    if(
szArg[0] != '@') return PLUGIN_CONTINUE;
    
    if(
function_get_flags(id) & ADMIN_ACCESS_CHAT || function_get_flags(id) & ROOT_ACCESS)
    {
        new 
szText[192];
        
read_args(szTextcharsmax(szText))
        
remove_quotes(szText)
    
        const  
MAX_LINES_SHIFTING 4;
        static 
iLine 0;
        new 
szTag[MAX_LINES_SHIFTING];
        
        if(
iLine )
        {
            for(new 
i=0iLinei++) szTag[i] = '^n';
        }
        
        
get_user_name(idg_player_data[id][szAdminName], charsmax(g_player_data[][szAdminName]))
        
iLine = ++iLine MAX_LINES_SHIFTING;
        
set_hudmessage(1441441440.050.506.06.00.50.15, -1);
        
show_hudmessage(0"%s%s: %s"szTagg_player_data[id][szAdminName], szText[1]);
        return 
PLUGIN_HANDLED;
    }
    
    
client_print_color(idid"%s No acces."TAG);
    
console_print(id"%s No acces."TAG);
    return 
PLUGIN_HANDLED;

__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 07-10-2021 at 14:20.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 07-10-2021 , 14:04   Re: New line for each command used
Reply With Quote #5

For another example of how to write subsequent HUD messages on a different line can be found with the built-in AMX Mod X command amx_tsay which can be found here (where 'tsay' is true).

When registering "say", read_args() and readargv(1, ...) will result in the same text string (because there is only 1 argument for the "say" command with the exception of the quotes on the string provided by read_args(). So, after removing the quotes, they are the same.

To print a string without the first X number of characters, you can reference the string variable as myStringVariable[X]. In this case, it will be szTest[1] in the show_hudmessage() function.
__________________

Last edited by fysiks; 07-10-2021 at 14:20.
fysiks is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 07-10-2021 , 14:22   Re: New line for each command used
Reply With Quote #6

Quote:
Originally Posted by fysiks View Post
When registering "say", read_args() and readargv(1, ...) will result in the same text string (because there is only 1 argument for the "say" command with the exception of the quotes on the string provided by read_args(). So, after removing the quotes, they are the same.
oh yeah i forgot about that for some reason i thought it had more than 1 argument.

code edited removed the @ sign from the message.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 07-10-2021 at 14:34.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
N3v3rM1nd
Junior Member
Join Date: Apr 2021
Old 07-10-2021 , 14:49   Re: New line for each command used
Reply With Quote #7

Thx both, is working perfectly
N3v3rM1nd is offline
Reply



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 00:37.


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