Error CMD
#1

pawn Код:
CMD:deletebusiness(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] < 5)
        return SendClientMessage(playerid, COLOR_GREY, "You're not authorised to use this command.");

    if(AdminDuty[playerid] != 1 && PlayerInfo[playerid][pAdmin] < 5)
        return SendClientMessage(playerid,COLOR_WHITE, "You're not on-duty as admin. To access your admin commands you must be on-duty. Type /aduty to go on-duty.");

    new
        iBusinessID;

    if(sscanf(params, "i", iBusinessID))
        return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /deletebusiness [BusinessID]");

 if(BusinessInfo[iBusinessID][bID] == 0 || iBusinessID >= MAX_BUSINESSES || iBusinessID < 0)
        return SendClientMessage(playerid, COLOR_WHITE, "The business ID does not exist");

    SetPVarInt(playerid, "DeleteBusinessID", iBusinessID);
    return true;
}
When I type /deletebusiness ID, It says, "The business ID does not exist"
Reply
#2

Anyone? I'll give rep+ to anyone who can help me to solve this problem
Reply
#3

The problem is either in the value of BusinessInfo[iBusinessID][bID], or the value of MAX_BUSINESSES, not in the coding.
Reply
#4

What do you mean?
Reply
#5

As Benzo said, BusinessInfo[iBusinessID][bID] is set to 0 or you need to increase the number of MAX_BUSINESSES.
Reply
#6

I have this
pawn Код:
#define MAX_BUSINESSES 750
How to set BusinessInfo[iBusinessID][bID] to 0?
Reply
#7

I suggest you use this:
pawn Код:
if (iBusinessID < MAX_BUSINESSES && iBusinessID >= 0)
{
    if (BusinessInfo[iBusinessID][bID] == 0}
        return SendClientMessage(playerid, COLOR_WHITE, "The business ID does not exist");
}
else
    return SendClientMessage(playerid, COLOR_WHITE, "Invalid Business-ID");
If you entered a value above MAX_BUSINESS or lower than 0 by mistake, you would get "array out of bounds" errors, because you were accessing the BusinessInfo array first. Your command could crash on that line, displaying at least: "SERVER: Unknown command".
First check if the entered value is valid, then check the rest (accessing an array with it for example).

"/deletebusiness 900" for example would first access the array at index 900 (which doesn't exist) and crash your command without displaying the proper message (invalid business-id).
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)