Command returns server unknown command. -
thimo - 19.01.2014
I have a sellhouse command but it just returns SERVER: Unknown command and crashdetect outputs something. This is the sellhouse command:
pawn Код:
CMD:sellhouse(playerid, params[])
{
new bool:HouseHasCars= false, CarSlot, HouseID;
HouseID = APlayerData[playerid][CurrentHouse];
for(new i; i < MAX_HOUSES; i++)
{
if(IsPlayerInRangeOfPoint(playerid, 2.50, AHouseData[i][HouseX], AHouseData[i][HouseY], AHouseData[i][HouseZ]))
{
new pName[MAX_PLAYER_NAME], string2[128], string3[128], string4[128];
GetPlayerName(playerid, pName, sizeof(pName));
if(strmatch(AHouseData[i][Owner], pName))
{
for (CarSlot = 0; CarSlot < 20; CarSlot++)
if (AHouseData[HouseID][VehicleIDs][CarSlot] != 0)
HouseHasCars = true;
if(HouseHasCars == false)
{
GivePlayerCash(playerid, floatround(AHouseData[i][price] * 0.75));
format(string2, sizeof(string2), "UPDATE Houses SET Houseowner = '' WHERE HouseID = '%d'", i);
mysql_function_query( Handle, string2, false, "", "" );
SendClientMessage(playerid, 0xFF0000, "Your house has been sold");
format(string3, sizeof(string3), "UPDATE Users SET Houses = '%d' WHERE Name = '%s'", APlayerData[playerid][Houses]--, APlayerData[playerid][Name]);
mysql_function_query( Handle, string3, false, "", "" );
DestroyDynamicPickup(HousePickup[i]);
HousePickup[i] = CreateDynamicPickup(1273, 1, AHouseData[i][HouseX], AHouseData[i][HouseY], AHouseData[i][HouseZ], -1);
format(string4, sizeof(string4), "{FFFFFF}This house is for sale!\nPrice: %i Level: %i\n Type /buyhouse to buy\nHouse ID: %i", AHouseData[i][price], AHouseData[i][Houselevel], i);
UpdateDynamic3DTextLabelText(AHouseData[i][HouseLabel], COLOR_GREY, string4);
strdel(AHouseData[i][Owner], 0, 24); //Owner = "" Anyway why the pickup wont get deleted? :| old pickupwill stay
SavePlayer(playerid);
}
else
SendClientMessage(playerid, 0xFF0000AA, "You can not sell a house with cars assigned to it.");
}
else
SendClientMessage(playerid, COLOR_GREY, "This house is not owned by you!");
}
}
return 1;
}
The error that the crashdetect gives out:
Код:
[11:47:04] [debug] Run time error 4: "Array index out of bounds"
[11:47:04] [debug] Accessing element at negative index -1
[11:47:04] [debug] AMX backtrace:
[11:47:04] [debug] #0 000341e8 in public cmd_sellhouse () from ET.amx
[11:47:04] [debug] #1 native CallLocalFunction () [004722d0] from samp-server.exe
[11:47:04] [debug] #2 00000748 in public OnPlayerCommandText () from ET.amx
[11:47:04] Thimo used: /sellhouse
What am i doing wrong?
Re: Command returns server unknown command. -
Avi Raj - 19.01.2014
Are you also using strcmp in this script or in any FS?
Try to convert all commands to ZCMD.
Re-compile and then run.
Re: Command returns server unknown command. -
MatriXgaMer - 19.01.2014
pawn Код:
Use this but its not tested soo good luck :D
CMD:sellhouse(playerid, params[])
{
new bool:HouseHasCars= false, CarSlot, HouseID;
HouseID = APlayerData[playerid][CurrentHouse];
for(new i; i < MAX_HOUSES; i++)
{
if(IsPlayerInRangeOfPoint(playerid, 2.50, AHouseData[i][HouseX], AHouseData[i][HouseY], AHouseData[i][HouseZ]))
{
new pName[MAX_PLAYER_NAME], string2[128], string3[128], string4[128];
GetPlayerName(playerid, pName, sizeof(pName));
if(strmatch(AHouseData[i][Owner], pName))
{
for (CarSlot = 0; CarSlot < 20; CarSlot++)
if (AHouseData[HouseID][VehicleIDs][CarSlot] != 0)
HouseHasCars = true;
if(HouseHasCars == false)
{
GivePlayerCash(playerid, floatround(AHouseData[i][price] * 0.75));
format(string2, sizeof(string2), "UPDATE Houses SET Houseowner = '' WHERE HouseID = '%d'", i);
mysql_function_query( Handle, string2, false, "", "" );
SendClientMessage(playerid, 0xFF0000, "Your house has been sold");
format(string3, sizeof(string3), "UPDATE Users SET Houses = '%d' WHERE Name = '%s'", APlayerData[playerid][Houses]--, APlayerData[playerid][Name]);
mysql_function_query( Handle, string3, false, "", "" );
DestroyDynamicPickup(HousePickup[i]);
HousePickup[i] = CreateDynamicPickup(1273, 1, AHouseData[i][HouseX], AHouseData[i][HouseY], AHouseData[i][HouseZ], -1);
format(string4, sizeof(string4), "{FFFFFF}This house is for sale!\nPrice: %i Level: %i\n Type /buyhouse to buy\nHouse ID: %i", AHouseData[i][price], AHouseData[i][Houselevel], i);
UpdateDynamic3DTextLabelText(AHouseData[i][HouseLabel], COLOR_GREY, string4);
strdel(AHouseData[i][Owner], 0, 24); //Owner = "" Anyway why the pickup wont get deleted? :| old pickupwill stay
SavePlayer(playerid);
}
else
{
SendClientMessage(playerid, 0xFF0000AA, "You can not sell a house with cars assigned to it.");
}
else
{
SendClientMessage(playerid, COLOR_GREY, "This house is not owned by you!");
}
}
return 1;
}
}
Re: Command returns server unknown command. -
thimo - 19.01.2014
I am not using strcmp anywhere. Since I am aware that zcmd is faster i wont use strcmp.
Re: Command returns server unknown command. -
thimo - 19.01.2014
Thanks for trying Matrixgamer but it doesnt work. It has something to do with an array. But wich one is causing it? :S
Re: Command returns server unknown command. -
Avi Raj - 19.01.2014
Any other command which shows error like that same?
And if that command is in any FS, try to reloadfs from game 2-3 times.
Re: Command returns server unknown command. -
thimo - 19.01.2014
it is in a gamemode and its the only command wich does this
Re: Command returns server unknown command. -
Konstantinos - 19.01.2014
If you don't use the latest version of crashdetect, get it from here:
https://github.com/Zeex/samp-plugin-...ases/tag/v4.13
Compile with debug info so you can know the line caused the run time error:
https://github.com/Zeex/samp-plugin-...ith-debug-info
I believe it's caused by this line.
pawn Код:
HouseID = APlayerData[playerid][CurrentHouse];
If you do a debugging, you'll find out that HouseID is -1 and that it accesses element at negative index here:
pawn Код:
if (AHouseData[HouseID][VehicleIDs][CarSlot] != 0) // run time error
Re: Command returns server unknown command. -
thimo - 19.01.2014
Okay but how do i fix this then? Thanks a lot for that Konstantinos!
Re: Command returns server unknown command. -
Konstantinos - 19.01.2014
That depends on you. What do you want to do if CurrentHouse of a player is -1? Return an error for something (again, it depends on you and how you scripted it) or if you don't want to do anything, just check if it's not -1 and do your code.
An example for the last:
pawn Код:
if (HouseID != -1)
{
for (CarSlot = 0; CarSlot < 20; CarSlot++)
if (AHouseData[HouseID][VehicleIDs][CarSlot] != 0)
HouseHasCars = true;
}