[HELP] /savepos command
#1

I got a problem, this is a command I created myself.
Compile give no errors or warnings, Once using command ingame.
Server crashed and samp-server.exe closes, The command succesfully sends SendClientMessage.
So I believe the script codes underneath the SendClientMessage is one of the problem.
Anyone help please.


pawn Код:
if(strcmp(cmdtext, "/Savepos", true) == 0)
    {
        new string[50];
        new Float:x, Float:y, Float:z;
        new File:hFile;
        GetPlayerPos(playerid, x, y, z);

        format(string, sizeof(string), "%f,%f,%f.", x, y, z);
        SendClientMessage(playerid,COLOR_GREEN,"Player Pos Should Be Saved.");
        hFile = fopen("scriptfiles/SavedPos.log", io_append);
        fwrite(hFile, string);
        fclose(hFile);
        return 1;
    }








Finaly, got a perfect working strcmp command with comment!
Thank you all for helping me out but I am gonna use Clive's command script (quote underneath)
Special thanks to Clive .

Quote:
Originally Posted by Clive
Посмотреть сообщение
xD, Try this
OnPlayerCommandText:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    new cmd[256];
    new idx;
    new tmp[256];

    cmd = strtok(cmdtext, idx);
    if(strcmp(cmd,"/savepos",true)==0)
    {
        tmp = strtok(cmdtext,idx);
        new string[128], string2[64], Float:X, Float:Z, Float:Y;
        if(!strlen(tmp)) return SendClientMessage(playerid, -1,"USAGE: /savepos [comment]");
        GetPlayerPos(playerid, X, Y, Z);
        format(string, sizeof(string), "%f, %f, %f //%s \r\n", X, Y, Z, cmdtext[9]);
        SavePosLogs(string);
        format(string2, sizeof(string2),"Player Pos Should Be Saved. With comment: %s", cmdtext[9]);
        SendClientMessage(playerid, -1,string2);
        return 1;
    }
    return 0;
}
Somewhere in your script:
pawn Код:
forward SavePosLogs(string[]);
public SavePosLogs(string[])
{
    new entry[256];
    format(entry, sizeof(entry), "%s\r\n",string);
    new File:hFile;
    hFile = fopen("SavedPos.log", io_append);
    if (hFile)
    {
    fwrite(hFile, entry);
    fclose(hFile);
    }
}
Somewhere in your script:
pawn Код:
stock strtok(const string[], &index,seperator=' ')
{
    new length = strlen(string);
    new offset = index;
    new result[255];
    while ((index < length) && (string[index] != seperator) && ((index - offset) < (sizeof(result) - 1)))
    {
        result[index - offset] = string[index];
        index++;
    }

    result[index - offset] = EOS;
    if ((index < length) && (string[index] == seperator))
    {
        index++;
    }
    return result;
}
Reply
#2

pawn Код:
if(strcmp(cmdtext, "/Savepos", true) == 0)
    {
        new string[50];
        new Float:x, Float:y, Float:z;
        new File:hFile;
        GetPlayerPos(playerid, x, y, z);

        format(string, sizeof(string), "%f,%f,%f.", x, y, z);
        SendClientMessage(playerid,COLOR_GREEN,"Player Pos Should Be Saved.");
        hFile = fopen("SavedPos.log", io_append);// It will automatically search for a file in scriptfiles.
        fwrite(hFile, string);
        fclose(hFile);
        return 1;
    }
Reply
#3

Quote:
Originally Posted by Hashski
Посмотреть сообщение
if(strcmp(cmdtext, "/Savepos", true) == 0)
{
new string[50];
new Float, Float:y, Float:z;
new File:hFile;
GetPlayerPos(playerid, x, y, z);

format(string, sizeof(string), "%f,%f,%f.", x, y, z);
SendClientMessage(playerid,COLOR_GREEN,"Player Pos Should Be Saved.");
hFile = fopen("SavedPos.log", io_append);// It will automatically search for a file in scriptfiles.
fwrite(hFile, string);
fclose(hFile);
return 1;
}
Please put in it next time.

EDIT: It works now.
Reply
#4

Quote:
Originally Posted by Rolyy
Посмотреть сообщение
Please put in it next time.
It don't matter what i use
Reply
#5

Quote:
Originally Posted by Hashski
Посмотреть сообщение
It don't matter what i use
It does, the difference is to make it easier for person that needs help to copy the pawn codes.. Instead of pawn code getting flooded by smileys.

And thanks for your help.
But I got another problem I guess.
Reply
#6

Код:
1264.279418,-2019.029052,59.297622.1266.660156,-2015.525756,60.020011.1267.267456,-2009.798461,59.487518.1261.948974,-2010.817626,60.154098.1266.249755,-2013.652099,59.916809.
This is what came out after 5 times of /savepos, how can I start a new line for the file to save?

NOTE: Sorry for bump within 24 hours, making sure to other players that I have a new problem.
Reply
#7

pawn Код:
if (strcmp(cmdtext, "/savepos", true)==0)
{
    new string[128];
    new Float:X, Float:Z, Float:Y;
    GetPlayerPos(playerid, X, Y, Z);
    SendClientMessage(playerid,COLOR_GREEN,"Player Pos Should Be Saved.");
    new File:pos=fopen("SavedPos.log", io_append);
    format(string, sizeof(string), "%f, %f, %f\r\n", X, Y, Z);
    fwrite(pos, string);
    fclose(pos);
    return 1;
}
Reply
#8

Quote:
Originally Posted by Clive
Посмотреть сообщение
pawn Код:
if (strcmp(cmdtext, "/savepos", true)==0)
{
    new string[128];
    new Float:X, Float:Z, Float:Y;
    GetPlayerPos(playerid, X, Y, Z);
    SendClientMessage(playerid,COLOR_GREEN,"Player Pos Should Be Saved.");
    new File:pos=fopen("SavedPos.log", io_append);
    format(string, sizeof(string), "%f, %f, %f\r\n", X, Y, Z);
    fwrite(pos, string);
    fclose(pos);
    return 1;
}
This works perfect, Thanks alot man.
Reply
#9

Quote:
Originally Posted by Rolyy
Посмотреть сообщение
This works perfect, Thanks alot man.
No Problem.
Reply
#10

I know it is possible but I have no knownledge about how to add a comment after every command?
Example: /savepos Gate one
and adds in file.txt "838.722351, -1222.245483, 16.499397 //Gate one"

Wondering if someone could help me with this.


pawn Код:
if (strcmp(cmdtext, "/savepos", true)==0)
{
    new string[128];
    new Float:X, Float:Z, Float:Y;
    GetPlayerPos(playerid, X, Y, Z);
    SendClientMessage(playerid,COLOR_GREEN,"Player Pos Should Be Saved. With comment: [...]");
    new File:pos=fopen("SavedPos.log", io_append);
    format(string, sizeof(string), "%f, %f, %f\r\n", X, Y, Z);
    fwrite(pos, string);
    fclose(pos);
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)