[Tool/Web/Other] live player stats in webpage
#1

I make small code for live viewing the playerstats on a webpage. + using a random own host webserver.
(html code in pawno)
Maybe useful for a little/homehosted server?

[ame]http://www.youtube.com/watch?v=zAJw7FUKjPk[/ame]

pwn:
Код:
new maininfo[5000];

forward WebInfo();
public WebInfo()
{
	maininfo="";
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
		{
        new str1[600],str2[600],str3[600],str4[600];

        new Float:health;
    	GetPlayerHealth(i,health);
  		format(str1,sizeof(str1),"%s%s%sname: %s<br>%s",dini_Get("html.txt","background"),dini_Get("html.txt","Re"),dini_Get("html.txt","font1"),GetPlyName(i),dini_Get("html.txt","fontend"));
  		format(str2,sizeof(str2),"%s  Money: %d<br>",dini_Get("html.txt","font2"),GetPlayerMoney(i));
  		format(str3,sizeof(str3),"  Score: %d<br>%s",GetPlayerScore(i));
  		format(str4,sizeof(str4),"  Health: %f<br>%s",health,dini_Get("html.txt","fontend"));
  		format(maininfo,sizeof(maininfo),"%s<br>%s%s%s%s",maininfo,str1,str2,str3,str4);
  		printf(maininfo);
  		}
	}

	fremove("/mainino.html");
 	new File:log = fopen("/mainino.html", io_write); // Open the file
    if(log)
    {
        fwrite(log, maininfo); // Write to the file (\r\n is for a new line)
        fclose(log); // Close the file
    }
    return 1;
}
ini file:

Код:
Re=<meta http-equiv="refresh" content="2" >
font1=<font size="5" color="red">
font2=<font size="4" color="yellow">
fontend=</font>
Reply
#2

Awesome!
P.S:First!
Reply
#3

Awesome[2]!
Reply
#4

Awesome!
Reply
#5

nice. but it will also work on hosted servers?
and how will you add it on your website?
Reply
#6

You should try to make a MySQL version of this, this won't work on "hosted" servers because the html cannot be written in another server's path. Hosting companies are also most likely using different servers for webhosting so there is a big change that the website isnt even hosted at the same server computer!

MySQL however does allow a webserver to communicate remotely to the SAMP Server's database and get the info. Just a tip for a future version
Reply
#7

Amazing.
Reply
#8

thanks.
Who will see i on the website: http://exa.servegame.com:8080/contact.htm
Server will be online for an hour. If you want to join...for only test
IP is in signature
Reply
#9

Your script has many problems. Everyone, use this instead!

pawn Код:
new mainInfo[500];
new mainFile[25] = "/index.html";
new pIDsWrote[100];

forward WebInfo();
public WebInfo()
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            new stringOne[250];

            new Float:playerStatHealth, playerStatScore, playerStatMoney;
            GetPlayerHealth(i, playerStatHealth);
            playerStatScore = GetPlayerScore(i);
            playerStatMoney = GetPlayerMoney(i);
           
            format(stringOne, 250, "%s%s%sname: %s<br>%s", dini_Get("html.txt","background"), dini_Get("html.txt","Re"), dini_Get("html.txt","font1"),ReturnPlayerName(i),dini_Get("html.txt","fontend"));
            format(stringOne, 250, "%s%s  Money: %d<br>", stringOne, dini_Get("html.txt","font2"), playerStatMoney);
            format(stringOne, 250, "%s  Score: %d<br>%s", stringOne, playerStatScore);
            format(stringOne, 250, "%s  Health: %f<br>%s", stringOne, playerStatHealth, dini_Get("html.txt","fontend"));
            format(mainInfo,  500, "%s<br>%s", mainInfo, stringOne);

            if(i != 1)
            {
                format(pIDsWrote, 100, "%s, %d", pIDsWrote, i);
            }
            else if(i == 1)
            {
                format(pIDsWrote, 100, "%d", i);
            }

            printf("--\n-- Added player %d's info to file write session.\n--");
        }
    }

    fremove(mainFile);
    new File:physFile = fopen(mainFile, io_write);
    if(physFile)
    {
        fwrite(physFile, mainInfo);
        fclose(physFile);
        if(strlen(pIDsWrote) == 0)
        {
            printf("--\n-- Successfully wrote to file \"%s\" with following player IDs:\n-- None. Server empty.\n--", mainFile, pIDsWrote);
        }
        else
        {
            printf("--\n-- Successfully wrote to file \"%s\" with following player IDs:\n-- %s\n--", mainFile, pIDsWrote);
        }
    }
    return 1;
}

stock ReturnPlayerName(pID)
{
    new nameInstance[25];
    GetPlayerName(pID, nameInstance, 25);
    return nameInstance;
}
Reply
#10

maybe i will make a tutorial how jou install it.

ps. I was just an example to show how you could do it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)