Raised This Month: $32 Target: $400
 8% 

Help with HudMessage


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Elusive13
Member
Join Date: Sep 2011
Old 05-04-2022 , 11:10   Help with HudMessage
Reply With Quote #1

Hello. I started making a message that reads the text from a separate file. After doing this, I found that the message could not be divided into separate lines in the text file (messages.ini). How do I fix this?
Code:
#include <amxmodx>

public plugin_init() {
	
    register_plugin("Welcome Hud Message", "1.3", "Nobi13")
}

public WelcomeHudMessage(id) {
	
	new file = fopen("addons/amxmodx/configs/messages.ini", "rt");
	new msg[1001]
		set_hudmessage(/* RGB Color set*/0, 80, 255, /*Float:x =*/ -1.0, /*Float:y = */0.18, /* effects =*/ 2, /* Float:fxtime = */ 3.0, /*Float:holdtime = */15.0, /*Float:fadeintime = */0.1, /*Float:fadeouttime = */ 1.5, /*bool:reliable =*/ false )
		fgets(file, msg, charsmax(msg))
		fclose(file)
		show_hudmessage(id,msg)
}
   	
public client_putinserver(id) {
   set_task(10.0, "WelcomeHudMessage",id) //After how many seconds to be showed
  }
Elusive13 is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 05-05-2022 , 08:45   Re: Help with HudMessage
Reply With Quote #2

You must use ^n in text to divide the text into separates link.
Example:
Code:
Welcome to our server!^nType 'm' to choose a team
will display
Code:
Welcome to our server!
Type 'm' to choose a team

Last edited by lexzor; 05-05-2022 at 08:45.
lexzor is offline
Elusive13
Member
Join Date: Sep 2011
Old 05-05-2022 , 12:01   Re: Help with HudMessage
Reply With Quote #3

Quote:
Originally Posted by lexzor View Post
You must use ^n in text to divide the text into separates link.
Example:
Code:
Welcome to our server!^nType 'm' to choose a team
will display
Code:
Welcome to our server!
Type 'm' to choose a team
I want to split messages into the .ini file not in .sma
Elusive13 is offline
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 05-05-2022 , 13:29   Re: Help with HudMessage
Reply With Quote #4

And what will you do with those lines later?

Quote:
Originally Posted by Elusive13 View Post
I want to split messages into the .ini file not in .sma
you put
Quote:
upper text^nlower text
in your config file, then in plugin you open this file, read the line, format it and show to player via show_hudmessage(). Users will see
Quote:
upper text
lower text
What's else?

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

Last edited by kww; 05-05-2022 at 13:44.
kww is offline
Elusive13
Member
Join Date: Sep 2011
Old 05-05-2022 , 15:34   Re: Help with HudMessage
Reply With Quote #5

Quote:
Originally Posted by kww View Post
And what will you do with those lines later?



you put

in your config file, then in plugin you open this file, read the line, format it and show to player via show_hudmessage(). Users will see

What's else?

you can read line by line...
Doesn't work. You can see https://i.imgur.com/cQ1R4DR.png

There is my code
Spoiler
Elusive13 is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 05-05-2022 , 16:27   Re: Help with HudMessage
Reply With Quote #6

Spoiler
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.
Supremache is offline
Elusive13
Member
Join Date: Sep 2011
Old 05-05-2022 , 17:52   Re: Help with HudMessage
Reply With Quote #7

Quote:
Originally Posted by Supremache View Post
Spoiler
Can you explain to me exactly how this works, that is, what exactly you do to make things happen or what to read to learn it.
What is this "i"before "File" var,what mean that g_szMessage or szFile

Last edited by Elusive13; 05-05-2022 at 18:13.
Elusive13 is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 05-05-2022 , 18:41   Re: Help with HudMessage
Reply With Quote #8

"i" before "File" represent a prefix before the name of the variable. you can declare variable names how you want, but using that prefixes would help you to code faster

integer -> new iFile
string -> new szFile[64]
float -> new Float:fFile
boolean -> new bool:bFile

global integer variable -> g_iFile
and so on

probably supremache didn t paid enough attention or he just copied the code from another plugin, but the g_szFile[128] should be szFile[128] because it s not a global variable and it is a string where the file path is stored.

PHP Code:
new iFile fopeng_szFile"rt" ); 
here, native fopen return file pointer (it s like a identifier for the specified file, if you want to see what fopen parameters do, you can read here: https://www.amxmodx.org/api/file/fopen)

the g_szMessage is a global variable where the message is stored after the plugin read it from the file. as you can see, he declared the variable above the plugin_init and because is not declared in a function the variable is global

Last edited by lexzor; 05-05-2022 at 18:43.
lexzor is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 05-05-2022 , 18:45   Re: Help with HudMessage
Reply With Quote #9

Quote:
Originally Posted by Elusive13 View Post
Can you explain to me exactly how this works, that is, what exactly you do to make things happen or what to read to learn it.
What is this "i"before "File" var,what mean that g_szMessage or szFile
PHP Code:
#include <amxmodx>
#include <amxmisc>

#if !defined MAX_FMT_LENGTH
    
const MAX_FMT_LENGTH 192 // Max Message length
#endif

new g_szMessageMAX_FMT_LENGTH ]; // String variable to store the message from the file

public plugin_init( ) 
{
    
register_plugin"Welcome Message""1.0""Supremache" )
    
    
ReadWelcomeMessageFile( ); // Read the file
}

public 
client_putinserverid )
{
    
set_task10.0"OnConnectMessage"id ); // Display the message when the client connects to the server
}

public 
OnConnectMessageid )
{
    
set_hudmessage080255,  -1.00.1823.015.00.11.5false )
    
show_hudmessageidg_szMessage // Put the message that was stored from the file
}

ReadWelcomeMessageFile( )
{
    new 
g_szFile128 ]; // Create a variable to store the location of the file
    
get_configsdirg_szFilecharsmaxg_szFile ) ) //  the location of the confing folder
    
addg_szFilecharsmaxg_szFile ), "/WelcomeMessages.ini" // add the file name
    
    
new iFile fopeng_szFile"rt" ); // Open the file
    
    
if( iFile // If the file exist
    
{
        new 
szDataMAX_FMT_LENGTH ]; // Create variable to store the data from the file
        
        
while( fgetsiFileszDatacharsmaxszData ) ) ) // Get the date from the file
        
{   
            
trimszData ); // remove space
            
            
switch( szData] )
            {
                case 
EOS';''#''/': continue; // Block these symbols
                
                
default:
                {
                    
copyg_szMessagecharsmaxg_szMessage ), szData // store the message from the file
                    
replace_allg_szMessagecharsmaxg_szMessage ), "!n""^n" // Replace field !n to ^n if you want to add line
                
}
            }
        }
        
fcloseiFile ); // Close the file
    
}

__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.

Last edited by Supremache; 05-05-2022 at 18:46.
Supremache is offline
Elusive13
Member
Join Date: Sep 2011
Old 05-06-2022 , 14:18   Re: Help with HudMessage
Reply With Quote #10

Quote:
Originally Posted by lexzor View Post
"i" before "File" represent a prefix before the name of the variable. you can declare variable names how you want, but using that prefixes would help you to code faster

integer -> new iFile
string -> new szFile[64]
float -> new Float:fFile
boolean -> new bool:bFile

global integer variable -> g_iFile
and so on

here, native fopen return file pointer (it s like a identifier for the specified file, if you want to see what fopen parameters do, you can read here: https://www.amxmodx.org/api/file/fopen)

the g_szMessage is a global variable where the message is stored after the plugin read it from the file. as you can see, he declared the variable above the plugin_init and because is not declared in a function the variable is global
Do I understand that all variables that are not in function are global? I can use these prefixes in variables and they don't depend directly on libraries, right?

And one question about the plugin, specifically about the code. Do I have to declare so many functions and variables to be able to use the functions of the .sma file in the config file, as in this case I replace the newline function (^n) with (!n) or whatever I decide except the characters that are forbidden?
Can i just do this
PHP Code:
 replace_all (g_szMessagecharsmax (g_szMessage), "!n""^n"
without doing the whole check?
Elusive13 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 08:20.


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