Advertisement
Guest User

Loading

a guest
Jun 14th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.52 KB | None | 0 0
  1. // Load all the rows from the database
  2. stock Business_LoadTableRows()
  3. {
  4.     mysql_iquery_s(
  5.         str_format(
  6.             "SELECT `b`.`*`, `u`.`NAME` AS `owner_name` \
  7.            FROM `business_data` b \
  8.            LEFT JOIN `users` u \
  9.                ON `b`.`owner_id` = `u`.`ID` \
  10.            WHERE \
  11.                `b`.`deleted` = '0'",
  12.         )
  13.     );    
  14.  
  15.     new rows = cache_get_row_count();
  16.  
  17.     if(rows) {
  18.         // Loop through all the rows
  19.         for(new i = 0; i < rows; i++) {
  20.             new Map: data = map_new();
  21.  
  22.             // Sets the current database id
  23.             new BusinessDBID: dbid;
  24.             dbid = BusinessDBID: cache_get_field_content_int(i, "id");
  25.             Business_SetDatabaseID(data, dbid);
  26.  
  27.             // Sets the name
  28.             new name[BUSINESS_MAX_NAME];
  29.             cache_get_field_content(i, "name", name);
  30.             Business_SetName(data, name);
  31.  
  32.             // Sets the type
  33.             new BusinessType: type;
  34.             type = BusinessType: cache_get_field_content_int(i, "type");
  35.             Business_SetType(data, type);
  36.  
  37.             // Sets the subtype
  38.             new BusinessSubtype: subtype;
  39.             subtype = BusinessSubtype: cache_get_field_content_int(i, "subtype");
  40.             Business_SetSubtype(data, subtype);
  41.  
  42.             // Sets the owners id
  43.             new PlayerDBID: owner_dbid;
  44.             owner_dbid = PlayerDBID: cache_get_field_content_int(i, "owner_id");
  45.             Business_SetOwnerDatabaseID(data, owner_dbid);
  46.  
  47.             // Sets the owners name
  48.             if(owner_dbid != 0) {
  49.                 new owner_name[MAX_PLAYERS];
  50.                 cache_get_field_content(i, "owner_name", owner_name);
  51.                 Business_SetOwnerName(data, owner_name);
  52.             }
  53.  
  54.             // Sets the price amount
  55.             new price;
  56.             price = cache_get_field_content_int(i, "price");
  57.             Business_SetPrice(data, price);
  58.  
  59.             // Sets the stock amount
  60.             new stock_amt;
  61.             stock_amt = cache_get_field_content_int(i, "stock");
  62.             Business_SetStock(data, stock_amt);
  63.  
  64.             // Sets the money
  65.             new money;
  66.             money = cache_get_field_content_int(i, "money");
  67.             Business_SetMoney(data, money);
  68.  
  69.             // Sets the tax amount
  70.             new tax_amt;
  71.             tax_amt = cache_get_field_content_int(i, "tax");
  72.             Business_SetTax(data, tax_amt);
  73.  
  74.             // Sets the security level
  75.             new security_level;
  76.             security_level = cache_get_field_content_int(i, "security_level");
  77.             Business_SetSecurityLevel(data, security_level);
  78.  
  79.             // Sets the entrance position
  80.             new
  81.                 Float: entrance_x,
  82.                 Float: entrance_y,
  83.                 Float: entrance_z,
  84.                 Float: entrance_a,
  85.                 entrance_int
  86.             ;
  87.  
  88.             entrance_x = cache_get_field_content_float(i, "entrance_x");
  89.             entrance_y = cache_get_field_content_float(i, "entrance_y");
  90.             entrance_z = cache_get_field_content_float(i, "entrance_z");
  91.             entrance_a = cache_get_field_content_float(i, "entrance_a");
  92.             entrance_int = cache_get_field_content_int(i, "entrance_int");
  93.  
  94.             Business_SetEntrancePosition(
  95.                 data,
  96.                 entrance_x,
  97.                 entrance_y,
  98.                 entrance_z,
  99.                 entrance_a,
  100.                 entrance_int,
  101.                 0
  102.             );
  103.  
  104.             // Sets the exit position
  105.             new
  106.                 Float: exit_x,
  107.                 Float: exit_y,
  108.                 Float: exit_z,
  109.                 Float: exit_a,
  110.                 exit_int,
  111.                 exit_vw
  112.             ;
  113.  
  114.             exit_x = cache_get_field_content_float(i, "exit_x");
  115.             exit_y = cache_get_field_content_float(i, "exit_y");
  116.             exit_z = cache_get_field_content_float(i, "exit_z");
  117.             exit_a = cache_get_field_content_float(i, "exit_a");
  118.             exit_int = cache_get_field_content_int(i, "exit_int");
  119.             exit_vw = VW_GetFreeID();
  120.  
  121.             Business_SetExitPosition(
  122.                 data,
  123.                 exit_x,
  124.                 exit_y,
  125.                 exit_z,
  126.                 exit_a,
  127.                 exit_int,
  128.                 exit_vw
  129.             );
  130.  
  131.             // Create a new instance
  132.             new BusinessIndex: index;
  133.             Business_CreateInstance(index, data);
  134.         }        
  135.     }
  136.  
  137.     return 1;
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement