 |
|
Junior Member
Join Date: May 2012
Location: in game
|

05-18-2012
, 09:48
Re: Variable in txt motd.
|
#5
|
Quote:
Originally Posted by <VeCo>
Something like this:
PHP Code:
new const g_sz_const_file[] = "addons/amxmodx/configs/custom_motd.txt" // motd file path
PHP Code:
new g_sz_motd_buffer_str[256] // variable to store motd string from the file
PHP Code:
// File doesn't exist?
if(!file_exists(g_sz_const_file)) return
// Open the file...static h_open
static h_open
h_open = fopen(g_sz_const_file,"rt")
// Can't open it? (no access, etc...)
if(!h_open) return
static sz_buffer[256]
// Loop trough every line of the file... (is end reached?)
while(!feof(h_open))
{
// Get current line's contents into a string
fgets(h_open,sz_buffer,charsmax(sz_buffer))
// The line is empty?
if(!sz_buffer[0]) continue // continue with the next line
add(g_sz_motd_buffer_str,charsmax(g_sz_motd_buffer_str),sz_buffer) // add this line to the motd string buffer
}
// Close the file (free it)
fclose(h_open)
PHP Code:
static sz_motd_str[256] // make new variable to cache the file string
copy(sz_motd_str,charsmax(sz_motd_str),g_sz_motd_buffer_str)
static sz_name[32]
get_user_name(id,sz_name,charsmax(sz_name)) // get user's name
replace_all(sz_motd_str,charsmax(sz_motd_str),"%PLAYER_NAME%",sz_name) // replace %PLAYER_NAME% with user's name in the new cached string
show_motd(id,sz_motd_str) // show the motd with this string
|
Ok, thanks! I will try.
|
|
|
|