#include <a_samp>
public OnPlayerConnect(playerid)
{
new File:playerinfos, pntFinal[256], pntName[MAX_PLAYER_NAME+1], pntIp[16];
GetPlayerName(playerid,pntName,sizeof(pntName));
GetPlayerIp(playerid,pntIp,sizeof(pntIp));
format(pntFinal,sizeof(pntFinal),"Name: %s | ",pntName);
format(pntFinal,sizeof(pntFinal),"%sIP: %s | ",pntFinal,pntIp);
playerinfos = fopen("playerinfos.txt",io_write);
fwrite(playerinfos,pntFinal);
fclose(playerinfos);
return 1;
}
#include <a_samp>
public OnPlayerConnect(playerid)
{
new File:playerinfos, pntFinal[MAX_PLAYER_NAME+15+11], pntName[MAX_PLAYER_NAME], pntIp[15];
GetPlayerName(playerid,pntName,sizeof(pntName));
GetPlayerIp(playerid,pntIp,sizeof(pntIp));
format(pntFinal,sizeof(pntFinal),"Name: %s | IP: %s",pntName,pntIp);
playerinfos = fopen("playerinfos.txt",io_append);
if (playerinfos)
{
fwrite(playerinfos,pntFinal);
fclose(playerinfos);
}
return 1;
}
print("fopen");
playerinfos = fopen(...);
print("fwrite");
fwrite(...);
print("fclose");
fclose(...);
playerinfos = fopen("playerinfos.txt", io_write);
if(playerinfos) // Check if the file handle is valid!
{
fwrite(playerinfos, pntFinal);
fclose(playerinfos);
}
You are using "format" twice which is actually useless because you are formatting the same thing then erasing the old and re-formatting it again.
So just format then append your changes. Then format again. |
format(string, sizeof(string), "Hey, %s!", szSomething);
format(string, sizeof(string), "%s|Oh hello there!", string);
format(pntFinal,sizeof(pntFinal),"Name: %s | ",pntName);
format(pntFinal,sizeof(pntFinal),"%sIP: %s | ",pntFinal,pntIp);
format(pntFinal, sizeof(pntFinal), "Name: %s | IP: %s | ", pntName, pntIp);