Advertisement
F1N4L_

[INC] Properties System v1.5 [MySQL]

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