Advertisement
Guest User

Untitled

a guest
Aug 8th, 2018
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.13 KB | None | 0 0
  1. new shopitems = 0;
  2.  
  3. // asta la pInfo
  4. enum pInfo {
  5.     pBuys;
  6. }
  7. new PlayerInfo[MAX_PLAYERS][pInfo];
  8.  
  9. #define pBuysx 10
  10. enum {
  11.     DIALOG_SHOP,
  12. }
  13.  
  14. enum shopInfo {
  15.     shopItem[32],
  16.     shopPrice,
  17.     shopValue
  18. }
  19. new ShopInfo[20][shopInfo];
  20.  
  21. public ongamemodeinit() {
  22.     LoadShop();
  23.     return 1;
  24. }
  25.  
  26. function Update(playerid, varid) {
  27.     gQuery[0] = EOS;
  28.     switch(varid) {
  29.         case pBuysx: format(gQuery, sizeof(gQuery), "UPDATE `users` SET `Buys`='%d' WHERE `ID`='%d'", PlayerInfo[playerid][pBuys], PlayerInfo[playerid][pSQLID]);
  30.     }
  31.     mysql_tquery(SQL, gQuery, "", "");
  32.     return 1;
  33. }
  34.  
  35. case DIALOG_SHOP: {
  36.             if(!response) return 1;
  37.             gString[0] = EOS;
  38.             listitem++;
  39.             if(PlayerInfo[playerid][pGold] < ShopInfo[listitem][shopPrice]) return SCMx(playerid, -1, "You don't have enough gold [%d required].", ShopInfo[listitem][shopPrice]);
  40.             format(gString, sizeof(gString), "You bought item %s [%d value] with %d gold from shop.",ShopInfo[listitem][shopItem],ShopInfo[listitem][shopValue], ShopInfo[listitem][shopPrice]);
  41.             SCM(playerid, -1, gString);
  42.             PlayerInfo[playerid][pBuys]++;
  43.             PlayerInfo[playerid][pGold] -= ShopInfo[listitem][shopPrice];
  44.             mysql_format(SQL, gQuery, sizeof(gQuery), "UPDATE `users` SET `%s`+='%d' WHERE `ID`='%s'",ShopInfo[listitem][shopItem],ShopInfo[listitem][shopValue], PlayerInfo[playerid][pSQLID]);
  45.             mysql_tquery(SQL, gQuery, "","");
  46.         }
  47.  
  48.  
  49. function LoadShop() {
  50.     gQuery[0] = EOS;
  51.     new Cache: db = mysql_query (SQL, "SELECT * FROM `shop`");
  52.     new x, result[128];
  53.     for(new i = 0; i < cache_num_rows(); i++) {
  54.         shopitems++;
  55.         x = cache_get_field_content_int(i, "ID");
  56.         ShopInfo[x][shopPrice] = cache_get_field_content_int(i, "shopPrice");
  57.         ShopInfo[x][shopValue] = cache_get_field_content_int(i, "shopValue");
  58.  
  59.         cache_get_field_content(i, "shopItem", result); format(ShopInfo[x][shopItem], 32, result);
  60.     }
  61.     printf("Shop Items: %d", shopitems);
  62.     cache_delete(db);
  63.     return 1;
  64. }
  65.  
  66. // unde incarcati voi totul despre player (adica acolo unde e cache_get_field_content_int) puneti si asta
  67.  
  68. PlayerInfo[playerid][pBuys] = cache_get_field_content_int(0, "Buys");
  69.  
  70. YCMD:shop(playerid, params[], help) {
  71.     gString[0] = EOS;
  72.     new dialog[128];
  73.     strcat(dialog, "Item\tValue\tPrice\n");
  74.     for(new i = 1; i <= shopitems; i++) {
  75.         format(gString, sizeof(gString), "%s\t%d\t%d\n", ShopInfo[i][shopItem], ShopInfo[i][shopValue], ShopInfo[i][shopPrice]);
  76.         strcat(dialog, gString);
  77.     }
  78.     ShowPlayerDialog(playerid, DIALOG_SHOP, DIALOG_STYLE_TABLIST_HEADERS, "Shop:", dialog, "Select", "Cancel");
  79.     return 1;
  80. }
  81. YCMD:addshop(playerid, params[], help) {
  82.     if(PlayerInfo[playerid][pAdmin] < 5) return StaffOnly(playerid, 6);
  83.     new sItem[32], sValue, sPrice;
  84.     gString[0] = EOS;
  85.     gQuery[0] = EOS;
  86.     if(sscanf(params, "iis[32]", sItem, sValue, sPrice)) return Usage(playerid, "/addshop <name> <value> <price>");
  87.     mysql_format(SQL, gQuery, sizeof(gQuery), "INSERT INTO `shop` (`shopItem`,`shopValue`,`shopPrice`) VALUES ('%s','%d','%d')", sItem, sValue, sPrice);
  88.     new Cache: result = mysql_query(SQL, gQuery);
  89.     new i = cache_insert_id();
  90.     cache_delete(result);
  91.  
  92.     format(ShopInfo[i][shopItem], 32, sItem);
  93.     ShopInfo[i][shopValue] = sValue;
  94.     ShopInfo[i][shopPrice] = sPrice;
  95.  
  96.  
  97.     SCMx(playerid, -1, "Shop Item Added:\n Item: %s\n Value: %d\n Price: %d\n", sItem, sValue, sPrice);
  98.     shopitems++;
  99.     format(gString, sizeof(gString), "Admin %s[%d] added item %s[Stock:%d | Speed: %s] in table `shop`.",GetName(playerid),playerid,sItem, sValue, sPrice);
  100.     AdminLogs(gString);
  101.     return 1;
  102. }
  103.  
  104. YCMD:deleteshop(playerid, params[], help) {
  105.     if(PlayerInfo[playerid][pAdmin] < 5) return StaffOnly(playerid, 6);
  106.     new sItem[32];
  107.     if(sscanf(params, "s[32]", sItem)) return Usage(playerid, "/deleteshop <item name>");
  108.     gQuery[0] = EOS;
  109.     gString[0] = EOS;
  110.     mysql_format(SQL, gQuery, sizeof(gQuery), "DELETE FROM `shop` WHERE `shopItem`='%s'", sItem);
  111.     mysql_tquery(SQL, gQuery, "", "");
  112.     SCMx(playerid, -1, "You deleted from table `shop` item '%s'.", sItem);
  113.     format(gString, sizeof(gString), "Admin %s[%d] deleted item %s from table `shop`.",GetName(playerid),playerid,sItem);
  114.     AdminLogs(gString);
  115.     return 1;
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement