Advertisement
Guest User

Street Sign

a guest
Oct 21st, 2019
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.02 KB | None | 0 0
  1. #include <a_samp>
  2. #include <a_mysql>
  3. #include <sscanf2>
  4. #include <streamer>
  5. #include <zcmd>
  6.  
  7. #define MAX_STREET (150)
  8. #define MAX_STREET_NAME (32)
  9.  
  10. new dbHandler;
  11.  
  12. enum E_STREETDATA
  13. {
  14. street_id,
  15. street_name[MAX_STREET_NAME],
  16. street_direction[32],
  17. Float: street_location[6], // MinX-Z, MaxX-Z
  18. Float: plate_location[6], // offset & rot
  19. Float: sign_location[6], // offset & rot
  20. Float: text_location[6], // offset & rot
  21. street_object[3]
  22. }
  23. new street_data[MAX_STREET][E_STREETDATA];
  24.  
  25. enum TEMP_DATA
  26. {
  27. bool:in_action,
  28. edit_mode,
  29. static_string,
  30. Float: current_pos[6],
  31. Float: sign_pos[6],
  32. Float: plate_pos[6],
  33. Float: text_pos[6],
  34. temp_object[3]
  35. }
  36.  
  37. new player_temp[MAX_PLAYERS][TEMP_DATA];
  38.  
  39. public OnFilterScriptInit()
  40. {
  41. dbHandler = mysql_connect("127.0.0.1", "demo", "root", "nopass", 3306, true, 10);
  42. mysql_tquery(dbHandler, "SELECT * FROM `street_names`", "LoadStreet");
  43. }
  44.  
  45. forward LoadStreet();
  46. public LoadStreet()
  47. {
  48. new id;
  49. for(new i = 0, list = cache_num_rows(); i < list; i++)
  50. {
  51. street_data[id][street_id] = cache_get_field_content_int(i, "sqlid");
  52. cache_get_field_content(i, "name", street_data[id][street_name], dbHandler, MAX_STREET_NAME);
  53. cache_get_field_content(i, "direction", street_data[id][street_direction], dbHandler, MAX_STREET_NAME);
  54. street_data[id][street_location][0] = cache_get_field_content_float(i, "minX");
  55. street_data[id][street_location][1] = cache_get_field_content_float(i, "minY");
  56. street_data[id][street_location][2] = cache_get_field_content_float(i, "minZ");
  57. street_data[id][street_location][3] = cache_get_field_content_float(i, "maxX");
  58. street_data[id][street_location][4] = cache_get_field_content_float(i, "maxY");
  59. street_data[id][street_location][5] = cache_get_field_content_float(i, "maxZ");
  60. street_data[id][plate_location][0] = cache_get_field_content_float(i, "plate_offsetX");
  61. street_data[id][plate_location][1] = cache_get_field_content_float(i, "plate_offsetY");
  62. street_data[id][plate_location][2] = cache_get_field_content_float(i, "plate_offsetZ");
  63. street_data[id][plate_location][3] = cache_get_field_content_float(i, "plate_rotX");
  64. street_data[id][plate_location][4] = cache_get_field_content_float(i, "plate_rotY");
  65. street_data[id][plate_location][5] = cache_get_field_content_float(i, "plate_rotZ");
  66. street_data[id][sign_location][0] = cache_get_field_content_float(i, "sign_offsetX");
  67. street_data[id][sign_location][1] = cache_get_field_content_float(i, "sign_offsetY");
  68. street_data[id][sign_location][2] = cache_get_field_content_float(i, "sign_offsetZ");
  69. street_data[id][sign_location][3] = cache_get_field_content_float(i, "sign_rotX");
  70. street_data[id][sign_location][4] = cache_get_field_content_float(i, "sign_rotY");
  71. street_data[id][sign_location][5] = cache_get_field_content_float(i, "sign_rotZ");
  72. street_data[id][text_location][0] = cache_get_field_content_float(i, "text_offsetX");
  73. street_data[id][text_location][1] = cache_get_field_content_float(i, "text_offsetY");
  74. street_data[id][text_location][2] = cache_get_field_content_float(i, "text_offsetZ");
  75. street_data[id][text_location][3] = cache_get_field_content_float(i, "text_rotX");
  76. street_data[id][text_location][4] = cache_get_field_content_float(i, "text_rotY");
  77. street_data[id][text_location][5] = cache_get_field_content_float(i, "text_rotZ");
  78.  
  79. street_data[id][street_object][0] = CreateDynamicObject(19981, street_data[id][street_location][0], street_data[id][street_location][1], street_data[id][street_location][2], 0.0, 0.0, 0.0, -1, -1, -1, 300.00, 300.00);
  80.  
  81. street_data[id][street_object][1] = CreateDynamicObject(18659, street_data[id][sign_location][0], street_data[id][sign_location][1], street_data[id][sign_location][2], street_data[id][sign_location][3], street_data[id][sign_location][4], street_data[id][sign_location][5], -1, -1, -1, 300.00, 300.00);
  82. SetDynamicObjectMaterialText(street_data[id][street_object][1], 0, street_data[id][street_name], 140, "Calibri", 30, 1, 0xFFFFFFFF, 0x00000000, 1);
  83.  
  84. street_data[id][street_object][2] = CreateDynamicObject(18659, street_data[id][text_location][0], street_data[id][text_location][1], street_data[id][text_location][2], street_data[id][text_location][3], street_data[id][sign_location][4], street_data[id][text_location][5], -1, -1, -1, 300.00, 300.00);
  85. SetDynamicObjectMaterialText(street_data[id][street_object][2], 0, street_data[id][street_direction], 140, "Calibri", 19, 1, 0xFFFFFFFF, 0x00000000, 1);
  86.  
  87. id ++;
  88. }
  89. return true;
  90. }
  91.  
  92. forward generate_street(playerid, step);
  93. public generate_street(playerid, step)
  94. {
  95. SetPVarInt(playerid, "current_step", step);
  96. switch(step)
  97. {
  98. case 0:
  99. {
  100. player_temp[playerid][edit_mode] = 1;
  101. player_temp[playerid][temp_object][0] = CreateDynamicObject(19981, player_temp[playerid][current_pos][0], player_temp[playerid][current_pos][1], player_temp[playerid][current_pos][2], 0.0, 0.0, 0.0, -1, -1, -1, 300.00, 300.00);
  102. EditDynamicObject(playerid, player_temp[playerid][temp_object][0]);
  103. }
  104. case 1:
  105. {
  106. player_temp[playerid][edit_mode] = 2;
  107. player_temp[playerid][temp_object][1] = CreateDynamicObject(18659, player_temp[playerid][current_pos][0], player_temp[playerid][current_pos][1], player_temp[playerid][current_pos][2], 0.0, 0.0, 0.0, -1, -1, -1, 300.00, 300.00);
  108. SetDynamicObjectMaterialText(player_temp[playerid][temp_object][1], 0, "Direction", 140, "Calibri", 30, 1, 0xFFFFFFFF, 0x00000000, 1);
  109. EditDynamicObject(playerid, player_temp[playerid][temp_object][1]);
  110. }
  111. case 2:
  112. {
  113. player_temp[playerid][edit_mode] = 3;
  114. player_temp[playerid][temp_object][2] = CreateDynamicObject(18659, player_temp[playerid][current_pos][0], player_temp[playerid][current_pos][1], player_temp[playerid][current_pos][2], 0.0, 0.0, 0.0, -1, -1, -1, 300.00, 300.00);
  115. SetDynamicObjectMaterialText(player_temp[playerid][temp_object][2], 0, "StreetName", 140, "Calibri", 30, 1, 0xFFFFFFFF, 0x00000000, 1);
  116. EditDynamicObject(playerid, player_temp[playerid][temp_object][2]);
  117. }
  118. default:
  119. {
  120. new query[512];
  121. mysql_format(dbHandler, query, sizeof(query), "INSERT INTO `street_names` (name, minX, minY, minZ, maxX, maxY, maxZ) VALUES ('%s',%f,%f,%f,%f,%f,%f)",
  122. player_temp[playerid][current_pos][0],
  123. player_temp[playerid][current_pos][1],
  124. player_temp[playerid][current_pos][2],
  125. player_temp[playerid][current_pos][3],
  126. player_temp[playerid][current_pos][4],
  127. player_temp[playerid][current_pos][5]
  128. );
  129. mysql_query(dbHandler, query, "insert_street", "d", playerid);
  130. }
  131. }
  132. return 0;
  133. }
  134.  
  135. Float: abs(Float: angel)
  136. {
  137. return ((angel < 0) ? (angel * -1) : (angel));
  138. }
  139.  
  140. stock returnAngel(playerid)
  141. {
  142. new Float: Velocity[3], string[32];
  143. GetPlayerVelocity(playerid, Velocity[0], Velocity[1], Velocity[2]);
  144. if(Velocity[0] == 0.0 && Velocity[1] == 0.0)
  145. {
  146. format(string, 32, "CENTRAL");
  147. }
  148. else
  149. {
  150. if(abs(Velocity[1])>abs(Velocity[0]))
  151. {
  152. if(Velocity[1] > 0)
  153. {
  154. format(string, 32, "NORTH");
  155. }
  156. else
  157. {
  158. format(string, 32, "SOUTH");
  159. }
  160. }
  161. else
  162. {
  163. if(Velocity[0] > 0)
  164. {
  165. format(string, 32, "EAST");
  166. }
  167. else
  168. {
  169. format(string, 32, "WEST");
  170. }
  171. }
  172. }
  173. return string;
  174. }
  175.  
  176. stock street_free_slot()
  177. {
  178. for(new S = 0; S < MAX_STREET; S++)
  179. {
  180. if(street_data[S][street_id] == 0)
  181. {
  182. return S;
  183. }
  184. }
  185. return -1;
  186. }
  187.  
  188. forward insert_street(playerid);
  189. public insert_street(playerid)
  190. {
  191. new id = street_free_slot();
  192. street_data[id][street_id] = cache_insert_id();
  193.  
  194. street_data[id][plate_location][0] = player_temp[playerid][plate_pos][0];
  195. street_data[id][plate_location][1] = player_temp[playerid][plate_pos][1];
  196. street_data[id][plate_location][2] = player_temp[playerid][plate_pos][2];
  197. street_data[id][plate_location][3] = player_temp[playerid][plate_pos][3];
  198. street_data[id][plate_location][4] = player_temp[playerid][plate_pos][4];
  199. street_data[id][plate_location][5] = player_temp[playerid][plate_pos][5];
  200.  
  201. street_data[id][sign_location][0] = player_temp[playerid][sign_pos][0];
  202. street_data[id][sign_location][1] = player_temp[playerid][sign_pos][1];
  203. street_data[id][sign_location][2] = player_temp[playerid][sign_pos][2];
  204. street_data[id][sign_location][3] = player_temp[playerid][sign_pos][3];
  205. street_data[id][sign_location][4] = player_temp[playerid][sign_pos][4];
  206. street_data[id][sign_location][5] = player_temp[playerid][sign_pos][5];
  207.  
  208. street_data[id][text_location][0] = player_temp[playerid][text_pos][0];
  209. street_data[id][text_location][1] = player_temp[playerid][text_pos][1];
  210. street_data[id][text_location][2] = player_temp[playerid][text_pos][2];
  211. street_data[id][text_location][3] = player_temp[playerid][text_pos][3];
  212. street_data[id][text_location][4] = player_temp[playerid][text_pos][4];
  213. street_data[id][text_location][5] = player_temp[playerid][text_pos][5];
  214.  
  215. format(street_data[id][street_name], player_temp[playerid][static_string]);
  216.  
  217. format(street_data[id][street_direction], 128, "%d %s", 1000+street_data[id][street_id], returnAngel(playerid));
  218.  
  219. street_data[id][street_object][0] = CreateDynamicObject(19981, street_data[id][plate_location][0], street_data[id][plate_location][1], street_data[id][plate_location][2], street_data[id][plate_location][3], street_data[id][plate_location][4], street_data[id][plate_location][5], -1, -1, -1, 300.00, 300.00);
  220.  
  221. street_data[id][street_object][1] = CreateDynamicObject(18659, street_data[id][sign_location][0], street_data[id][sign_location][1], street_data[id][sign_location][2], street_data[id][sign_location][3], street_data[id][sign_location][4], street_data[id][sign_location][5], -1, -1, -1, 300.00, 300.00);
  222. SetDynamicObjectMaterialText(street_data[id][street_object][1], 0, street_data[id][street_name], 140, "Calibri", 30, 1, 0xFFFFFFFF, 0x00000000, 1);
  223.  
  224. street_data[id][street_object][2] = CreateDynamicObject(18659, street_data[id][text_location][0], street_data[id][text_location][1], street_data[id][text_location][2], street_data[id][text_location][3], street_data[id][sign_location][4], street_data[id][text_location][5], -1, -1, -1, 300.00, 300.00);
  225. SetDynamicObjectMaterialText(street_data[id][street_object][2], 0, street_data[id][street_direction], 140, "Calibri", 19, 1, 0xFFFFFFFF, 0x00000000, 1);
  226. reset_temp(playerid);
  227. SaveStreet(street_data[id][street_id]);
  228. }
  229.  
  230. forward SaveStreet(id);
  231. public SaveStreet(id)
  232. {
  233. new query[300];
  234. mysql_format(dbHandler, query, sizeof(query), "UPDATE street_names SET name = '%s', direction = '%s' WHERE sqlid = %i", street_data[id][street_name], street_data[id][street_direction], id);
  235. mysql_query(dbHandler, query);
  236.  
  237. mysql_format(dbHandler, query, sizeof(query), "UPDATE street_names SET plate_offsetX = %f, plate_offsetY = %f, plate_offsetZ = %f, plate_rotX = %f, plate_rotY = %f, plate_rotZ = %f WHERE sqlid = %i", street_data[id][plate_location][0], street_data[id][plate_location][1], street_data[id][plate_location][2], street_data[id][plate_location][3], street_data[id][plate_location][4], street_data[id][plate_location][5], id);
  238. mysql_query(dbHandler, query);
  239.  
  240. mysql_format(dbHandler, query, sizeof(query), "UPDATE street_names SET sign_offsetX = %f, sign_offsetY = %f, sign_offsetZ = %f, sign_rotX = %f, sign_rotY = %f, sign_rotZ = %f WHERE sqlid = %i", street_data[id][sign_location][0], street_data[id][sign_location][1], street_data[id][sign_location][2], street_data[id][sign_location][3], street_data[id][sign_location][4], street_data[id][sign_location][5], id);
  241. mysql_query(dbHandler, query);
  242.  
  243. mysql_format(dbHandler, query, sizeof(query), "UPDATE street_names SET text_offsetX = %f, text_offsetY = %f, text_offsetZ = %f, text_rotX = %f, text_rotY = %f, text_rotZ = %f WHERE sqlid = %i", street_data[id][text_location][0], street_data[id][text_location][1], street_data[id][text_location][2], street_data[id][text_location][3], street_data[id][sign_location][4], street_data[id][text_location][5], id);
  244. mysql_query(dbHandler, query);
  245. }
  246.  
  247. stock reset_temp(playerid)
  248. {
  249. player_temp[playerid][in_action] = false;
  250. player_temp[playerid][edit_mode] = 0;
  251.  
  252. format(player_temp[playerid][static_string], "None");
  253. for(new addr = 0; addr < 3; addr++)
  254. {
  255. player_temp[playerid][current_pos][addr] = 0.0;
  256. if(IsValidDynamicObject(player_temp[playerid][temp_object][addr])) DestroyDynamicObject(player_temp[playerid][temp_object][addr]);
  257. player_temp[playerid][temp_object][addr] = INVALID_OBJECT_ID;
  258. }
  259. }
  260.  
  261. public OnPlayerEditDynamicObject(playerid, objectid, response, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz)
  262. {
  263. if(response == EDIT_RESPONSE_FINAL)
  264. {
  265. switch(player_temp[playerid][edit_mode])
  266. {
  267. case 1:
  268. {
  269. player_temp[playerid][plate_pos][0] = x;
  270. player_temp[playerid][plate_pos][1] = y;
  271. player_temp[playerid][plate_pos][2] = z;
  272. player_temp[playerid][plate_pos][3] = rx;
  273. player_temp[playerid][plate_pos][4] = ry;
  274. player_temp[playerid][plate_pos][5] = rz;
  275. }
  276. case 2:
  277. {
  278. player_temp[playerid][sign_pos][0] = x;
  279. player_temp[playerid][sign_pos][1] = y;
  280. player_temp[playerid][sign_pos][2] = z;
  281. player_temp[playerid][sign_pos][3] = rx;
  282. player_temp[playerid][sign_pos][4] = ry;
  283. player_temp[playerid][sign_pos][5] = rz;
  284. }
  285. case 3:
  286. {
  287. player_temp[playerid][text_pos][0] = x;
  288. player_temp[playerid][text_pos][1] = y;
  289. player_temp[playerid][text_pos][2] = z;
  290. player_temp[playerid][text_pos][3] = rx;
  291. player_temp[playerid][text_pos][4] = ry;
  292. player_temp[playerid][text_pos][5] = rz;
  293. }
  294. }
  295. generate_street(playerid, GetPVarInt(playerid, "current_step")+1);
  296. }
  297. if(response == EDIT_RESPONSE_CANCEL)
  298. {
  299. if(player_temp[playerid][edit_mode])
  300. {
  301. reset_temp(playerid);
  302. }
  303. }
  304. return 1;
  305. }
  306.  
  307. stock GetPlayerStreet(playerid, zone[], length)
  308. {
  309. new Float:x, Float:y, Float:z;
  310. GetPlayerPos(playerid, x, y, z);
  311. for(new i = 0; i != MAX_STREET; i++)
  312. {
  313. if(x >= street_data[i][street_location][0] && x <= street_data[i][street_location][3] && y >= street_data[i][street_location][1] && y <= street_data[i][street_location][4])
  314. {
  315. return format(zone, length, street_data[i][street_name], 0);
  316. }
  317. }
  318. return format(zone, length, "Unknown", 0);
  319. }
  320.  
  321. stock GetStreetID(playerid)
  322. {
  323. new Float:x, Float:y, Float:z;
  324. GetPlayerPos(playerid, x, y, z);
  325. for(new i = 0; i != MAX_STREET; i++)
  326. {
  327. if(IsPlayerInRangeOfPoint(playerid, 15.0, street_data[i][street_location][0], street_data[i][street_location][2], street_data[i][street_location][3]) || IsPlayerInRangeOfPoint(playerid, 15.0, street_data[i][street_location][3], street_data[i][street_location][4], street_data[i][street_location][5]))
  328. {
  329. return i;
  330. }
  331. }
  332. return -1;
  333. }
  334.  
  335. CMD:create_street(playerid, params[])
  336. {
  337. new Float: player_pos[3];
  338. if(player_temp[playerid][in_action])
  339. {
  340. if(sscanf(params,"s[32]", params[0]))
  341. {
  342. return SendClientMessage(playerid, -1, "USAGE: /create_street [street_name]");
  343. }
  344. GetPlayerPos(playerid, player_pos[0], player_pos[1], player_pos[2]);
  345. player_temp[playerid][current_pos][3] = player_pos[0];
  346. player_temp[playerid][current_pos][4] = player_pos[1];
  347. player_temp[playerid][current_pos][5] = player_pos[2];
  348. format(player_temp[playerid][static_string], params[0]);
  349. generate_street(playerid, 0);
  350. }
  351. else
  352. {
  353. GetPlayerPos(playerid, player_pos[0], player_pos[1], player_pos[2]);
  354. player_temp[playerid][current_pos][0] = player_pos[0];
  355. player_temp[playerid][current_pos][1] = player_pos[1];
  356. player_temp[playerid][current_pos][2] = player_pos[2];
  357. player_temp[playerid][in_action] = true;
  358. SendClientMessage(playerid, -1, "SERVER: Please stand at any corner or the end of street.");
  359. SendClientMessage(playerid, -1, "SERVER: Take more 10 sprints after redo the command.");
  360. }
  361. return true;
  362. }
  363.  
  364. CMD:streetname(playerid, params[])
  365. {
  366. new str[64], street[32];
  367. GetPlayerStreet(playerid, street, 32);
  368. format(str, sizeof(str), "SERVER: YOU ARE NOW STANDING ON %s, %s", street_data[ GetStreetID(playerid) ][street_direction], street);
  369. SendClientMessage(playerid, -1, str);
  370. return true;
  371. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement