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: Command problem (
/showthread.php?tid=664194)
Command problem -
SymonClash - 21.02.2019
I made a garage system and i made also a /sellgarage command where players can sell their garage. Problem is, it doesn't work as it should.
pawn Код:
CMD:sellgarage(playerid, params[])
{
new GarageID, price;
if(sscanf(params, "ii", GarageID, price)) return SCM(playerid, COLOR_BELGREEN, "» [USAGE]: /sellgarage [Garage ID] [Price]");
if(!GarageInfo[GarageID][garageExists]) return SCM(playerid, COLOR_ERROR, "» You have specified an invalid garage ID.");
if(strcmp(GarageInfo[GarageID][Owner], ReturnPlayerName(playerid))) return SCM(playerid, COLOR_ERROR, "» You can't sell this garage because is not yours.");
if(price < 0 || price > 999999) return SCM(playerid, COLOR_ERROR, "» Invalid price.");
GarageInfo[GarageID][SellPlayerPrice] = price;
Garage_Update(GarageID);
SCMEX(playerid, COLOR_YELLOW, "» [GARAGE] Your garage has been put for sale for $%d!", price);
SCMTAEX(COLOR_YELLOW, "» [GARAGE] %s (%d) is selling their garage for $%d", ReturnPlayerName(playerid), playerid, price);
return 1;
}
In detail, i have a problem with the owner checking. As you can see i added a check to see if the player owns the garage he's trying to sell, but doesn't work. Even if is not the owner, he can sell it.
Fun fact:
I've also an /enter command, where a player can't enter the garage if he's not the owner. Therre is a loop inside to check it:
pawn Код:
CMD:enter(playerid, params[])
{
new GarageID;
for(GarageID = 1; GarageID < MAX_GARAGES; GarageID++)
{
if(IsValidDynamicPickup(GarageInfo[GarageID][PickupID]))
{
if(GarageInfo[GarageID][Owned] == 0) return SCM(playerid, COLOR_ERROR, "» You can't enter unowned garages.");
if(DoesPlayerOwnsGarage(playerid, GarageID) == 0)
{
SCM(playerid, COLOR_ERROR, "» You are not the owner of this garage.");
return 1;
}
return 1;
}
}
return 0;
}
So i've tried to copy this loop inside the /sellgarage command but getting "array index out of bounds (Referred to MAX_GARAGES) and command doesn't execute.
What's wrong?
Re: Command problem -
Undef1ned - 21.02.2019
Haven't you tried doing this?:
PHP код:
CMD:sellgarage(playerid, params[])
{
new GarageID, price;
if(sscanf(params, "ii", GarageID, price)) return SCM(playerid, COLOR_BELGREEN, "» [USAGE]: /sellgarage [Garage ID] [Price]");
if(!GarageInfo[GarageID][garageExists]) return SCM(playerid, COLOR_ERROR, "» You have specified an invalid garage ID.");
if(price < 0 || price > 999999) return SCM(playerid, COLOR_ERROR, "» Invalid price.");
if(DoesPlayerOwnsGarage(playerid, GarageID) == 0) return SCM(playerid, COLOR_ERROR, "» You are not the owner of this garage.");
GarageInfo[GarageID][SellPlayerPrice] = price;
Garage_Update(GarageID);
SCMEX(playerid, COLOR_YELLOW, "» [GARAGE] Your garage has been put for sale for $%d!", price);
SCMTAEX(COLOR_YELLOW, "» [GARAGE] %s (%d) is selling their garage for $%d", ReturnPlayerName(playerid), playerid, price);
return 1;
}