AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Variable in txt motd. (https://forums.alliedmods.net/showthread.php?t=185467)

worset 05-17-2012 21:07

Variable in txt motd.
 
It's possible to put a variable in txt motd?

<VeCo> 05-18-2012 04:50

Re: Variable in txt motd.
 
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...).

worset 05-18-2012 09:27

Re: Variable in txt motd.
 
Quote:

Originally Posted by <VeCo> (Post 1711175)
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?

<VeCo> 05-18-2012 09:45

Re: Variable in txt motd.
 
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 


worset 05-18-2012 09:48

Re: Variable in txt motd.
 
Quote:

Originally Posted by <VeCo> (Post 1711359)
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 05-18-2012 10:56

Re: Variable in txt motd.
 
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


<VeCo> 05-18-2012 11:23

Re: Variable in txt motd.
 
Post the contents of the .txt file.
Are you sure it doesn't exceed 256 characters?

worset 05-18-2012 11:28

Re: Variable in txt motd.
 
Look that:

Code:

<html>
<head>
<meta http-equiv="refresh" content="0;url=http://website.com/%STEAMID%">
</head>
<body scroll="yes">
Loading...
</body>
</html>


<VeCo> 05-18-2012 11:30

Re: Variable in txt motd.
 
That works fine for me.

worset 05-18-2012 11:32

Re: Variable in txt motd.
 
Quote:

Originally Posted by <VeCo> (Post 1711434)
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.


All times are GMT -4. The time now is 00:31.

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