#1

Hello.

I've found this script to save a player's IP to a file:

Код:
new File:ip = fopen("ip.log", io_readwrite);
new string[100], pName[24], pIp[20];
if(ip)
 	{
GetPlayerName(playerid, pName, sizeof(pName)); 
GetPlayerIp(playerid, pIp, sizeof(pIp)); 
format(string, sizeof(string), "%s - %s \n", pIp, pName); 
fwrite(ip, string);
fclose(ip); 
}
But it only shows 1 player's name and IP. Does anyone know how to make it so it saves everyone's IP and name in a list?

Credits go to ZeroBurn who permits to code to be used by anyone.

Thank you in advance!
Reply
#2

pawn Код:
new File:ip = fopen("ip.log", io_readwrite);
new string[100], pName[24], pIp[20];
if(ip)
{
   for(new i = 0; i < MAX_PLAYERS; i++)
   {
      GetPlayerName(i, pName, sizeof(pName));
      GetPlayerIp(i, pIp, sizeof(pIp));
      format(string, sizeof(string), "%s - %s \n", pIp, pName);
      fwrite(ip, string);
      fclose(ip);
   }
}
I accidentally deleted mine lol,re-edited.
Reply
#3

Quote:
Originally Posted by Ash0153
Hello.

I've found this script to save a player's IP to a file:

Код:
new File:ip = fopen("ip.log", io_readwrite);
new string[100], pName[24], pIp[20];
if(ip)
 	{
GetPlayerName(playerid, pName, sizeof(pName)); 
GetPlayerIp(playerid, pIp, sizeof(pIp)); 
format(string, sizeof(string), "%s - %s \n", pIp, pName); 
fwrite(ip, string);
fclose(ip); 
}
But it only shows 1 player's name and IP. Does anyone know how to make it so it saves everyone's IP and name in a list?

Credits go to ZeroBurn who permits to code to be used by anyone.

Thank you in advance!
Try:
Код:
new File:ip = fopen("ip.log", io_readwrite);
new string[100], pName[24], pIp[20];
if(ip)
 	{
for(new i = 0; i < MAX_PLAYERS; i++)
{
  GetPlayerName(i, pName, sizeof(pName)); 
  GetPlayerIp(i, pIp, sizeof(pIp)); 
  format(string, sizeof(string), "%s - %s \n", pIp, pName); 
  fwrite(ip, string);
}
fclose(ip); 
}
Reply
#4

Kaisersouse, yours' repeats the saved data about 100 times inside the file.
Testing yours now Karlip. Thanks for the replies =]
Reply
#5

Quote:
Originally Posted by Ash0153
Kaisersouse, yours' repeats the saved data about 100 times inside the file.
Testing yours now Karlip. Thanks for the replies =]
Ash,mine does the same.

Do you want it to save on connect?
Reply
#6

ugh im used to using foreach which has built-in IsPlayerConnected. Sorry
Код:
if(ip
{
  if(IsPlayerConnected(i))
  {
  everything else
Reply
#7

Sorry for the late reply, I went for tea.

Quote:
Originally Posted by Karlip
Quote:
Originally Posted by Ash0153
Kaisersouse, yours' repeats the saved data about 100 times inside the file.
Testing yours now Karlip. Thanks for the replies =]
Ash,mine does the same.

Do you want it to save on connect?
On connect or login would be great =]

Quote:
Originally Posted by kaisersouse
ugh im used to using foreach which has built-in IsPlayerConnected. Sorry
Код:
if(ip
{
  if(IsPlayerConnected(i))
  {
  everything else
error 017: undefined symbol "i" - Probably something really simple but I'm not too sure how to get around it.

Should: pIp[20];
be pIp[16]; ?
Reply
#8

Put that before IsPlayerConnected:

for(new i = 0; i < MAX_PLAYERS; i++)
{

So, it should look like this
pawn Код:
if(ip)
{
   for(new i = 0; i < MAX_PLAYERS; i++)
   {
       if(IsPlayerConnected(i))
       {
           // Blah
       }
   }
}
Reply
#9

Thank you, trying that now =] - Still only saves 1 person.

Sorry about all the hassle guys
Reply
#10

If you want it on connect:
pawn Код:
forward KickLog(string[]);
public IpLog(string[])
{
     new entry[256];
    format(entry, sizeof(entry), "%s\r\n",string);
    new File:hFile;
    hFile = fopen("ip.log", io_append);
    if (hFile){
        fwrite(hFile, entry);
        fclose(hFile);
    }
}

public OnPlayerConnect(playerid)
{
    new string[100], pName[24], pIp[20];
    GetPlayerName(playerid, pName, sizeof(pName));
    GetPlayerIp(playerid, pIp, sizeof(pIp));
    format(string, sizeof(string), "%s - %s \n", pIp, pName);
    IpLog(string);
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)