SA-MP Forums Archive
ZCMD Unknown Command Problem - 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: ZCMD Unknown Command Problem (/showthread.php?tid=492521)



ZCMD Unknown Command Problem - Vlad64 - 04.02.2014

Hey, I have this command, but whenever I use it, it shows "SERVER: Unknown command" but it does what it's supposed to do, why?

pawn Код:
CMD:exit(playerid)
{
    for(new i=0; i<MAX_HOUSES; i++)
    {
        new hid=i;
        new path[200];
        format(path, sizeof(path), "/Houses/%d.ini",hid);
        if(dini_Exists(path))
        {
            if(IsPlayerInRangeOfPoint(playerid,5,hInfo[InHouse[playerid]][EnterX],hInfo[InHouse[playerid]][EnterY],hInfo[InHouse[playerid]][EnterZ]))
            {
                SetPlayerInterior(playerid,0);
                SetPlayerVirtualWorld(playerid,0);
                SetPlayerPos(playerid,hInfo[InHouse[playerid]][ExitX],hInfo[InHouse[playerid]][ExitY],hInfo[InHouse[playerid]][ExitZ]);
                InHouse[playerid]=-1;
            }
        }
    }
    return 1;
}
How can i remove "SERVER: Unknown command", even though it's returning 1 and I'm not using OnPlayerCommandText?? Thanks.


Re: ZCMD Unknown Command Problem - Konstantinos - 04.02.2014

If it shows the unknown command, it might be because of a run time error.

Load crashdetect plugin and compile with debug info (-d3). Re-compile your scripts, start the server and type that command. In case it will display the unknown command, post your server log.

If InHouse[playerid] is not any value between 0 and (MAX_HOUSES - 1), a run time error about Array index out of bounds will be caused.


Re: ZCMD Unknown Command Problem - Vlad64 - 04.02.2014

Here's the log:
Код:
[12:12:15] [debug] Run time error 4: "Array index out of bounds"
[12:12:15] [debug]  Accessing element at negative index -1
[12:12:15] [debug] AMX backtrace:
[12:12:15] [debug] #0 0001fa7c in public cmd_exit (playerid=0, ... <1 argument>) at F:\Scripting\SAMP\Green Country RP\gamemodes\GM.pwn:1669
[12:12:15] [debug] #1 native CallLocalFunction () [00472000] from samp-server.exe
[12:12:15] [debug] #2 00000580 in public OnPlayerCommandText (playerid=0, cmdtext[]=@0x0004713c "/exit") at F:\Scripting\SAMP\Green Country RP\pawno\include\zcmd.inc:104
Line 1669:
pawn Код:
if(IsPlayerInRangeOfPoint(playerid,5,hInfo[InHouse[playerid]][EnterX],hInfo[InHouse[playerid]][EnterY],hInfo[InHouse[playerid]][EnterZ]))
Also, MAX_HOUSES is 200


Re: ZCMD Unknown Command Problem - Konstantinos - 04.02.2014

A run time error Array index out of bounds for accessing element at negative index -1.

As you can see, InHouse[playerid] is -1 and you use it inside hInfo which causes the run time error. In order to get rid of it, you need to check whether its value is in bounds.

The actual problem was that if the house is found, it sets the variable to -1 but it doesn't break the loop and continues.

pawn Код:
CMD:exit(playerid)
{
    new path[20];
    for(new hid=0; hid<MAX_HOUSES; hid++)
    {
        format(path, sizeof(path), "/Houses/%d.ini",hid);
        if(dini_Exists(path) && 0 <= InHouse[playerid] < sizeof (hInfo))
        {
            if(IsPlayerInRangeOfPoint(playerid,5,hInfo[InHouse[playerid]][EnterX],hInfo[InHouse[playerid]][EnterY],hInfo[InHouse[playerid]][EnterZ]))
            {
                SetPlayerInterior(playerid,0);
                SetPlayerVirtualWorld(playerid,0);
                SetPlayerPos(playerid,hInfo[InHouse[playerid]][ExitX],hInfo[InHouse[playerid]][ExitY],hInfo[InHouse[playerid]][ExitZ]);
                InHouse[playerid]=-1;
                break;
            }
        }
    }
    return 1;
}
A note too, since it's ZCMD, why do you use:
pawn Код:
CMD:exit(playerid)
instead of:
pawn Код:
CMD:exit(playerid, params[])
?


Re: ZCMD Unknown Command Problem - Vlad64 - 04.02.2014

Thank you very much Konstantinos It doesn't show that again

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
A note too, since it's ZCMD, why do you use:
pawn Код:
CMD:exit(playerid)
instead of:
pawn Код:
CMD:exit(playerid, params[])
?
I used only (playerid) because I don't think it needs any parameters, with (playerid,params[]) i have to put #pragma unused params;
One more question: Is it bad if I keep the debug -d3?


Re: ZCMD Unknown Command Problem - Konstantinos - 04.02.2014

In ZCMD is not necessary to use #pragma if you do not use params but keep the correct syntax no matter what.

No, it's not at all. -d3 gives more information related to run time errors, crashes etc and it is always helpful and recommended!


Re: ZCMD Unknown Command Problem - Wizz123 - 04.02.2014

ZCMD dosent work that way, you gotta put parameters on each command even if you arent using it.
No, its not bad to use -d3 its popularly attributed why would it be bad.

EDIT: Konstantinos wrote first, but i'll keep it so people can read.