F1N4L_

[INC] Properties System v1.5 (FINAL VERSION) [MySQL R39-4]

Jun 16th, 2016
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.56 KB | None | 0 0
  1. #include <a_samp>
  2. #include <zcmd>
  3. #include <a_mysql>
  4.  
  5. #define TABLE_PROP "PROPERTIES"
  6. #define ID_PROP "ID"
  7. #define NAME_PROP "NAME"
  8. #define COST_PROP "PROP COMPRA"
  9. #define SELL_PROP "PROP Sell"
  10. #define VALOR_LUCRE_PROP "PROP LUCRE"
  11. #define LUCRE_PROP "LUCRE"
  12. #define OWNER_PROP "OWNER"
  13. #define POSX_PROP "POS X"
  14. #define POSY_PROP "POS Y"
  15. #define POSZ_PROP "POS Z"
  16.  
  17. #define MAX_PROPS 100
  18. #define TEMPO_Lucre 1
  19. #define DEBUG_PROP true
  20.  
  21. new
  22. MySQL_Connection;
  23.  
  24. new
  25. pInfoPropName[MAX_PROPS][20],
  26. pInfoPropBuyPrice[MAX_PROPS],
  27. pInfoPropSellPrice[MAX_PROPS],
  28. pInfoPropLucre_[MAX_PROPS],
  29. pInfoPropLucre[MAX_PROPS],
  30. pInfoPropTimeLucre[MAX_PROPS],
  31. pInfoPropOwner[MAX_PROPS][MAX_PLAYER_NAME],
  32. Float:pInfoPropPosX[MAX_PROPS],
  33. Float:pInfoPropPosY[MAX_PROPS],
  34. Float:pInfoPropPosZ[MAX_PROPS],
  35. bool:pInfoPropIdCheck[MAX_PROPS];
  36.  
  37. new
  38. pInfoPickupProp[MAX_PROPS],
  39. Text3D:pInfoLabelProp[MAX_PROPS];
  40.  
  41. new
  42. Format_MySQL[600],
  43. Format_Label[150],
  44. GetPropLucre;
  45.  
  46. public OnGameModeExit()
  47. {
  48. mysql_close(MySQL_Connection);
  49.  
  50. #if defined Prop_OnGameModeExit
  51. return Prop_OnGameModeExit();
  52. #else
  53. return 1;
  54. #endif
  55. }
  56. #if defined _ALS_OnGameModeExit
  57. #undef OnGameModeExit
  58. #else
  59. #define _ALS_OnGameModeExit
  60. #endif
  61. #define OnGameModeExit Prop_OnGameModeExit
  62. #if defined Prop_OnGameModeExit
  63. forward Prop_OnGameModeExit();
  64. #endif
  65.  
  66. stock mysql_prop_connect(const Server_Host[], const Server_User[], const Server_Database[], const Server_Password[])
  67. {
  68. MySQL_Connection = mysql_connect(Server_Host, Server_User, Server_Database, Server_Password);
  69.  
  70. mysql_format(MySQL_Connection, Format_MySQL, sizeof Format_MySQL, " \
  71. CREATE TABLE IF NOT EXISTS `"TABLE_PROP"` ( \
  72. `"ID_PROP"` INT(5) PRIMARY KEY NOT NULL, \
  73. `"NAME_PROP"` VARCHAR(20) NOT NULL DEFAULT 'N/A', \
  74. `"COST_PROP"` INT(10) NOT NULL DEFAULT '0', \
  75. `"SELL_PROP"` INT(10) NOT NULL DEFAULT '0', \
  76. `"VALOR_LUCRE_PROP"` INT(10) NOT NULL DEFAULT '0', \
  77. `"LUCRE_PROP"` INT(10) NOT NULL DEFAULT '0', \
  78. `"OWNER_PROP"` VARCHAR(24) NOT NULL DEFAULT 'N/A', \
  79. `"POSX_PROP"` FLOAT NOT NULL DEFAULT '0.0', \
  80. `"POSY_PROP"` FLOAT NOT NULL DEFAULT '0.0', \
  81. `"POSZ_PROP"` FLOAT NOT NULL DEFAULT '0.0')");
  82. mysql_query(MySQL_Connection, Format_MySQL);
  83.  
  84. #if DEBUG_PROP == true
  85. printf("\nCONNECTION MYSQL - TABLE: %s\n", TABLE_PROP);
  86. #endif
  87.  
  88. LoadProps();
  89.  
  90. return 1;
  91. }
  92. stock CreateProp(Name_Prop[], Price_Buy_Prop, Price_Sell_Prop, Lucre_Prop, Owner_Prop[], Float:PosX_Prop, Float:PosY_Prop, Float:PosZ_Prop)
  93. {
  94. new ID_Prop;
  95.  
  96. for(new p = 0; p < MAX_PROPS; p ++)
  97. {
  98. if(pInfoPropIdCheck[p] == false)
  99. {
  100. pInfoPropIdCheck[p] = true;
  101. ID_Prop = p;
  102. break;
  103. }
  104. }
  105.  
  106. if(strcmp("N/A", OWNER_PROP, true) == 0) format(Format_Label, sizeof Format_Label, "ID: %i\nName: %s\nOwner: %s\nPrice: R$ %i,00\nLucre: R$ %i,00", ID_Prop, Name_Prop, Owner_Prop, Price_Buy_Prop, Lucre_Prop);
  107. else format(Format_Label, sizeof Format_Label, "ID: %i\nName: %s\nOwner: %s\nLucre: R$ 0,00 (Generating)", ID_Prop, Name_Prop, Owner_Prop);
  108.  
  109. pInfoPickupProp[ID_Prop] = CreatePickup(1210, 1, PosX_Prop, PosY_Prop, PosZ_Prop);
  110. pInfoLabelProp[ID_Prop] = Create3DTextLabel(Format_Label, -1, PosX_Prop, PosY_Prop, PosZ_Prop + 1, 50.0, 0, 1);
  111.  
  112. mysql_format(MySQL_Connection, Format_MySQL, sizeof Format_MySQL, " \
  113. INSERT INTO `"TABLE_PROP"` ( \
  114. `"ID_PROP"`, \
  115. `"NAME_PROP"`, \
  116. `"COST_PROP"`, \
  117. `"SELL_PROP"`, \
  118. `"VALOR_LUCRE_PROP"`, \
  119. `"LUCRE_PROP"`, \
  120. `"OWNER_PROP"`, \
  121. `"POSX_PROP"`, \
  122. `"POSY_PROP"`, \
  123. `"POSZ_PROP"`) \
  124. VALUES ('%i', '%s', '%i', '%i', '%i', '0', '%s', '%f', '%f', '%f')", ID_Prop, Name_Prop, Price_Buy_Prop, Price_Sell_Prop, Lucre_Prop, Owner_Prop, PosX_Prop, PosY_Prop, PosZ_Prop);
  125. mysql_query(MySQL_Connection, Format_MySQL);
  126.  
  127. strcat((pInfoPropName[ID_Prop][0] = '\0', pInfoPropName[ID_Prop]), Name_Prop);
  128. pInfoPropBuyPrice[ID_Prop] = Price_Buy_Prop;
  129. pInfoPropSellPrice[ID_Prop] = Price_Sell_Prop;
  130. pInfoPropLucre_[ID_Prop] = Lucre_Prop;
  131. pInfoPropLucre[ID_Prop] = 0;
  132. strcat((pInfoPropOwner[ID_Prop][0] = '\0', pInfoPropOwner[ID_Prop]), OWNER_PROP);
  133. pInfoPropPosX[ID_Prop] = PosX_Prop;
  134. pInfoPropPosY[ID_Prop] = PosY_Prop;
  135. pInfoPropPosZ[ID_Prop] = PosZ_Prop;
  136. pInfoPropIdCheck[ID_Prop] = true;
  137.  
  138. #if DEBUG_PROP == true
  139. printf("CreateProp: ID: %i | Name: %s | Cost: R$ %i,00 | Sell: R$ %i,00 | Lucre: R$ %i,00 | Owner: %s", ID_Prop, NAME_PROP, Price_Buy_Prop, Price_SELL_PROP, LUCRE_PROP, OWNER_PROP);
  140. #endif
  141. return 1;
  142. }
  143. stock DeleteProp(ID_Prop)
  144. {
  145. if(pInfoPropIdCheck[ID_Prop] == false) return false;
  146.  
  147. for(new p = 0; p < MAX_PROPS; p ++)
  148. {
  149. if(pInfoPropIdCheck[p] == false) continue;
  150.  
  151. if(pInfoPropIdCheck[ID_Prop] == true)
  152. {
  153. Delete3DTextLabel(pInfoLabelProp[ID_Prop]);
  154. DestroyPickup(pInfoPickupProp[ID_Prop]);
  155.  
  156. mysql_format(MySQL_Connection, Format_MySQL, sizeof Format_MySQL, "DELETE FROM `"TABLE_PROP"` WHERE `"ID_PROP"` = '%i'", ID_Prop);
  157. mysql_query(MySQL_Connection, Format_MySQL, false);
  158.  
  159. pInfoPropName[ID_Prop][0] = '\0';
  160. pInfoPropBuyPrice[ID_Prop] = 0;
  161. pInfoPropSellPrice[ID_Prop] = 0;
  162. pInfoPropTimeLucre[ID_Prop] = 0;
  163. pInfoPropLucre_[ID_Prop] = 0;
  164. pInfoPropLucre[ID_Prop] = 0;
  165. pInfoPropOwner[ID_Prop][0] = '\0';
  166. pInfoPropPosX[ID_Prop] = 0;
  167. pInfoPropPosY[ID_Prop] = 0;
  168. pInfoPropPosZ[ID_Prop] = 0;
  169. pInfoPropIdCheck[ID_Prop] = false;
  170.  
  171. break;
  172. }
  173. }
  174.  
  175. #if DEBUG_PROP == true
  176. printf("DeleteProp: %i", ID_Prop);
  177. #endif
  178. return 1;
  179. }
  180. stock BuyProp(Owner_Prop[], ID_Prop)
  181. {
  182. if(pInfoPropIdCheck[ID_Prop] == false) return false;
  183.  
  184. pInfoPropTimeLucre[ID_Prop] = TEMPO_Lucre * 60 + gettime();
  185.  
  186. strcat((pInfoPropOwner[ID_Prop][0] = '\0', pInfoPropOwner[ID_Prop]), Owner_Prop);
  187.  
  188. format(Format_Label, sizeof Format_Label, "ID: %i\nName: %s\nOwner: %s\nLucre: R$ %i,00 (Generating)", ID_Prop, pInfoPropName[ID_Prop], pInfoPropOwner[ID_Prop], pInfoPropLucre[ID_Prop]);
  189. Update3DTextLabelText(pInfoLabelProp[ID_Prop], -1, Format_Label);
  190.  
  191. mysql_format(MySQL_Connection, Format_MySQL, sizeof Format_MySQL, "UPDATE `"TABLE_PROP"` SET `"OWNER_PROP"` = '%s' WHERE `"ID_PROP"` = '%i'", Owner_Prop, ID_Prop);
  192. mysql_query(MySQL_Connection, Format_MySQL);
  193.  
  194. #if DEBUG_PROP == true
  195. printf("BuyProp: %s | Owner: %s", pInfoPropName[ID_Prop], Owner_Prop);
  196. #endif
  197. return 1;
  198. }
  199. stock SellProp(ID_Prop)
  200. {
  201. if(pInfoPropIdCheck[ID_Prop] == false) return false;
  202.  
  203. pInfoPropOwner[ID_Prop] = "N/A";
  204. pInfoPropLucre[ID_Prop] = 0;
  205.  
  206. mysql_format(MySQL_Connection, Format_MySQL, sizeof Format_MySQL, "UPDATE `"TABLE_PROP"` SET `"OWNER_PROP"` = 'N/A', `"LUCRE_PROP"` = '0' WHERE `"ID_PROP"` = '%i'", ID_Prop);
  207. mysql_query(MySQL_Connection, Format_MySQL, false);
  208.  
  209. format(Format_Label, sizeof Format_Label, "ID: %i\nName: %s\nOwner: %s\nPrice: R$ %i,00\nLucre: R$ %i,00", ID_Prop, pInfoPropName[ID_Prop], pInfoPropOwner[ID_Prop], pInfoPropBuyPrice[ID_Prop], pInfoPropLucre_[ID_Prop]);
  210.  
  211. Update3DTextLabelText(pInfoLabelProp[ID_Prop], -1, Format_Label);
  212.  
  213. #if DEBUG_PROP == true
  214. printf("SellProp: %s", pInfoPropName[ID_Prop]);
  215. #endif
  216. return 1;
  217. }
  218. stock GetPropBuyVal(ID_Prop)
  219. {
  220. if(pInfoPropIdCheck[ID_Prop] == false) return false;
  221.  
  222. #if DEBUG_PROP == true
  223. printf("GetPropBuyVal: R$ %i,00", pInfoPropBuyPrice[ID_Prop]);
  224. #endif
  225. return pInfoPropBuyPrice[ID_Prop];
  226. }
  227. stock GetPropSellVal(ID_Prop)
  228. {
  229. if(pInfoPropIdCheck[ID_Prop] == false) return false;
  230.  
  231. #if DEBUG_PROP == true
  232. printf("GetPropSellVal: R$ %i,00", pInfoPropSellPrice[ID_Prop]);
  233. #endif
  234. return pInfoPropSellPrice[ID_Prop];
  235. }
  236. stock GetPropLucreVal(ID_Prop)
  237. {
  238. if(pInfoPropIdCheck[ID_Prop] == false) return false;
  239.  
  240. GetPropLucre = EOS;
  241. GetPropLucre = pInfoPropLucre[ID_Prop];
  242. pInfoPropLucre[ID_Prop] = 0;
  243.  
  244. format(Format_Label, sizeof Format_Label, "ID: %i\nName: %s\nOwner: %s\nLucre: R$ %i,00 (Generating)", ID_Prop, pInfoPropName[ID_Prop], pInfoPropOwner[ID_Prop], pInfoPropLucre[ID_Prop]);
  245. Update3DTextLabelText(pInfoLabelProp[ID_Prop], -1, Format_Label);
  246.  
  247. mysql_format(MySQL_Connection, Format_MySQL, sizeof Format_MySQL, "UPDATE `"TABLE_PROP"` SET `"LUCRE_PROP"` = '0' WHERE `"ID_PROP"` = '%i'", ID_Prop);
  248. mysql_query(MySQL_Connection, Format_MySQL, false);
  249.  
  250. #if DEBUG_PROP == true
  251. printf("GetPropLucreVal: R$ %i,00", pInfoPropLucre[ID_Prop]);
  252. #endif
  253. return GetPropLucre;
  254. }
  255. stock GetPlayerProps(playerid, Owner_Prop[])
  256. {
  257. new String[128];
  258.  
  259. for(new p = 0; p < MAX_PROPS; p ++)
  260. {
  261. if(pInfoPropIdCheck[p] == false) continue;
  262.  
  263. if(strcmp(pInfoPropOwner[p], Owner_Prop, false) == 0)
  264. {
  265. format(String, sizeof String, "Owner: %s | Property: %s - ID: %i", pInfoPropOwner[p], pInfoPropName[p], p);
  266. SendClientMessage(playerid, -1, String);
  267. }
  268. }
  269.  
  270. #if DEBUG_PROP == true
  271. printf("GetPlayerProps: %s", Owner_Prop);
  272. #endif
  273. return 1;
  274. }
  275. stock LoadProps()
  276. {
  277. new GetID;
  278.  
  279. mysql_format(MySQL_Connection, Format_MySQL, sizeof Format_MySQL, "SELECT * FROM `"TABLE_PROP"`");
  280. mysql_query(MySQL_Connection, Format_MySQL);
  281. if(cache_num_rows())
  282. {
  283. printf("\n____________________________PROPERTIES_SYS_BY_F1N4L____________________________");
  284. for(new p = 0; p < cache_num_rows(); p ++)
  285. {
  286. GetID = cache_get_field_content_int(p, ID_PROP);
  287.  
  288. cache_get_field_content(p, NAME_PROP, pInfoPropName[GetID]);
  289. cache_get_field_content(p, OWNER_PROP, pInfoPropOwner[GetID]);
  290. pInfoPropBuyPrice[GetID] = cache_get_field_content_int(p, COST_PROP);
  291. pInfoPropSellPrice[GetID] = cache_get_field_content_int(p, SELL_PROP);
  292. pInfoPropLucre_[GetID] = cache_get_field_content_int(p, VALOR_LUCRE_PROP);
  293. pInfoPropLucre[GetID] = cache_get_field_content_int(p, LUCRE_PROP);
  294. pInfoPropPosX[GetID] = cache_get_field_content_float(p, POSX_PROP);
  295. pInfoPropPosY[GetID] = cache_get_field_content_float(p, POSY_PROP);
  296. pInfoPropPosZ[GetID] = cache_get_field_content_float(p, POSZ_PROP);
  297.  
  298. pInfoPropIdCheck[GetID] = true;
  299. pInfoPropTimeLucre[GetID] = TEMPO_Lucre * 60 + gettime();
  300.  
  301. if(strcmp("N/A", pInfoPropOwner[GetID], true) == 0) format(Format_Label, sizeof Format_Label, "ID: %i\nName: %s\nOwner: %s\nPrice: R$ %i,00\nLucre: R$ %i,00", GetID, pInfoPropName[GetID], pInfoPropOwner[GetID], pInfoPropBuyPrice[GetID], pInfoPropLucre_[GetID]);
  302. else format(Format_Label, sizeof Format_Label, "ID: %i\nName: %s\nOwner: %s\nLucre: R$ %i,00", GetID, pInfoPropName[GetID], pInfoPropOwner[GetID], pInfoPropLucre[GetID]);
  303.  
  304. pInfoPickupProp[GetID] = CreatePickup(1210, 1, pInfoPropPosX[GetID], pInfoPropPosY[GetID], pInfoPropPosZ[GetID]);
  305. pInfoLabelProp[GetID] = Create3DTextLabel(Format_Label, -1, pInfoPropPosX[GetID], pInfoPropPosY[GetID], pInfoPropPosZ[GetID] + 1, 50.0, 0, 1);
  306.  
  307. #if DEBUG_PROP == true
  308. printf("ID: %i | Name: %s | Owner: %s | Cost: %i | Sell: %i | Lucre: %i", GetID, pInfoPropName[GetID], pInfoPropOwner[GetID], pInfoPropBuyPrice[GetID], pInfoPropSellPrice[GetID], pInfoPropLucre[GetID]);
  309. #endif
  310. }
  311.  
  312. SetTimer("LucreProp", 1000, true);
  313.  
  314. #if DEBUG_PROP == true
  315. printf("\n%i Properties loaded.\n_____________________________________________________________________________\n", cache_num_rows());
  316. #endif
  317. }
  318.  
  319. return 1;
  320. }
  321. stock bool:IsPlayerInRangeOfProp(playerid, ID_Prop)
  322. {
  323. if(pInfoPropIdCheck[ID_Prop] == false) return false;
  324.  
  325. new bool:InRange;
  326.  
  327. if(IsPlayerInRangeOfPoint(playerid, 5.0, pInfoPropPosX[ID_Prop], pInfoPropPosY[ID_Prop], pInfoPropPosZ[ID_Prop])) InRange = true;
  328. else InRange = false;
  329.  
  330. #if DEBUG_PROP == true
  331. printf("IsPlayerInRangeOfProp: %s | Playerid: %i | Near: %i", pInfoPropName[ID_Prop], playerid, InRange);
  332. #endif
  333. return InRange;
  334. }
  335. stock bool:IsEmptyProp(ID_Prop)
  336. {
  337. if(pInfoPropIdCheck[ID_Prop] == false) return false;
  338.  
  339. new bool:CheckOwner;
  340.  
  341. if(strcmp("N/A", pInfoPropOwner[ID_Prop], false) == 0) CheckOwner = true;
  342. else CheckOwner = false;
  343.  
  344. #if DEBUG_PROP == true
  345. printf("CheckOwnerProp: %s | Exists: %i", pInfoPropName[ID_Prop], CheckOwner);
  346. #endif
  347. return CheckOwner;
  348. }
  349. stock bool:IsPlayerOwnerProp(Owner_Prop[], ID_Prop)
  350. {
  351. if(pInfoPropIdCheck[ID_Prop] == false) return false;
  352.  
  353. new bool:PlayerIsOwner;
  354.  
  355. if(strcmp(Owner_Prop, pInfoPropOwner[ID_Prop], false) == 0) PlayerIsOwner = true;
  356. else PlayerIsOwner = false;
  357.  
  358. #if DEBUG_PROP == true
  359. printf("PlayerIsOwnerProp: %s | Owner: %s | is Owner: %i", pInfoPropName[ID_Prop], Owner_Prop, PlayerIsOwner);
  360. #endif
  361. return PlayerIsOwner;
  362. }
  363. stock bool:PropIdExists(ID_Prop)
  364. {
  365. new bool:PropExists;
  366.  
  367. for(new p = 0; p < MAX_PROPS; p ++)
  368. {
  369. if(pInfoPropIdCheck[p] == false) continue;
  370.  
  371. if(pInfoPropIdCheck[ID_Prop] == true)
  372. {
  373. PropExists = true;
  374. break;
  375. }
  376. else PropExists = false;
  377. }
  378.  
  379. #if DEBUG_PROP == true
  380. printf("PropExists: %s | Exists: %i", pInfoPropName[ID_Prop], PropExists);
  381. #endif
  382. return PropExists;
  383. }
  384. stock bool:PropNameExists(Name_Prop[])
  385. {
  386. new bool:PropExists;
  387.  
  388. for(new p = 0; p < MAX_PROPS; p ++)
  389. {
  390. if(pInfoPropIdCheck[p] == false) continue;
  391.  
  392. if(strcmp(Name_Prop, pInfoPropName[p], true) == 0)
  393. {
  394. PropExists = true;
  395. break;
  396. }
  397. else PropExists = false;
  398. }
  399.  
  400. #if DEBUG_PROP == true
  401. printf("PropNameExists: %s | Exists: %i", NAME_PROP, PropExists);
  402. #endif
  403. return PropExists;
  404. }
  405. forward LucreProp();
  406. public LucreProp()
  407. {
  408. for(new p = 0; p < MAX_PROPS; p ++)
  409. {
  410. if(pInfoPropIdCheck[p] == false) continue;
  411.  
  412. if(strcmp("N/A", pInfoPropOwner[p], true) == 0) continue;
  413.  
  414. if(pInfoPropTimeLucre[p] < gettime())
  415. {
  416. pInfoPropTimeLucre[p] = TEMPO_Lucre * 60 + gettime();
  417.  
  418. pInfoPropLucre[p] += pInfoPropLucre_[p];
  419.  
  420. format(Format_Label, sizeof Format_Label, "ID: %i\nName: %s\nOwner: %s\nLucre: R$ %i,00", p, pInfoPropName[p], pInfoPropOwner[p], pInfoPropLucre[p]);
  421. Update3DTextLabelText(pInfoLabelProp[p], -1, Format_Label);
  422.  
  423. mysql_format(MySQL_Connection, Format_MySQL, sizeof Format_MySQL, "UPDATE `"TABLE_PROP"` SET `"LUCRE_PROP"` = '%i' WHERE `"ID_PROP"` = '%i'", pInfoPropLucre[p], p);
  424. mysql_query(MySQL_Connection, Format_MySQL, false);
  425. }
  426. }
  427. return 1;
  428. }
Advertisement
Add Comment
Please, Sign In to add comment