Array problem
#2

Since content data are mixed up you need to count every time an item from that shop appears and if it equals the listitem, then give the weapon etc.

PHP Code:
if (!response) return true;
new 
count_listitem = -1z;
for (new 
0MAX_SHOPSi++)
{
    if (
IsPlayerInRangeOfPoint(playerid5.0ShopInfo[i][ShopX], ShopInfo[i][ShopY], ShopInfo[i][ShopZ]))
    {
        for (new 
0MAX_CONTENT_DATAx++)
        {
            
ShopInfo[i][ShopID];
            if (
ShopData[z][x][ContentID] == ShopInfo[i][ShopID])
            {
                if (++
count_listitem == listitem)
                {
                    if (
GetPlayerMoney(playerid) < ShopData[z][listitem][ContentPrice]) return SCM(playeridCOLOR_RED"You dont have enough money. You need %i to buy this"ShopData[i][listitem][ContentPrice]);
                    
GivePlayerWeapon(playeridShopData[z][listitem][ContentWeapon], ShopData[z][listitem][ContentAmmo]);
                    
SCM(playeridCOLOR_RED"You have purchased weapon ID: %i for %i$"ShopData[z][listitem][ContentWeapon], ShopData[z][listitem][ContentPrice]);
                    
GivePlayerMoney(playeridShopData[z][listitem][ContentPrice]);
                    break;
                }
            }
        }
    }

Unfortunately, you'll have to loop again and check which shop it is. A per-player variable would be useful I guess if there are many shops.

EDIT: Added money check, forgot it.
Reply


Messages In This Thread
Array problem - by TwinkiDaBoss - 15.06.2016, 19:23
Re: Array problem - by Konstantinos - 15.06.2016, 19:35
Re: Array problem - by TwinkiDaBoss - 15.06.2016, 19:40
Re: Array problem - by Konstantinos - 15.06.2016, 19:48
Re: Array problem - by TwinkiDaBoss - 15.06.2016, 19:57
Re: Array problem - by Konstantinos - 15.06.2016, 20:05
Re: Array problem - by TwinkiDaBoss - 15.06.2016, 20:13

Forum Jump:


Users browsing this thread: 1 Guest(s)