[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


Messages In This Thread
[HELP] /savepos command - by Rolyy - 01.03.2011, 11:47
Re: [HELP] /savepos command - by Hashski - 01.03.2011, 11:52
Re: [HELP] /savepos command - by Rolyy - 01.03.2011, 11:53
Re: [HELP] /savepos command - by Hashski - 01.03.2011, 11:55
Re: [HELP] /savepos command - by Rolyy - 01.03.2011, 12:00
Re: [HELP] /savepos command - by Rolyy - 01.03.2011, 12:05
Re: [HELP] /savepos command - by HyperZ - 01.03.2011, 12:40
Re: [HELP] /savepos command - by Rolyy - 01.03.2011, 12:46
Re: [HELP] /savepos command - by HyperZ - 01.03.2011, 12:47
Re: [HELP] /savepos command - by Rolyy - 01.03.2011, 12:53

Forum Jump:


Users browsing this thread: 4 Guest(s)