Raised This Month: $ Target: $400
 0% 

Print contents from a text file into client's console


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
spiderbites
Senior Member
Join Date: Nov 2007
Old 04-15-2008 , 00:41   Print contents from a text file into client's console
Reply With Quote #1

who can code this? i need it for motd replacement.

when a player join a server, pop up his console and print contents from a text file into his console.
spiderbites is offline
Sn!ff3r
Veteran Member
Join Date: Aug 2007
Location: Poland
Old 04-15-2008 , 12:01   Re: Print contents from a text file into client's console
Reply With Quote #2

Hmm, try this

PHP Code:
#include <amxmodx>

#define MOTD_FLAG_ARG 1
#define MOTD_FLAG_END 1

new bool:g_bSawMotd[33];
new 
file[] = "cmotd.txt"

public plugin_init()
{
    
register_plugin("Console MOTD""0.1""Exolent & Sn!ff3r");
    
register_message(get_user_msgid("MOTD"), "message_MOTD");
}

public 
client_connect(id)
{
    
g_bSawMotd[id] = false
    set_task
(10.0,"show_message",id)
}

public 
show_message(id)
{
    new 
File fopen(file"rt")
    
    static 
Buffer[128]
    
    while(!
feof(File))
    {
        
fgets(FileBuffersizeof Buffer 1)
        
client_print(id,print_console,"%s",Buffer)
    }
    
    
client_cmd(id,"toggleconsole")
    
fclose(File)    
}

public 
message_MOTD(msgiddestid)
{
    if(!
g_bSawMotd[id])
    {
        if(
get_msg_arg_int(MOTD_FLAG_ARG) == MOTD_FLAG_END)
        {
            
g_bSawMotd[id] = true
        
}
        return 
PLUGIN_HANDLED
    
}
    return 
PLUGIN_CONTINUE;

Sn!ff3r is offline
Send a message via Skype™ to Sn!ff3r
spiderbites
Senior Member
Join Date: Nov 2007
Old 04-15-2008 , 20:13   Re: Print contents from a text file into client's console
Reply With Quote #3

so cmotd.txt goes in amxmodx\config folder, right? the console popped up but messages from cmotd.txt was not displayed.
spiderbites is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 04-15-2008 , 20:14   Re: Print contents from a text file into client's console
Reply With Quote #4

No, the way the script is, the file should be in the cstrike folder
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
spiderbites
Senior Member
Join Date: Nov 2007
Old 04-15-2008 , 20:27   Re: Print contents from a text file into client's console
Reply With Quote #5

thanks for correcting me yami.


@Sn!ff3r
i got it to work now. but the messages spacing arent exactly like they are in the file. messages in the text file contain single spacing but they are displayed with double spacing in the console. can it be made so it prints exactly like in the file?
spiderbites is offline
atomen
Veteran Member
Join Date: Oct 2006
Location: Stockholm, Sweden
Old 04-16-2008 , 08:27   Re: Print contents from a text file into client's console
Reply With Quote #6

Using html ?
__________________
atomen is offline
Send a message via MSN to atomen
spiderbites
Senior Member
Join Date: Nov 2007
Old 04-16-2008 , 09:33   Re: Print contents from a text file into client's console
Reply With Quote #7

nope..plain text
spiderbites is offline
Sn!ff3r
Veteran Member
Join Date: Aug 2007
Location: Poland
Old 04-16-2008 , 09:40   Re: Print contents from a text file into client's console
Reply With Quote #8

Quote:
Using html ?
Ehh... you can't use html in this plugin...

@spiderbites, try this [work fine for me]
PHP Code:
#include <amxmodx>

#define MOTD_FLAG_ARG 1
#define MOTD_FLAG_END 1

new bool:g_bSawMotd[33];
new 
file[] = "cmotd.txt"

public plugin_init()
{
    
register_plugin("Console MOTD""0.1""Exolent & Sn!ff3r");
    
register_message(get_user_msgid("MOTD"), "message_MOTD");
}

public 
client_connect(id)
{
    
g_bSawMotd[id] = false
    set_task
(10.0,"show_message",id)
}

public 
show_message(id)
{
    new 
line[128], len0nextline
    
    
if (file_exists(file))
    {    
        while((
nextline read_file(file,i++,line,128,len)))
        {
            if(!
nextline) break
            
client_print(id,print_console,"%s",line)
        }
        
client_cmd(id,"toggleconsole")    
    }        
}

public 
message_MOTD(msgiddestid)
{
    if(!
g_bSawMotd[id])
    {
        if(
get_msg_arg_int(MOTD_FLAG_ARG) == MOTD_FLAG_END)
        {
            
g_bSawMotd[id] = true
        
}
        return 
PLUGIN_HANDLED
    
}
    return 
PLUGIN_CONTINUE;

Sn!ff3r is offline
Send a message via Skype™ to Sn!ff3r
spiderbites
Senior Member
Join Date: Nov 2007
Old 04-16-2008 , 19:16   Re: Print contents from a text file into client's console
Reply With Quote #9

nice..

can you make the console pops up before the menu for choosing team appears? and also, what's the maximum lines i can have in cmotd.txt?
Attached Thumbnails
Click image for larger version

Name:	cmotd.jpg
Views:	195
Size:	69.0 KB
ID:	25764  
spiderbites is offline
Sn!ff3r
Veteran Member
Join Date: Aug 2007
Location: Poland
Old 04-17-2008 , 08:45   Re: Print contents from a text file into client's console
Reply With Quote #10

Lines? Unlimited

Quote:
can you make the console pops up before the menu for choosing team appears?
No, why? Because messages NOT printing in console before team select.
Sn!ff3r is offline
Send a message via Skype™ to Sn!ff3r
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 12:13.


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