Raised This Month: $51 Target: $400
 12% 

Hud msg from a .txt


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
AntiBots
Veteran Member
Join Date: May 2008
Location: Brazil
Old 09-01-2008 , 12:52   Hud msg from a .txt
Reply With Quote #1

Hi friends,

I need a code for this, I have a .txt in a WebHost < www.aerocs.com.ar/radio/informacion/currentsong.txt > well I want to add that text into a Hud that reload every 10 seconds.

It is posible? The .txt change when I change the song in my Radio

Good Bye. I have the some in a php < www.aerocs.com.ar/radio/informacion/currentsong.php >
__________________
AntiBots is offline
Send a message via ICQ to AntiBots Send a message via MSN to AntiBots Send a message via Skype™ to AntiBots
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 09-01-2008 , 16:05   Re: Hud msg from a .txt
Reply With Quote #2

Maybe you can send a request through sockets, and read the results...you must strip the header/lines delimiters and show the rest of text in a HUD message.
Alka is offline
AntiBots
Veteran Member
Join Date: May 2008
Location: Brazil
Old 09-01-2008 , 17:25   Re: Hud msg from a .txt
Reply With Quote #3

You can show me an example ???
__________________
AntiBots is offline
Send a message via ICQ to AntiBots Send a message via MSN to AntiBots Send a message via Skype™ to AntiBots
PrEn1umz
Junior Member
Join Date: Feb 2007
Location: Nice, France
Old 09-01-2008 , 18:13   Re: Hud msg from a .txt
Reply With Quote #4

well,
i dont know a lot about sockets but here we go (there is probably some errors, but the principal is here)


PHP Code:
#pragma semicolon 1;

new const VERSION[] = "0.1.a"
new const V_DATE[] = "01/09/2008";

/* -------------------------------------------------------------------------------------------------
   ---------------------------------------- Socket Hud Message ------------------------------------- 
   -------------------------------------------------------------------------------------------------
                                                By PrEn1umz
   -------------------------------------------------------------------------------------------------
   -------------------------------------------------------------------------------------------------

Cvar:
----------
        amxx_sockets_hud : 0/1 - display hud message or not

   -------------------------------------------------------------------------------------------------
   -------------------------------------------------------------------------------------------------
   ------------------------------------------------------------------------------------------------- */

#include <amxmodx>
#include <sockets>

#define SCRIPT_NAME "/hud.txt"
#define REMOTE_HOST "url.com"
#define LOCAL_FILE "htmlread.txt"

new pCVAR_sockets_hud;

new 
g_SocketWeb;
new 
g_SocketTimeOut;
new 
g_SocketDir[128];
new 
bool:g_SocketWrite_Now;
new 
bool:g_File_Open;
new 
g_File_Handler;
new 
g_Msg[256];

public 
plugin_init()
{
    
register_plugin("Socket Hud Message"VERSION"PrEn1umz");
    
    
set_task(5.0"Task_Connect_Web");
    
set_task(10.0"Task_Display_Msg"1000""0"ab");
    
    
get_configsdir(g_SocketDir127);
    
format(g_SocketDir127"%s/%s"g_SocketDirLOCAL_FILE);
    
    
pCVAR_sockets_hud register_cvar("amxx_sockets_hud""1");
}

public 
Task_Connect_Web()
{
    new 
error 0;
    new 
constring[512];

    
g_SocketWeb socket_open(REMOTE_HOST80SOCKET_TCPerror);
    
    if (
g_SocketWeb 0)
    {
        
format(constring511"GET %s HTTP/1.1^nHost: %s^n^n"SCRIPT_NAMEREMOTE_HOST);
        
Write_Web(constring);
        
Read_Web();
    }
    else
    {
        switch (
error)
        {
            case 
1server_print("Error creating socket");
            case 
2server_print("Error resolving remote hostname");
            case 
3server_print("Error connecting socket");
        }
    }
    return 
PLUGIN_CONTINUE;
}

public 
Read_Web()
{
    new 
buffer[512];
    
    if (
socket_change(g_SocketWeb100))
    {
        
g_SocketTimeOut 0;
        
socket_recv(g_SocketWebbuffer511);
        
        if (!
g_SocketWrite_Now)
        {
            new 
search strfind(buffer"Your.url"00);
            
            if (
search != -1)
            {
                
copy(buffer511buffer[search]);
                
g_SocketWrite_Now true;
            }
        }
        if (
g_SocketWrite_Now)
        {
            if (!
g_File_Open)
            {
                
g_File_Handler fopen(g_SocketDir"w+");
                
g_File_Open true;
            }
            if (
g_File_Open)
            {
                
fputs(g_File_Handlerbuffer);
            }
        }
    }
    else
    {
        
g_SocketTimeOut ++;
    }
    if (
g_SocketTimeOut >= 5)
    {
        
Disconnect_Web();
    }
    else
    {
        
set_task(0.1"Read_Web");
    }
    
    return 
PLUGIN_CONTINUE;
}

public 
Write_Web(text[512])
{
    
socket_send(g_SocketWebtext511);
}

public 
Disconnect_Web()
{
    if (!
g_SocketWrite_Now)
    {
        
log_amx("Error getting HTTP data");
    }
    if (
g_File_Open)
    {
        
fclose(g_File_Handler);
    }
        
    
socket_close(g_SocketWeb);
    
    
Get_HudMsg();

    return 
PLUGIN_HANDLED;
}

public 
Get_HudMsg()
{
    if (
file_exists(g_SocketDir) == 1)
    {
        new 
temp[64];
        new 
file fopen(g_SocketDir"rt");
        
        while (!
feof(file))
        {
            
fgets(filetemp63);
            
parse(tempg_Msg255);
        }
        
fclose(file);
    }
    else
    {
        
format(g_Msg255"Error while connecting server");
    }

    return 
PLUGIN_CONTINUE;
}

public 
Task_Display_Msg(id)
{
    if (
get_pcvar_num(pCVAR_sockets_hud))
    {
        
set_hudmessage(25500, -1.00.802.02.00.20.21);
        
show_hudmessage(indexg_Msg);
    }

PrEn1umz is offline
AntiBots
Veteran Member
Join Date: May 2008
Location: Brazil
Old 09-02-2008 , 08:31   Re: Hud msg from a .txt
Reply With Quote #5

Thank, but i cant do work.
__________________
AntiBots is offline
Send a message via ICQ to AntiBots Send a message via MSN to AntiBots Send a message via Skype™ to AntiBots
AntiBots
Veteran Member
Join Date: May 2008
Location: Brazil
Old 09-03-2008 , 19:37   Re: Hud msg from a .txt
Reply With Quote #6

And with SQL It is posible?
__________________
AntiBots is offline
Send a message via ICQ to AntiBots Send a message via MSN to AntiBots Send a message via Skype™ to AntiBots
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 23:44.


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