Command problem
#1

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?
Reply
#2

Haven't you tried doing this?:

PHP код:
CMD:sellgarage(playeridparams[])
{
    new 
GarageIDprice;
    if(
sscanf(params"ii"GarageIDprice)) return SCM(playeridCOLOR_BELGREEN"» [USAGE]: /sellgarage [Garage ID] [Price]");
    if(!
GarageInfo[GarageID][garageExists]) return SCM(playeridCOLOR_ERROR"» You have specified an invalid garage ID.");
    if(
price || price 999999) return SCM(playeridCOLOR_ERROR"» Invalid price.");
    if(
DoesPlayerOwnsGarage(playeridGarageID) == 0) return SCM(playeridCOLOR_ERROR"» You are not the owner of this garage.");
    
GarageInfo[GarageID][SellPlayerPrice] = price;
    
Garage_Update(GarageID);
    
    
SCMEX(playeridCOLOR_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), playeridprice);
    return 
1;

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)