Saving to .txt file
#1

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?
Reply
#2

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;
}
Reply
#3

Nevermind, fixed.
Reply
#4

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


Forum Jump:


Users browsing this thread: 1 Guest(s)