Advertisement
Guest User

Eingangs System (Dynamisch)

a guest
Sep 16th, 2011
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.97 KB | None | 0 0
  1. /*
  2. Dynamic Entrance System
  3. By Raimis_[R]
  4.  
  5. Deutsche Übersetzung und Edierung by Inf3rnus
  6. */
  7.  
  8. #define FILTERSCRIPT
  9. /* Includes */
  10. #include <a_samp>
  11. #include "../include/a_mysql.inc"
  12. #include "../include/sscanf2.inc"
  13. #include "../include/zcmd.inc"
  14. /* Die MySQL Login Daten */
  15. #define MySQL_HOST "localhost"
  16. #define MySQL_USER "root"
  17. #define MySQL_DB "rpg"
  18. #define MySQL_PASS ""
  19.  
  20. #define MAX_ENTRANCES (100)
  21. #define MAX_ENTRANCE_NAME (25)
  22.  
  23. #define void%0(%1)\
  24. forward%0(%1); public%0(%1)
  25. #define function%0(%1)\
  26. stock%0(%1)
  27. #define forEx(%0,%1)\
  28. for(new %0; %0 != %1; %0++)
  29. #define PRESSED(%0)\
  30. (((newkeys & (%0)) == (%0)) && ((oldkeys & (%0)) != (%0)))
  31.  
  32. enum items
  33. {
  34. ID,
  35. Name[MAX_ENTRANCE_NAME],
  36. Float:Enter[3],
  37. Float:Exit[3],
  38. Interior,
  39. VirtualW
  40. }
  41. new eSystem[MAX_ENTRANCES][items];
  42.  
  43. new Text3D:EnterLabel[MAX_ENTRANCES];
  44.  
  45. public OnFilterScriptInit()
  46. {
  47. CreateMySQLConnection(MySQL_HOST, MySQL_USER, MySQL_DB, MySQL_PASS);
  48.  
  49. mysql_query("SELECT * FROM `entrances`");
  50. mysql_store_result();
  51.  
  52. new query[200], string[66], Count = 1;
  53.  
  54. while(mysql_fetch_row(query))
  55. {
  56. sscanf(query,"e<p<|>is[25]ffffffii>",eSystem[Count]);
  57.  
  58. format(string,sizeof(string),"%s\nBenutze die Taste [ENTER] um es zu Betreten!", eSystem[Count][Name]);
  59. EnterLabel[Count] = Create3DTextLabel(string, -1, eSystem[Count][Enter][0], eSystem[Count][Enter][1], eSystem[Count][Enter][2], 100.0, 0, 0);
  60. Count++;
  61. }
  62. return 1;
  63. }
  64.  
  65. public OnFilterScriptExit()
  66. {
  67. print("INFO: DES System UnLoaded!");
  68. mysql_close();
  69. print("INFO: MySQL Connection closed!");
  70. return 1;
  71. }
  72.  
  73. command(create, playerid, params[])
  74. {
  75. if (!IsPlayerAdmin(playerid)) return 0;
  76.  
  77. new pName[MAX_ENTRANCE_NAME], pInterior, query[200];
  78.  
  79. if (sscanf(params,"s[25]i", pName, pInterior))
  80. {
  81. return SendClientMessage(playerid, -1, "* Benutze: /create [Name des Eingangs] [Interior ID]");
  82. }
  83. if (strlen(pName) > MAX_ENTRANCE_NAME)
  84. {
  85. return SendClientMessage(playerid, -1, "* Der Name des Eingangs kann nicht länger als 25 Simbole lang sein!");
  86. }
  87. new Float:Player[3];
  88. GetPlayerPos(playerid, Player[0], Player[1], Player[2]);
  89.  
  90. mysql_query("SELECT MAX(ID) FROM `entrances`");
  91. mysql_store_result();
  92.  
  93. new sqlid[10];
  94. mysql_fetch_row_format(sqlid,"|");
  95. printf("INFO: Last ID: %s", sqlid);
  96.  
  97. new SQLID = strval(sqlid);
  98. SQLID++;
  99. eSystem[SQLID][ID] = SQLID;
  100. eSystem[SQLID][Name] = pName;
  101. eSystem[SQLID][Enter][0] = Player[0];
  102. eSystem[SQLID][Enter][1] = Player[1];
  103. eSystem[SQLID][Enter][2] = Player[2];
  104. eSystem[SQLID][VirtualW] = SQLID;
  105.  
  106. format(query,sizeof(query),"INSERT INTO `entrances` (`ID`,`Name`,`X`,`Y`,`Z`,`VirtualW`) VALUES ('%i','%s','%f','%f','%f','%i')",
  107. eSystem[SQLID][ID], eSystem[SQLID][Name], eSystem[SQLID][Enter][0], eSystem[SQLID][Enter][1], eSystem[SQLID][Enter][2], eSystem[SQLID][VirtualW]);
  108. mysql_query(query);
  109.  
  110. new string[66];
  111. format(string,sizeof(string),"%s\nBenutze die Taste [ENTER] um es zu Betreten!", eSystem[SQLID][Name]);
  112. EnterLabel[SQLID] = Create3DTextLabel(string, -1, eSystem[SQLID][Enter][0], eSystem[SQLID][Enter][1], eSystem[SQLID][Enter][2], 50.0, 0, 1);
  113.  
  114. UpdateExitCordinates(SQLID,pInterior);
  115. mysql_free_result();
  116. return 1;
  117. }
  118.  
  119.  
  120.  
  121. function UpdateExitCordinates(eID, eInterior)
  122. {
  123. switch(eInterior)
  124. {
  125. case 1: // LV Gym
  126. {
  127. eSystem[eID][Interior] = 7;
  128. eSystem[eID][Exit][0] = 773.579956;
  129. eSystem[eID][Exit][1] = -77.096694;
  130. eSystem[eID][Exit][2] = 1000.655029;
  131. }
  132. case 2: // Car school
  133. {
  134. eSystem[eID][Interior] = 3;
  135. eSystem[eID][Exit][0] = -2029.798339;
  136. eSystem[eID][Exit][1] = -106.675910;
  137. eSystem[eID][Exit][2] = 1035.171875;
  138. }
  139. case 3: // Bike school
  140. {
  141. eSystem[eID][Interior] = 3;
  142. eSystem[eID][Exit][0] = 1494.325195;
  143. eSystem[eID][Exit][1] = 1304.942871;
  144. eSystem[eID][Exit][2] = 1093.289062;
  145. }
  146. case 4: // LS Police HQ
  147. {
  148. eSystem[eID][Interior] = 6;
  149. eSystem[eID][Exit][0] = 246.783996;
  150. eSystem[eID][Exit][1] = 63.900199;
  151. eSystem[eID][Exit][2] = 1003.640625;
  152. }
  153. case 5: // Zero's RC Shop
  154. {
  155. eSystem[eID][Interior] = 6;
  156. eSystem[eID][Exit][0] = -2240.468505;
  157. eSystem[eID][Exit][1] = 137.060440;
  158. eSystem[eID][Exit][2] = 1035.414062;
  159. }
  160. case 6: // Ammunation 1
  161. {
  162. eSystem[eID][Interior] = 1;
  163. eSystem[eID][Exit][0] = 286.148986;
  164. eSystem[eID][Exit][1] = -40.644397;
  165. eSystem[eID][Exit][2] = 1001.515625;
  166. }
  167. case 7: // 24/7 1
  168. {
  169. eSystem[eID][Interior] = 17;
  170. eSystem[eID][Exit][0] = -25.884498;
  171. eSystem[eID][Exit][1] = -185.868988;
  172. eSystem[eID][Exit][2] = 1003.546875;
  173. }
  174. case 8: // Jefferson motel
  175. {
  176. eSystem[eID][Interior] = 15;
  177. eSystem[eID][Exit][0] = 2215.454833;
  178. eSystem[eID][Exit][1] = -1147.475585;
  179. eSystem[eID][Exit][2] = 1025.796875;
  180. }
  181. case 9: // Binco
  182. {
  183. eSystem[eID][Interior] = 15;
  184. eSystem[eID][Exit][0] = 207.737991;
  185. eSystem[eID][Exit][1] = -109.019996;
  186. eSystem[eID][Exit][2] = 1005.132812;
  187. }
  188. case 10: // Club
  189. {
  190. eSystem[eID][Interior] = 17;
  191. eSystem[eID][Exit][0] = 493.390991;
  192. eSystem[eID][Exit][1] = -22.722799;
  193. eSystem[eID][Exit][2] = 1000.679687;
  194. }
  195. default: // Bar
  196. {
  197. eSystem[eID][Interior] = 11;
  198. eSystem[eID][Exit][0] = 501.980987;
  199. eSystem[eID][Exit][1] = -69.150199;
  200. eSystem[eID][Exit][2] = 998.757812;
  201. }
  202. }
  203. new query[200];
  204. format(query,sizeof(query),"UPDATE `entrances` SET `exitX` = '%f', `exitY` = '%f', `exitZ` = '%f', `Interior` = '%i' WHERE `ID` = '%i'",
  205. eSystem[eID][Exit][0], eSystem[eID][Exit][1], eSystem[eID][Exit][2], eSystem[eID][Interior], eID);
  206. mysql_query(query);
  207. }
  208.  
  209.  
  210. function CreateMySQLConnection(host[], user[], db[], pass[])
  211. {
  212. mysql_connect(host, user, db, pass);
  213.  
  214. if (mysql_ping() >= 1)
  215. {
  216. print("INFO: Connected To MySQL!");
  217. }
  218. else
  219. {
  220. print("INFO: Can't Connect To MySQL!");
  221. }
  222. }
  223.  
  224.  
  225. void OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  226. {
  227. if (PRESSED(KEY_SECONDARY_ATTACK))
  228. {
  229. forEx(i, MAX_ENTRANCES)
  230. {
  231. if (IsPlayerInRangeOfPoint(playerid, 2, eSystem[i][Enter][0], eSystem[i][Enter][1], eSystem[i][Enter][2]))
  232. {
  233. SetPlayerVirtualWorld(playerid, eSystem[i][VirtualW]);
  234. SetPlayerInterior(playerid, eSystem[i][Interior]);
  235. SetPlayerPos(playerid, eSystem[i][Exit][0], eSystem[i][Exit][1], eSystem[i][Exit][2]);
  236. SetPVarInt(playerid, "entranceID", i); // Need for exit
  237. break; // Stoping loop
  238. }
  239. }
  240. if (IsPlayerInRangeOfPoint(playerid, 2, eSystem[GetPVarInt(playerid,"entranceID")][Exit][0], eSystem[GetPVarInt(playerid,"entranceID")][Exit][1], eSystem[GetPVarInt(playerid,"entranceID")][Exit][2]))
  241. {
  242. SetPlayerVirtualWorld(playerid, 0);
  243. SetPlayerInterior(playerid, 0);
  244. SetPlayerPos(playerid, eSystem[GetPVarInt(playerid,"entranceID")][Enter][0], eSystem[GetPVarInt(playerid,"entranceID")][Enter][1], eSystem[GetPVarInt(playerid,"entranceID")][Enter][2]);
  245. }
  246. }
  247. return 1;
  248. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement