SA-MP Forums Archive
Saving to .txt file - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Saving to .txt file (/showthread.php?tid=185392)



Saving to .txt file - willsuckformoney - 24.10.2010

OK I have this command here:

pawn Код:
dcmd_cp(playerid,params[])
{
    if(IsPlayerAdmin(playerid)) {
        new cpName, tmp[256], Index;
        tmp = strtok(params,Index),cpName = strval(tmp);
        new Float:X,Float:Y,Float:Z,string[128];
        GetPlayerPos(playerid,X,Y,Z);
        if(strlen(params))
        {
            CreateDynamicCP(X,Y,Z,3,-1,-1,-1,100.0);
            format(string,sizeof(string),"new %s = CreateDynamicCP(%0.1f,%0.1f,%0.1f,3,-1,-1,-1,100.0);",cpName,X,Y,Z);
            SaveToFile("CheckPoints",string);
            format(string,sizeof(string),"Dynamic CheckPoint Created! X = %0.1f, Y = %0.1f, Z = %0.1f, Name = %s",X,Y,Z,cpName);
            SendClientMessageToAll(MSGSUCC_COLOR,string);
        } else return SendClientMessage(playerid,red,"USAGE: /CP [CP Name]");
    } else return SendERROR(playerid,1);
    return 1;
}
//
forward SaveToFile(filename[],text[]);
public SaveToFile(filename[],text[])
{
    new File:FAdmin, filepath[256], string[256];

    format(filepath,sizeof(filepath),"CNR/logs/%s.txt",filename);
    FAdmin = fopen(filepath,io_append);
    format(string,sizeof(string),"%s\r\n",text);
    fwrite(FAdmin,string);
    fclose(FAdmin);

    return 1;
}
It all works but the problem is, it wont save the CP name it just saves as

= CreateDynamicCP(PX,PY,PZ,3,-1,-1,-1,100.0);

Its missing the name at the beginning. Anyone know why?


Re: Saving to .txt file - LarzI - 24.10.2010

Why the hell do you use strtok? O_O

pawn Код:
dcmd_cp(playerid,params[])
{
    if(IsPlayerAdmin(playerid)) {
        new cpName;
        new Float:X,Float:Y,Float:Z,string[128];
        GetPlayerPos(playerid,X,Y,Z);
        if(strlen(params)) {
            strmid(cpName, params, 0, 255);
            CreateDynamicCP(X,Y,Z,3,-1,-1,-1,100.0);
            format(string,sizeof(string),"%s = CreateDynamicCP(%0.1f,%0.1f,%0.1f,3,-1,-1,-1,100.0);",cpName,X,Y,Z);
            SaveToFile("CheckPoints",string);
        } else return SendClientMessage(playerid,red,"USAGE: /CP [CP Name]");
    } else return SendERROR(playerid,1);
    return 1;
}



Re: Saving to .txt file - willsuckformoney - 29.10.2010

Nevermind, fixed.


Re: Saving to .txt file - HydraX - 14.11.2010

Quote:
Originally Posted by ******
Посмотреть сообщение
O_O
You don't see that everyday..