Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- new shopitems = 0;
- // asta la pInfo
- enum pInfo {
- pBuys;
- }
- new PlayerInfo[MAX_PLAYERS][pInfo];
- #define pBuysx 10
- enum {
- DIALOG_SHOP,
- }
- enum shopInfo {
- shopItem[32],
- shopPrice,
- shopValue
- }
- new ShopInfo[20][shopInfo];
- public ongamemodeinit() {
- LoadShop();
- return 1;
- }
- function Update(playerid, varid) {
- gQuery[0] = EOS;
- switch(varid) {
- case pBuysx: format(gQuery, sizeof(gQuery), "UPDATE `users` SET `Buys`='%d' WHERE `ID`='%d'", PlayerInfo[playerid][pBuys], PlayerInfo[playerid][pSQLID]);
- }
- mysql_tquery(SQL, gQuery, "", "");
- return 1;
- }
- case DIALOG_SHOP: {
- if(!response) return 1;
- gString[0] = EOS;
- listitem++;
- if(PlayerInfo[playerid][pGold] < ShopInfo[listitem][shopPrice]) return SCMx(playerid, -1, "You don't have enough gold [%d required].", ShopInfo[listitem][shopPrice]);
- format(gString, sizeof(gString), "You bought item %s [%d value] with %d gold from shop.",ShopInfo[listitem][shopItem],ShopInfo[listitem][shopValue], ShopInfo[listitem][shopPrice]);
- SCM(playerid, -1, gString);
- PlayerInfo[playerid][pBuys]++;
- PlayerInfo[playerid][pGold] -= ShopInfo[listitem][shopPrice];
- mysql_format(SQL, gQuery, sizeof(gQuery), "UPDATE `users` SET `%s`+='%d' WHERE `ID`='%s'",ShopInfo[listitem][shopItem],ShopInfo[listitem][shopValue], PlayerInfo[playerid][pSQLID]);
- mysql_tquery(SQL, gQuery, "","");
- }
- function LoadShop() {
- gQuery[0] = EOS;
- new Cache: db = mysql_query (SQL, "SELECT * FROM `shop`");
- new x, result[128];
- for(new i = 0; i < cache_num_rows(); i++) {
- shopitems++;
- x = cache_get_field_content_int(i, "ID");
- ShopInfo[x][shopPrice] = cache_get_field_content_int(i, "shopPrice");
- ShopInfo[x][shopValue] = cache_get_field_content_int(i, "shopValue");
- cache_get_field_content(i, "shopItem", result); format(ShopInfo[x][shopItem], 32, result);
- }
- printf("Shop Items: %d", shopitems);
- cache_delete(db);
- return 1;
- }
- // unde incarcati voi totul despre player (adica acolo unde e cache_get_field_content_int) puneti si asta
- PlayerInfo[playerid][pBuys] = cache_get_field_content_int(0, "Buys");
- YCMD:shop(playerid, params[], help) {
- gString[0] = EOS;
- new dialog[128];
- strcat(dialog, "Item\tValue\tPrice\n");
- for(new i = 1; i <= shopitems; i++) {
- format(gString, sizeof(gString), "%s\t%d\t%d\n", ShopInfo[i][shopItem], ShopInfo[i][shopValue], ShopInfo[i][shopPrice]);
- strcat(dialog, gString);
- }
- ShowPlayerDialog(playerid, DIALOG_SHOP, DIALOG_STYLE_TABLIST_HEADERS, "Shop:", dialog, "Select", "Cancel");
- return 1;
- }
- YCMD:addshop(playerid, params[], help) {
- if(PlayerInfo[playerid][pAdmin] < 5) return StaffOnly(playerid, 6);
- new sItem[32], sValue, sPrice;
- gString[0] = EOS;
- gQuery[0] = EOS;
- if(sscanf(params, "iis[32]", sItem, sValue, sPrice)) return Usage(playerid, "/addshop <name> <value> <price>");
- mysql_format(SQL, gQuery, sizeof(gQuery), "INSERT INTO `shop` (`shopItem`,`shopValue`,`shopPrice`) VALUES ('%s','%d','%d')", sItem, sValue, sPrice);
- new Cache: result = mysql_query(SQL, gQuery);
- new i = cache_insert_id();
- cache_delete(result);
- format(ShopInfo[i][shopItem], 32, sItem);
- ShopInfo[i][shopValue] = sValue;
- ShopInfo[i][shopPrice] = sPrice;
- SCMx(playerid, -1, "Shop Item Added:\n Item: %s\n Value: %d\n Price: %d\n", sItem, sValue, sPrice);
- shopitems++;
- format(gString, sizeof(gString), "Admin %s[%d] added item %s[Stock:%d | Speed: %s] in table `shop`.",GetName(playerid),playerid,sItem, sValue, sPrice);
- AdminLogs(gString);
- return 1;
- }
- YCMD:deleteshop(playerid, params[], help) {
- if(PlayerInfo[playerid][pAdmin] < 5) return StaffOnly(playerid, 6);
- new sItem[32];
- if(sscanf(params, "s[32]", sItem)) return Usage(playerid, "/deleteshop <item name>");
- gQuery[0] = EOS;
- gString[0] = EOS;
- mysql_format(SQL, gQuery, sizeof(gQuery), "DELETE FROM `shop` WHERE `shopItem`='%s'", sItem);
- mysql_tquery(SQL, gQuery, "", "");
- SCMx(playerid, -1, "You deleted from table `shop` item '%s'.", sItem);
- format(gString, sizeof(gString), "Admin %s[%d] deleted item %s from table `shop`.",GetName(playerid),playerid,sItem);
- AdminLogs(gString);
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement