case DIALOG_WEAPON_PURCHASE: {
if(!response) return true;
for(new i=0; i < MAX_SHOPS; i++) {
new z = 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]);
}
}
}
YCMD:buy(playerid,params[],help) {
new string[50], mainstring[1024], resultsfound = 0, gunname[32];
for(new i=0; i < MAX_SHOPS; i++) {
if(IsPlayerInRangeOfPoint(playerid,5.0,ShopInfo[i][ShopX],ShopInfo[i][ShopY],ShopInfo[i][ShopZ])) {
for(new x=0; x < MAX_CONTENT_DATA; x++) {
new z = 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_PURCHASE, DIALOG_STYLE_TABLIST_HEADERS,"Pick a weapon to buy",finalstring,"Buy","Cancel");
return true;
}
public OnContentLoad() {
new rows = cache_num_rows();
for(new i=0; i < rows; i++) {
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]);
}
}
if (!response) return true;
new count_listitem = -1, z;
for (new i = 0; i < MAX_SHOPS; i++)
{
if (IsPlayerInRangeOfPoint(playerid, 5.0, ShopInfo[i][ShopX], ShopInfo[i][ShopY], ShopInfo[i][ShopZ]))
{
for (new x = 0; x < MAX_CONTENT_DATA; x++)
{
z = ShopInfo[i][ShopID];
if (ShopData[z][x][ContentID] == ShopInfo[i][ShopID])
{
if (++count_listitem == listitem)
{
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]);
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]);
break;
}
}
}
}
}
[21:55:05] Weapon ID: 0 :: Weapon Shop ID: 2 :: Content ID: 0
[21:55:07] Weapon ID: 0 :: Weapon Shop ID: 2 :: Content ID: 0
[21:55:22] Weapon ID: 0 :: Weapon Shop ID: 1 :: Content ID: 0
[21:55:23] Weapon ID: 0 :: Weapon Shop ID: 1 :: Content ID: 0
printf("Weapon ID: %i :: Weapon Shop ID: %i :: Content ID: %i",ShopData[z][listitem][ContentWeapon],i,ShopData[z][listitem][ContentID]);
YCMD:buy(playerid, params[], help)
{
new string[50], mainstring[1024], resultsfound = 0, gunname[32];
for (new i = 0; i < MAX_SHOPS; i++)
{
printf("DEBUG: /buy -> i: %i", i);
if (IsPlayerInRangeOfPoint(playerid, 5.0, ShopInfo[i][ShopX], ShopInfo[i][ShopY], ShopInfo[i][ShopZ]))
{
printf("DEBUG: /buy -> in range: %i", i);
for (new x = 0; x < MAX_CONTENT_DATA; x++)
{
new z = ShopInfo[i][ShopID];
printf("DEBUG: /buy -> x: %i & z: %i & ContentID: %i", x, z, ShopData[z][x][ContentID]);
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");
printf("DEBUG: /buy -> resultsfound: %i", resultsfound);
new finalstring[1100];
format(finalstring, sizeof(finalstring), "Weapon Name\t Ammo\t Price\n %s", mainstring);
ShowPlayerDialog(playerid, DIALOG_WEAPON_PURCHASE, DIALOG_STYLE_TABLIST_HEADERS, "Pick a weapon to buy", finalstring, "Buy", "Cancel");
return true;
}
#define MAX_CONTENT_HOLD 255
new Item_CurrentlyBrowing[MAX_PLAYERS][MAX_CONTENT_HOLD],
Price_CurrentlyBrowing[MAX_PLAYERS][MAX_CONTENT_HOLD],
Ammo_CurrentlyBrowing[MAX_PLAYERS][MAX_CONTENT_HOLD];
Item_CurrentlyBrowing[playerid][resultsfound] = ShopData[z][x][ContentWeapon];
Price_CurrentlyBrowing[playerid][resultsfound] = ShopData[z][x][ContentAmmo];
Ammo_CurrentlyBrowing[playerid][resultsfound] = ShopData[z][x][ContentPrice];
resultsfound += 1;
GivePlayerWeapon(playerid,Item_CurrentlyBrowing[playerid][listitem],Ammo_CurrentlyBrowing[playerid][listitem]);
GivePlayerMoney(playerid,-Price_CurrentlyBrowing[playerid][listitem]);
new string[128];
format(string,sizeof(string),"Weapon ID: %i :: Price; %i$ :: Ammo: %i",Item_CurrentlyBrowing[playerid][listitem],Ammo_CurrentlyBrowing[playerid][listitem],Price_CurrentlyBrowing[playerid][listitem]);
SendClientMessage(playerid,COLOR_RED,string);
A per-player variable would be useful I guess if there are many shops. |