Advertisement
whitetiiger

EasyScripting System V2.0 sa-mp.de

Jul 12th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.81 KB | None | 0 0
  1. /*
  2. @autor whitetiiger
  3. @time 12.07.2016 9:48Uhr
  4. @table houses
  5. @version 1.0
  6. @ext OnFactionFinish()
  7. */
  8. #define MAX_FACTION [Hier Maximale Anzahl eintragen]
  9.  
  10.  
  11. enum faction_data
  12. {
  13.     bool:fdActive,
  14.     fdId,
  15.     fdUser_id,
  16.     Float:fdPosX,
  17.     Float:fdPosY,
  18.     Float:fdPosZ,
  19.     Float:fdPrice,
  20.    
  21. }
  22. new FactionData[MAX_FACTION][faction_data];
  23.  
  24.  
  25.  
  26. stock LoadAllFaction()
  27. {
  28.     new query[128];
  29.     format(query, 128, "SELECT * FROM houses");
  30.     mysql_tquery(Handle, query, "OnLoadAllFaction", "");
  31.     return 1;
  32. }
  33.  
  34. forward OnLoadAllFaction();
  35. public OnLoadAllFaction()
  36. {
  37.     new rows, fields;
  38.     cache_get_data(rows, fields, Handle);
  39.     for(new i = 0; i < rows; i++)
  40.     {
  41.         new factionid = GetFreeFactionID();
  42.         if(factionid == -1) return -1;
  43.         FactionData[factionid][fdId] = cache_get_field_content_int(i, "id", Handle);
  44.         FactionData[factionid][fdUser_id] = cache_get_field_content_int(i, "user_id", Handle);
  45.         FactionData[factionid][fdPosX] = cache_get_field_content_float(i,"posX",Handle);
  46.         FactionData[factionid][fdPosY] = cache_get_field_content_float(i,"posY",Handle);
  47.         FactionData[factionid][fdPosZ] = cache_get_field_content_float(i,"posZ",Handle);
  48.         FactionData[factionid][fdPrice] = cache_get_field_content_float(i,"price",Handle);
  49.         OnFactionFinish(factionid);
  50.     }
  51.     return 1;
  52. }
  53.  
  54. stock LoadFactionByID(Id)
  55. {
  56.     new query[128];
  57.     format(query, 128, "SELECT * FROM houses WHERE id = '%d'",Id);
  58.     mysql_tquery(Handle, query, "OnLoadFactionByID", "");
  59.     return 1;
  60. }
  61.  
  62. forward OnLoadFactionByID();
  63. public OnLoadFactionByID()
  64. {
  65.     new factionid = GetFreeFactionID();
  66.     if(factionid == -1) return -1;
  67.    
  68.     FactionData[factionid][fdId] = cache_get_field_content_int(0, "id", Handle);
  69.     FactionData[factionid][fdUser_id] = cache_get_field_content_int(0, "user_id", Handle);
  70.     FactionData[factionid][fdPosX] = cache_get_field_content_float(0,"posX",Handle);
  71.     FactionData[factionid][fdPosY] = cache_get_field_content_float(0,"posY",Handle);
  72.     FactionData[factionid][fdPosZ] = cache_get_field_content_float(0,"posZ",Handle);
  73.     FactionData[factionid][fdPrice] = cache_get_field_content_float(0,"price",Handle);
  74.     OnFactionFinish(factionid);
  75.     return 1;
  76. }
  77.  
  78. stock OnFactionFinish(factionid)
  79. {
  80.     FactionData[factionid][fdActive] = true;
  81.     return 1;
  82. }
  83.  
  84. stock ReloadFactionByID(factionid)
  85. {
  86.     DestroyFaction(factionid);
  87.     LoadFactionByID(FactionData[factionid][fdId]);
  88.     return 1;
  89. }
  90.  
  91. stock CreateFaction() Hier Parameter anpassen!
  92. {
  93.     new factionid = GetFreeFactionID(), Float:Pos[3];
  94.     if(factionid == -1) return -1;
  95.     GetPlayerPos(playerid, Pos[0], Pos[1], Pos[2]);
  96.     new query[128]; Länge anpassen!
  97.     format(query, sizeof(query), "INSERT INTO `houses`(`user_id`, `posX`, `posY`, `posZ`, `price`) VALUES ('%d', '%f', '%f', '%f', '%f')",value);
  98.     mysql_tquery(Handle, query, "OnCreateFaction", "");
  99.     return factionid;
  100. }
  101.  
  102. forward OnCreateFaction();
  103. public OnCreateFaction()
  104. {
  105.     LoadFactionByID(cache_insert_id());
  106.     return 1;
  107. }
  108. stock SaveFaction(factionid)
  109. {
  110.     new query[177];
  111.     format(query,sizeof(query),"UPDATE `houses` SET  `user_id` = '%d',  `posX` = '%f',  `posY` = '%f',  `posZ` = '%f',  `price` = '%f' WHERE id='%d'", FactionData[factionid][fdUser_id],  FactionData[factionid][fdPosX],  FactionData[factionid][fdPosY],  FactionData[factionid][fdPosZ],  FactionData[factionid][fdPrice], FactionData[factionid][fdId]);
  112.     mysql_tquery(Handle, query, "", "");
  113.     return 1;
  114. }
  115.  
  116.  
  117. stock DeleteFaction(factionid)
  118. {
  119.     if(FactionData[factionid][fdActive] == false) return -2;
  120.     new query[128];
  121.     format(query, 128, "DELETE FROM `houses` WHERE id = '%d'",FactionData[factionid][fdId]);
  122.     mysql_tquery(Handle, query, "", "");
  123.     FactionData[factionid][fdActive] = false;
  124.     return 1;
  125. }
  126.  
  127. stock DestroyFaction(factionid)
  128. {
  129.     if(FactionData[factionid][fdActive] == false) return -2;
  130.     FactionData[factionid][fdActive] = false;
  131.     return 1;
  132. }
  133.  
  134. stock GetFreeFactionID()
  135. {
  136.     for(new factionid=0; factionid<MAX_FACTION; factionid++)
  137.     {
  138.         if(FactionData[factionid][fdActive] == true) continue;
  139.         return factionid;
  140.     }
  141.     return -1;
  142. }
  143.  
  144. stock GetFactionCount()
  145. {
  146.     new count = 0;
  147.     for(new factionid=0; factionid<MAX_FACTION; factionid++)
  148.     {
  149.         if(FactionData[factionid][fdActive] == false) continue;
  150.         count ++;
  151.     }
  152.     return count;
  153. }
  154.  
  155. stock getNearstFaction(playerid) {
  156.     new x = -1, Float: distanz[2];
  157.     for(new factionid; factionid <MAX_FACTION; factionid++) {
  158.         distanz[0] = GetPlayerDistanceFromPoint(playerid, FactionData[factionid][fdPosX], FactionData[factionid][fdPosY], FactionData[factionid][fdPosZ]);
  159.         if(FactionData[factionid][fdActive] == true && distanz[0] < distanz[1]) x = factionid, distanz[1] = distanz[0];
  160.     }
  161.     return x;
  162. }
  163.  
  164. stock GetFactionID(dbID)
  165. {
  166.     for(new factionid=0; factionid <MAX_FACTION; factionid++)
  167.     {
  168.         if(FactionData[factionid][fdActive] == false) continue;
  169.         if(dbID != FactionData[factionid][fdId]) continue;
  170.         return factionid;
  171.     }
  172.     return -1;
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement