Command shuts off server
#1

It compiles fine, just when I use it, it shuts down the server:
pawn Код:
dcmd_setscore(playerid, params[])
{
    new Index;
    new tmp[256];
    tmp = strtok(params, Index);
    new tmp2[256];
    tmp2 = strtok(params, Index);
    new score;
    new id;
    id = strval(tmp);
    score = strval(tmp2);
    new string[100];
    new pName[MAX_PLAYER_NAME];
    new pNameTwo[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pName, sizeof(pName));
    GetPlayerName(id, pNameTwo, sizeof(pNameTwo));
    if(!strlen(params)) return SendClientMessage(playerid, COLOR_RED, "Usage: /setscore (ID) (Score)");
    if(score == GetPlayerScore(id)) return SendClientMessage(playerid, COLOR_RED, "ERROR: Score must be different then current score");
    if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "ERROR: Invalid player ID");
    if(PlayerInfo[playerid][Admin] < 3) return SendClientMessage(playerid, COLOR_RED, "ERROR: You need to be level 3+ to use this command");
    else
    {
        SetPlayerScore(id, score);
        format(string, sizeof(string),"-| You have set %s(%d)'s score to %d |-", pNameTwo, id, score);
        SendClientMessage(playerid, COLOR_AQUA, string);
        format(string, sizeof(string),"-| Administrator %s(%d) has set your score to %d |-", pName, playerid, score);
        SendClientMessage(id, COLOR_AQUA, string);
    }
    return 1;
}
And help?
Reply
#2

Quote:
Originally Posted by [HLF]Southclaw
Посмотреть сообщение
Use ZCMD and SSCANF it's far less complex!

But to find your problem, put a "print()" line in between each line of code to see where it stops:

pawn Код:
print("NUMBER");
// for instance:



Function();
print("1");
Function();
print("2");
Function();
print("3");
BrokenFunction();
print("4");
Function();
print("5");
You will see numbers printed on the console, see what number it reaches before it crashes (Look in the server log file)

You will then know what line is causing the error!
OK, I'll try.

EDIT: It got all the way to 3 with this code:
pawn Код:
dcmd_setscore(playerid, params[])
{
    new Index;
    new tmp[256];
    tmp = strtok(params, Index);
    new tmp2[256];
    tmp2 = strtok(params, Index);
    new score;
    new id;
    id = strval(tmp);
    score = strval(tmp2);
    new string[100];
    new pName[MAX_PLAYER_NAME];
    new pNameTwo[MAX_PLAYER_NAME];
    GetPlayerName(playerid, pName, sizeof(pName));
    GetPlayerName(id, pNameTwo, sizeof(pNameTwo));
    if(!strlen(params)) return SendClientMessage(playerid, COLOR_RED, "Usage: /setscore (ID) (Score)");
    if(score == GetPlayerScore(id)) return SendClientMessage(playerid, COLOR_RED, "ERROR: Score must be different then current score");
    if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, COLOR_RED, "ERROR: Invalid player ID");
    if(PlayerInfo[playerid][Admin] < 3) return SendClientMessage(playerid, COLOR_RED, "ERROR: You need to be level 3+ to use this command");
    else
    {
        SetPlayerScore(id, score);
        print("0");
        format(string, sizeof(string),"-| You have set %s(%d)'s score to %d |-", pNameTwo, id, score);
        print("1");
        SendClientMessage(playerid, COLOR_AQUA, string);
        print("2");
        format(string, sizeof(string),"-| Administrator %s(%d) has set your score to %d |-", pName, playerid, score);
        print("3");
        SendClientMessage(id, COLOR_AQUA, string);
    }
    return 1;
}
And it worked, i think it was because i changed:
Код:
score = strval(tmp2);
id = strval(tmp)
To:
Код:
id = strval(tmp);
score = strval(tmp2)
But thanks, REP+
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)