Run time error 4: "Array index out of bounds"
#1

Crash Detect:
pawn Код:
[18:52:12] [debug] Run time error 4: "Array index out of bounds"
[18:52:12] [debug]  Accessing element at negative index -1
[18:52:12] [debug] AMX backtrace:
[18:52:12] [debug] #0 0000b4a4 in ?? (0xffffffff) from sicilian.amx
[18:52:12] [debug] #1 00017664 in public cmd_ahouse (0x00000000, 0x0010a270) from sicilian.amx
[18:52:12] [debug] #2 native CallLocalFunction () [00472ef0] from samp-server.exe
[18:52:12] [debug] #3 000005b4 in public OnPlayerCommandText (0x00000000, 0x0010a234) from sicilian.amx
/house
pawn Код:
COMMAND:house(playerid, params[]) // For owners of house
{
    new tmp[ 15 ], tmp2[ 15 ], tmp3[ 128 ];
    if(sscanf(params, "szz", tmp, tmp2, tmp3)) return SCP(playerid, "[ buy / sell / lock / rentprice / locker / dupekey / furniture]");
    new houseId = P_TEMP[playerid][tmphouse];
    if(!strcmp(tmp, "buy", true, 3))
    {
        if(IsPlayerOutHouse(playerid) == -1) return SendClientError(playerid, "You need to be outside a house to use this.");
        if(IsPlayerOutHouse(playerid)) houseId = IsPlayerOutHouse(playerid);
        if(House[houseId][sellprice] < 1) return SendClientError(playerid, "This house is not on sale");
        else
        {
            new PlayerCash = GetPlayerMoney(playerid);
            if(PlayerCash >= House[houseId][sellprice])
            {
                P_INFO[playerid][PMoney] -=House[houseId][sellprice];
                SendClientInfo(playerid, "You have purchased this house. Congradulations.");
                new pname[50];
                GetPlayerName(playerid, pname, sizeof(pname));
                format(SmllStr, sizeof(SmllStr), "Houses/HouseID-%d.ini", houseId);
                dini_Set(SmllStr, "owner", pname);
                dini_IntSet(SmllStr, "sellprice", 0);
                ReloadHouse(houseId);
            }
            else return SendClientError(playerid, "You do not have enough cash to make a purchase");
        }
    }
    else if(!strcmp(tmp, "sell", true, 4))
    {
        if(IsPlayerOutHouse(playerid) == -1) return SendClientError(playerid, "You need to be outside a house to use this.");
        if(IsPlayerOutHouse(playerid)) houseId = IsPlayerOutHouse(playerid);
       
        new pname[24];
        GetPlayerName(playerid, pname, sizeof(pname));
        if(strcmp(pname, House[houseId][owner], true)) return SendClientError(playerid, "You are not the owner of this house");

        new MaxPrice = strval(tmp2);
        new warning[50];
        format(warning, sizeof(warning), "A house can only be sold for $%d, please change amount.", MaxPriceAHouseCanBeSold);
        if(MaxPrice < 0 || MaxPrice > MaxPriceAHouseCanBeSold) return SendClientWarning(playerid, warning);
        format(SmllStr, sizeof(SmllStr), "Houses/HouseID-%d.ini", houseId);
        dini_IntSet(SmllStr, "sellprice", MaxPrice);
        new iStr[50];
        format(iStr, sizeof(iStr), "your house is now on sale for a price of $%s. (ID: %d)", Number_Format(MaxPrice), houseId);
        SendClientInfo(playerid, iStr);
        ReloadHouse(houseId);
    }
    else if(!strcmp(tmp, "rentprice", true, 9))
    {
        if(IsPlayerOutHouse(playerid) == -1) return SendClientError(playerid, "You need to be outside a house to use this.");
        if(IsPlayerOutHouse(playerid)) houseId = IsPlayerOutHouse(playerid);
       
        new pname[24];
        GetPlayerName(playerid, pname, sizeof(pname));
        if(strcmp(pname, House[houseId][owner], true)) return SendClientError(playerid, "You are not the owner of this house");

        new Rent = strval(tmp2);
        if(Rent >= 1500) return SendClientError(playerid, "Maximum rent of $1,500.");
        format(SmllStr, sizeof(SmllStr), "Houses/HouseID-%d.ini", houseId);
        dini_IntSet(SmllStr, "rentprice", Rent);

        new iStr[50];
        format(iStr, sizeof(iStr), "your house is now rentable for a price of $%s. (ID: %d)", Number_Format(Rent), houseId);
        SendClientInfo(playerid, iStr);
        ReloadHouse(houseId);
    }
    else if(!strcmp(tmp, "rentroom", true, 8))
    {
        if(IsPlayerOutHouse(playerid) == -1) return SendClientError(playerid, "You need to be outside a house to use this.");
        if(IsPlayerOutHouse(playerid)) houseId = IsPlayerOutHouse(playerid);

        new Rent = House[houseId][rentprice], PlayerCash = GetPlayerMoney(playerid);
        if(Rent == 0) return SendClientError(playerid, "This house is not rentable.");
        if(PlayerCash < Rent) return SendClientError(playerid, "You do not have enough cash to rent here.");
        else
        {
            P_INFO[playerid][houseID] = houseId;
            new iStr[50], zone[128];
            GetZone(House[houseId][outX],House[houseId][outY],House[houseId][outZ],zone);
            format(iStr, sizeof(iStr), "you are now renting at a house located in %s for a price of $%s. (ID: %d)", zone, Number_Format(Rent), houseId);
            SendClientInfo(playerid, iStr);
            P_INFO[playerid][PMoney] -=Rent;
        }
    }
    else if(!strcmp(tmp, "locker", true, 6))
    {
        if(IsPlayerOutHouse(playerid) == -1) return SendClientError(playerid, "You need to be outside a house to use this.");
        if(IsPlayerOutHouse(playerid)) houseId = IsPlayerOutHouse(playerid);

        if(House[houseId][closed] == 1)return SendClientError(playerid, "This house locked is currently closed.");
        else
        {
            if(!strlen(tmp2) || IsNumeric(tmp2)) return SCP(playerid, "[take / store]");
            else if(!strcmp(tmp2, "take", true, 4))
            {
                if(!strlen(tmp3) || !IsNumeric(tmp3) || strlen(tmp3) > 9) return SCP(playerid, "[amount]");
                new Amount = strval(tmp3);
                if(Amount > House[houseId][housecash]) return SendClientError(playerid, "Not enough inside the house.");
                House[houseId][housecash] -= Amount;
                P_INFO[playerid][PMoney] += Amount;
                format(SmllStr, sizeof(SmllStr), "You have taken $%s from %d house locker.", Number_Format(Amount), houseId);
                SendClientInfo(playerid, SmllStr);
            }
            else if(!strcmp(tmp2, "store", true, 5))
            {

            }
            else return SCP(playerid, "[take / store]");
        }
    }
    else if(!strcmp(tmp, "lock", true, 4))
    {
        if(IsPlayerOutHouse(playerid) == -1) return SendClientError(playerid, "You need to be outside a house to use this.");
        if(IsPlayerOutHouse(playerid)) houseId = IsPlayerOutHouse(playerid);

        new pname[24];
        GetPlayerName(playerid, pname, sizeof(pname));
        if(strcmp(pname, House[houseId][owner], true)) return SendClientError(playerid, "You are not the owner of this house.");

        if(House[houseId][closed] == 1)
        {
            House[houseId][closed] = 0;
            SendClientInfo(playerid, "Opened, please note that anyone can enter your house and take cash.");
            return 1;
        }
        else
        {
            House[houseId][closed] = 1;
            SendClientInfo(playerid, "Closed, your house is secure.");
            return 1;
        }
    }
    else if(!strcmp(tmp, "dupekey", true, 7))
    {
        if(IsPlayerOutHouse(playerid) == -1) return SendClientError(playerid, "You need to be outside a house to use this.");
        if(IsPlayerOutHouse(playerid)) houseId = IsPlayerOutHouse(playerid);

        new pname[24];
        GetPlayerName(playerid, pname, sizeof(pname));
        if(strcmp(pname, House[houseId][owner], true)) return SendClientError(playerid, "You are not the owner of this house");
        else
        {
            if(!strlen(tmp2) || IsNumeric(tmp2)) return SCP(playerid, "[take / set]");
            else if(!strcmp(tmp2, "take", true, 4))
            {
                format(SmllStr, sizeof(SmllStr), "Houses/HouseID-%d.ini", houseId);
                format(LrgStr, sizeof(LrgStr), "Dupekey has been taken from %s", NoUnderscore(dini_Get(SmllStr, "dupekey")));
                SendClientInfo(playerid, LrgStr);
                dini_Set(SmllStr, "dupekey", "None");
                ReloadHouse(houseId);
            }
            else if(!strcmp(tmp2, "set", true, 3))
            {
                if(!strlen(tmp3) || !IsNumeric(tmp3) || strlen(tmp3) > MAX_PLAYERS) return SCP(playerid, "[playerid]");
                new playerID = strval(tmp3);
                if(!IsPlayerConnected(playerID)) return SendClientError(playerid, PLAYER_NOT_FOUND);
                GetPlayerName(playerID, pname, sizeof(pname));
                format(SmllStr, sizeof(SmllStr), "Houses/HouseID-%d.ini", houseId);
                dini_Set(SmllStr, "dupekey", pname);
                ReloadHouse(houseId);
            }
            else return SCP(playerid, "[take / set]");
        }
    }
    else return SCP(playerid, "[ buy / sell / lock / rentprice / locker / dupekey ]");
    return 1;
}
Reply


Messages In This Thread
Run time error 4: "Array index out of bounds" - by Brandon_More - 10.05.2014, 17:40
Re: Run time error 4: "Array index out of bounds" - by Konstantinos - 10.05.2014, 17:45
Re: Run time error 4: "Array index out of bounds" - by Brandon_More - 10.05.2014, 17:52

Forum Jump:


Users browsing this thread: 1 Guest(s)