Quantcast
Channel: SA-MP Forums
Viewing all articles
Browse latest Browse all 18226

Array problem

$
0
0
Alright so the problem is quite hard to explain.

I have this system where I can dynamicly add stuff to a shop. Now it works perfectly besides 1 problem, it will constantly return weapon 0 and price 0. Well basically everything as 0.

PHP Code:

case DIALOG_WEAPON_PURCHASE: {
            if(!
response) return true;
             for(new 
i=0MAX_SHOPSi++) {
                 new 
ShopInfo[i][ShopID];
                if(
GetPlayerMoney(playerid) < ShopData[z][listitem][ContentPrice]) return SCM(playerid,COLOR_RED,"You dont have enough money. You need %i to buy this",ShopData[i][listitem][ContentPrice]);
                  if(
IsPlayerInRangeOfPoint(playerid,5.0,ShopInfo[i][ShopX],ShopInfo[i][ShopY],ShopInfo[i][ShopZ])) {

                    
GivePlayerWeapon(playerid,ShopData[z][listitem][ContentWeapon],ShopData[z][listitem][ContentAmmo]);
                    
SCM(playerid,COLOR_RED,"You have purchased weapon ID: %i for %i$",ShopData[z][listitem][ContentWeapon],ShopData[z][listitem][ContentPrice]);
                    
GivePlayerMoney(playerid,ShopData[z][listitem][ContentPrice]);
                }
            }
        } 


Now to understand my code, look at this.
This is how i show them whats in the shop.

Every item is linked to certain shop ID (this part of the code works, the one above doesnt!)

PHP Code:

YCMD:buy(playerid,params[],help) {
    new 
string[50], mainstring[1024], resultsfound 0gunname[32];
    for(new 
i=0MAX_SHOPSi++) {
        if(
IsPlayerInRangeOfPoint(playerid,5.0,ShopInfo[i][ShopX],ShopInfo[i][ShopY],ShopInfo[i][ShopZ])) {
            for(new 
x=0MAX_CONTENT_DATAx++) {
                new 
ShopInfo[i][ShopID];
                if(
ShopData[z][x][ContentID] == ShopInfo[i][ShopID]) {
                    
GetWeaponName(ShopData[z][x][ContentWeapon],gunname,sizeof(gunname));
                    
format(string,sizeof(string),"%s\t%i\t%i$\n",gunname,ShopData[z][x][ContentAmmo],ShopData[z][x][ContentPrice]);
                    
strcat(mainstring,string);
                    
resultsfound += 1;
                }
            }
        }
    }
    if(
resultsfound == 0) return SendClientMessage(playerid,COLOR_RED,"No weapons are found for this shop");
    
    new 
finalstring[1100];
    
format(finalstring,sizeof(finalstring),"Weapon Name\t Ammo\t Price\n %s",mainstring);
    
ShowPlayerDialog(playerid,DIALOG_WEAPON_PURCHASEDIALOG_STYLE_TABLIST_HEADERS,"Pick a weapon to buy",finalstring,"Buy","Cancel");
    return 
true;



Basically my enum is like this

new ShopData[MAX_SHOPS][MAX_CONTENT_DATA][CON_DATA];

MAX SHOPS - bound to certain shop ID
MAX_CONTENT_DATA its own ID.

For example, loading from sql that also works
PHP Code:

public OnContentLoad() {
    new 
rows cache_num_rows();
    
    for(new 
i=0rowsi++) {
        new 
id cache_get_field_content_int(i,"ID");
        
ShopData[id][i][ContentKey] = cache_get_field_content_int(i,"Unique"); //unique Key ID
        
ShopData[id][i][ContentWeapon] = cache_get_field_content_int(i,"WeaponID");
        
ShopData[id][i][ContentID] = id;
        
ShopData[id][i][ContentPrice] = cache_get_field_content_int(i,"Price");
        
ShopData[id][i][ContentAmmo] = cache_get_field_content_int(i,"Ammo");
        
        
printf("Shop ID: %i :: Content linked ID: %i :: Content Unique ID: %i",id,ShopData[id][i][ContentID],ShopData[id][i][ContentKey]);
    }



Viewing all articles
Browse latest Browse all 18226

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>