SA-MP Forums Archive
Command is crashing the server - 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)
+--- Thread: Command is crashing the server (/showthread.php?tid=512531)



Command is crashing the server - Twizted - 11.05.2014

Apparently, this command is crashing the server whenever executed. What is possibly causing the server to crash?

pawn Код:
new
            string[ 128 ],
            Age = PlayerInfo[ playerid ][ pAge ],
            Money = GetPlayerCash( playerid )
        ;

        new Sex[20];
        if(PlayerInfo[ playerid ][ pSex ] == 1) { Sex = "Male"; }
        else if(PlayerInfo[ playerid ][ pSex ] == 2) { Sex = "Female"; }

        SendClientMessage(playerid, COLOR_LIGHTBLUE, "_________________________STATISTICS OF %s_________________________, pName");
        SendClientMessage(playerid, -1, "");
        format(string, sizeof(string), "Name: {FFFFFF}%s {6FDD96}| Money: {FFFFFF}%d {6FDD96}| Age: {FFFFFF}%d {6FDD96}| Sex: {FFFFFF}%s", pName, Money, Age, Sex);
        SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
        SendClientMessage(playerid, -1, "");
        SendClientMessage(playerid, COLOR_LIGHTBLUE,"____________________________________________________________________");



Re: Command is crashing the server - Mriss - 11.05.2014

idk try remove
Код:
SendClientMessage(playerid, -1, "");
and if that doesnt work use cashdetect


Re: Command is crashing the server - Jstylezzz - 11.05.2014

To find out, I recommend you to place debug prints through the code. Like this:
pawn Код:
print("DEBUG: CMDSTART");
        new
            string[ 128 ],
            Age = PlayerInfo[ playerid ][ pAge ],
            Money = GetPlayerCash( playerid )
        ;
        print("DEBUG: 1");
        new Sex[20];
        if(PlayerInfo[ playerid ][ pSex ] == 1) { Sex = "Male"; }
        else if(PlayerInfo[ playerid ][ pSex ] == 2) { Sex = "Female"; }
        print("DEBUG: 2");
        SendClientMessage(playerid, COLOR_LIGHTBLUE, "_________________________STATISTICS OF %s_________________________, pName");
        SendClientMessage(playerid, -1, "");
        format(string, sizeof(string), "Name: {FFFFFF}%s {6FDD96}| Money: {FFFFFF}%d {6FDD96}| Age: {FFFFFF}%d {6FDD96}| Sex: {FFFFFF}%s", pName, Money, Age, Sex);
        SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
        SendClientMessage(playerid, -1, "");
        SendClientMessage(playerid, COLOR_LIGHTBLUE,"____________________________________________________________________");
        print("DEBUG:3");
After the server crashes, check the server log. You should see one or more number printed separately. The issue is most likely after the last number displayed.
If you run the command with the debug prints, check back here with the results. It will shrink the searching area, which will make it easier to find the problem here.

EDIT:

Quote:
Originally Posted by Mriss
Посмотреть сообщение
idk try remove
Код:
SendClientMessage(playerid, -1, "");
and if that doesnt work use cashdetect
That should be fine. I use this in a loop to clear the chat, so it shouldn't be a problem here either I think.


Re: Command is crashing the server - Beckett - 11.05.2014

Show the whole command please.


Re: Command is crashing the server - Twizted - 11.05.2014

It started happening when I added the colors. But I need the colors there.

Код:
[09:24:21] DEBUG: CMDSTART
[09:24:21] DEBUG: 1
[09:24:21] DEBUG: 2
[09:24:21] [debug] Server crashed while executing saonline.amx
[09:24:21] [debug] AMX backtrace:
[09:24:21] [debug] #0 native SendClientMessage () [004703a0] from samp-server.exe
[09:24:21] [debug] #1 0001a904 in public cmd_stats (0x00000000, 0x01025ec8) from saonline.amx
[09:24:21] [debug] #2 native CallLocalFunction () [00472ad0] from samp-server.exe
[09:24:21] [debug] #3 000009c4 in public OnPlayerCommandText (0x00000000, 0x01025eac) from saonline.amx
[09:24:21] [debug] Native backtrace:
[09:24:21] [debug] #0 004989ec in ?? () from samp-server.exe
[09:24:21] [debug] #1 747a6977 in ?? () from samp-server.exe
[09:24:21] [debug] #2 770b3ca4 in ?? () from C:\Windows\SysWOW64\ntdll.dll
[09:24:21] [debug] #3 770b3cfe in ?? () from C:\Windows\SysWOW64\ntdll.dll
[09:24:21] [debug] #4 770b3ca4 in ?? () from C:\Windows\SysWOW64\ntdll.dll
[09:24:21] [debug] #5 0045a965 in ?? () from samp-server.exe
[09:24:21] [debug] #6 770b3ca4 in ?? () from C:\Windows\SysWOW64\ntdll.dll
pawn Код:
CMD:stats(playerid, params[])
{
    GetPlayerName(playerid, pName, sizeof(pName));
   
    if(IsPlayerConnected(playerid))
    {
        print("DEBUG: CMDSTART");
        new
            string[ 128 ],
            Age = PlayerInfo[ playerid ][ pAge ],
            Money = GetPlayerCash( playerid )
        ;
        print("DEBUG: 1");
        new Sex[20];
        if(PlayerInfo[ playerid ][ pSex ] == 1) { Sex = "Male"; }
        else if(PlayerInfo[ playerid ][ pSex ] == 2) { Sex = "Female"; }
        print("DEBUG: 2");
        SendClientMessage(playerid, COLOR_LIGHTBLUE, "_________________________STATISTICS OF %s_________________________, pName");
        SendClientMessage(playerid, -1, "");
        format(string, sizeof(string), "Name: {FFFFFF}%s {6FDD96}| Money: {FFFFFF}%d {6FDD96}| Age: {FFFFFF}%d {6FDD96}| Sex: {FFFFFF}%s", pName, Money, Age, Sex);
        SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
        SendClientMessage(playerid, -1, "");
        SendClientMessage(playerid, COLOR_LIGHTBLUE,"____________________________________________________________________");
        print("DEBUG:3");
    }
    return 1;
}



Re: Command is crashing the server - CutX - 11.05.2014

do not use %s in SendClientMessage
pawn Код:
SendClientMessage(playerid, COLOR_LIGHTBLUE, "_________________________STATISTICS OF %s_________________________, pName");
of course it's crashing if you go using format Specifiers in SendClientMessage.
just do it like this
pawn Код:
format(string, sizeof(string), "_________________________STATISTICS OF %s_________________________",pName);
SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
i think they should add that tho the wiki in some warning-box-thingy


Re: Command is crashing the server - Jstylezzz - 11.05.2014

Alright, as you can see, the problem is somewhere between 2 and 3. To get the exact location, we can place debug prints after each function. I'll make it easy for you and do it for you.
pawn Код:
CMD:stats(playerid, params[])
{
    GetPlayerName(playerid, pName, sizeof(pName));

    if(IsPlayerConnected(playerid))
    {
        print("DEBUG: CMDSTART");
        new
            string[ 128 ],
            Age = PlayerInfo[ playerid ][ pAge ],
            Money = GetPlayerCash( playerid )
        ;
        print("DEBUG: 1");
        new Sex[20];
        if(PlayerInfo[ playerid ][ pSex ] == 1) { Sex = "Male"; }
        else if(PlayerInfo[ playerid ][ pSex ] == 2) { Sex = "Female"; }
        print("DEBUG: 2");
        SendClientMessage(playerid, COLOR_LIGHTBLUE, "_________________________STATISTICS OF %s_________________________, pName");
        print("DEBUG: 2.1");
        SendClientMessage(playerid, -1, "");
        print("DEBUG: 2.2");
        format(string, sizeof(string), "Name: {FFFFFF}%s {6FDD96}| Money: {FFFFFF}%d {6FDD96}| Age: {FFFFFF}%d {6FDD96}| Sex: {FFFFFF}%s", pName, Money, Age, Sex);
        print("DEBUG: 2.3");
        SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
        print("DEBUG: 2.4");
        SendClientMessage(playerid, -1, "");
        print("DEBUG: 2.5");
        SendClientMessage(playerid, COLOR_LIGHTBLUE,"____________________________________________________________________");
        print("DEBUG:3");
    }
    return 1;
}
For bigger codes this solution wouldn't be fast enough, but I think that for this command it's alright to do it like this, since you'll find the exact crash location.
Now do the same as you did first, and I hope we get the exact crash location.

In advance, if it's the colors that cause the problem, do they work in other messages? If not, you might want to have a look at the color defines and redo it.

EDIT:

Quote:
Originally Posted by CutX
Посмотреть сообщение
do not use %s in SendClientMessage
pawn Код:
SendClientMessage(playerid, COLOR_LIGHTBLUE, "_________________________STATISTICS OF %s_________________________, pName");
of course it's crashing if you go using format Specifiers in SendClientMessage.
just do it like this
pawn Код:
format(string, sizeof(string), "_________________________STATISTICS OF %s_________________________",pName);
SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
i think they should add that tho the wiki in some warning-box-thingy
LOL, good point. I didn't even notice. I'll try and add it to the wiki.


Re: Command is crashing the server - Twizted - 11.05.2014

Jstylezzz, I didn't know about that debug thing, but Lord thank you, it's useful. Thanks to CutX too, I hadn't figured that out. Thanks a bunch you two.