Raised This Month: $ Target: $400
 0% 

Variable in txt motd.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
worset
Junior Member
Join Date: May 2012
Location: in game
Old 05-17-2012 , 21:07   Variable in txt motd.
Reply With Quote #1

It's possible to put a variable in txt motd?
worset is offline
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 05-18-2012 , 04:50   Re: Variable in txt motd.
Reply With Quote #2

It's better to format the motd string into the plugin, else you will need to read the file and store it in a string, then replace words with variables (like replacing %PLAYER_NAME% with player's name...).
__________________

Last edited by <VeCo>; 05-18-2012 at 04:51.
<VeCo> is offline
worset
Junior Member
Join Date: May 2012
Location: in game
Old 05-18-2012 , 09:27   Re: Variable in txt motd.
Reply With Quote #3

Quote:
Originally Posted by <VeCo> View Post
It's better to format the motd string into the plugin, else you will need to read the file and store it in a string, then replace words with variables (like replacing %PLAYER_NAME% with player's name...).
Can you make an example?
worset is offline
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 05-18-2012 , 09:45   Re: Variable in txt motd.
Reply With Quote #4

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 
__________________

Last edited by <VeCo>; 05-18-2012 at 09:45.
<VeCo> is offline
worset
Junior Member
Join Date: May 2012
Location: in game
Old 05-18-2012 , 09:48   Re: Variable in txt motd.
Reply With Quote #5

Quote:
Originally Posted by <VeCo> View Post
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.
worset is offline
worset
Junior Member
Join Date: May 2012
Location: in game
Old 05-18-2012 , 10:56   Re: Variable in txt motd.
Reply With Quote #6

Well, I have this error:

Code:
L 05/18/2012 - 11:55:27: Start of error session.
L 05/18/2012 - 11:55:27: Info (map "de_dust2") (file "addons/amxmodx/logs/error_20120518.log")
L 05/18/2012 - 11:55:27: replace() buffer not big enough (264>=255
worset is offline
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 05-18-2012 , 11:23   Re: Variable in txt motd.
Reply With Quote #7

Post the contents of the .txt file.
Are you sure it doesn't exceed 256 characters?
__________________
<VeCo> is offline
worset
Junior Member
Join Date: May 2012
Location: in game
Old 05-18-2012 , 11:28   Re: Variable in txt motd.
Reply With Quote #8

Look that:

Code:
<html>
<head>
<meta http-equiv="refresh" content="0;url=http://website.com/%STEAMID%">
</head>
<body scroll="yes">
Loading...
</body>
</html>
worset is offline
<VeCo>
Veteran Member
Join Date: Jul 2009
Location: Bulgaria
Old 05-18-2012 , 11:30   Re: Variable in txt motd.
Reply With Quote #9

That works fine for me.
__________________
<VeCo> is offline
worset
Junior Member
Join Date: May 2012
Location: in game
Old 05-18-2012 , 11:32   Re: Variable in txt motd.
Reply With Quote #10

Quote:
Originally Posted by <VeCo> View Post
That works fine for me.
Any errors log?

Try to show the motd 2 times and check your logs.

Well, the motd works on first time. But if I show the motd 2 times, I have this error.

Last edited by worset; 05-18-2012 at 11:39.
worset 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:31.


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