Error CMD - 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: Error CMD (
/showthread.php?tid=489627)
Error CMD -
Wayland - 23.01.2014
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"
Re: Error CMD -
Wayland - 23.01.2014
Anyone? I'll give rep+ to anyone who can help me to solve this problem
Re: Error CMD -
Threshold - 23.01.2014
The problem is either in the value of BusinessInfo[iBusinessID][bID], or the value of MAX_BUSINESSES, not in the coding.
Re: Error CMD -
Wayland - 23.01.2014
What do you mean?
Re: Error CMD -
Shetch - 23.01.2014
As Benzo said, BusinessInfo[iBusinessID][bID] is set to 0 or you need to increase the number of MAX_BUSINESSES.
Re: Error CMD -
Wayland - 23.01.2014
I have this
pawn Код:
#define MAX_BUSINESSES 750
How to set BusinessInfo[iBusinessID][bID] to 0?
Re: Error CMD -
PowerPC603 - 23.01.2014
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).