AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Hud msg from a .txt (https://forums.alliedmods.net/showthread.php?t=76881)

AntiBots 09-01-2008 12:52

Hud msg from a .txt
 
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 :D

Good Bye. I have the some in a php < www.aerocs.com.ar/radio/informacion/currentsong.php >

Alka 09-01-2008 16:05

Re: Hud msg from a .txt
 
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.

AntiBots 09-01-2008 17:25

Re: Hud msg from a .txt
 
You can show me an example :D???

PrEn1umz 09-01-2008 18:13

Re: Hud msg from a .txt
 
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);
    }



AntiBots 09-02-2008 08:31

Re: Hud msg from a .txt
 
Thank, but i cant do work.

AntiBots 09-03-2008 19:37

Re: Hud msg from a .txt
 
And with SQL It is posible?


All times are GMT -4. The time now is 03:18.

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