Advertisement
adri1

Map Mover 1.1 by adri1

May 10th, 2014
2,582
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.07 KB | None | 0 0
  1. // Map Mover 1.1 by adri1
  2.  
  3. #define MAX_MAPMOVER_OBJECTS (500)
  4. #define MAX_MAPMOVER_REMOVEBUILDING 1
  5.  
  6.  
  7.  
  8.  
  9.  
  10. //-------------------------------------------------
  11. //
  12. // This is an example of using the AttachCameraToObject function
  13. // to create a no-clip flying camera.
  14. //
  15. // h02 2012
  16. //
  17. // SA-MP 0.3e and above
  18. //
  19. //-------------------------------------------------
  20.  
  21. #include <a_samp>
  22. #include <sscanf2>
  23. // Players Move Speed
  24. #define MOVE_SPEED 100.0
  25. #define ACCEL_RATE 0.03
  26.  
  27. // Players Mode
  28. #define CAMERA_MODE_NONE 0
  29. #define CAMERA_MODE_FLY 1
  30.  
  31. // Key state definitions
  32. #define MOVE_FORWARD 1
  33. #define MOVE_BACK 2
  34. #define MOVE_LEFT 3
  35. #define MOVE_RIGHT 4
  36. #define MOVE_FORWARD_LEFT 5
  37. #define MOVE_FORWARD_RIGHT 6
  38. #define MOVE_BACK_LEFT 7
  39. #define MOVE_BACK_RIGHT 8
  40.  
  41. // Enumeration for storing data about the player
  42. enum noclipenum
  43. {
  44. cameramode,
  45. flyobject,
  46. mode,
  47. lrold,
  48. udold,
  49. lastmove,
  50. Float:accelmul
  51. }
  52. new noclipdata[MAX_PLAYERS][noclipenum];
  53.  
  54. //--------------------------------------------------
  55.  
  56. public OnFilterScriptInit()
  57. {
  58. return 1;
  59. }
  60.  
  61. public OnFilterScriptExit()
  62. {
  63. // If any players are still in edit mode, boot them out before the filterscript unloads
  64. for(new x; x<MAX_PLAYERS; x++)
  65. {
  66. if(noclipdata[x][cameramode] == CAMERA_MODE_FLY) CancelFlyMode(x);
  67. }
  68. return 1;
  69. }
  70.  
  71. //--------------------------------------------------
  72.  
  73. public OnPlayerConnect(playerid)
  74. {
  75. // Reset the data belonging to this player slot
  76. noclipdata[playerid][cameramode] = CAMERA_MODE_NONE;
  77. noclipdata[playerid][lrold] = 0;
  78. noclipdata[playerid][udold] = 0;
  79. noclipdata[playerid][mode] = 0;
  80. noclipdata[playerid][lastmove] = 0;
  81. noclipdata[playerid][accelmul] = 0.0;
  82. return 1;
  83. }
  84.  
  85.  
  86. /* CODE */
  87.  
  88.  
  89. new Object_String[512];
  90. new Player_MovingMap[MAX_PLAYERS];
  91. new Player_MovingObjects[MAX_PLAYERS];
  92. new ObjectCenter;
  93. new mapnamefile[24];
  94. new Float:CamOffSetX;
  95. new Float:CamOffSetY;
  96. new Float:CamOffSetZ;
  97. enum OBJECT_INFORMATION
  98. {
  99. ModelID,
  100. Float:PositionX,
  101. Float:PositionY,
  102. Float:PositionZ,
  103. Float:RotationX,
  104. Float:RotationY,
  105. Float:RotationZ,
  106. Float:OffSetX,
  107. Float:OffSetY,
  108. Float:OffSetZ,
  109. ObjectID
  110. };
  111. new MAPMOVER_OBJECTS[MAX_MAPMOVER_OBJECTS][OBJECT_INFORMATION];
  112.  
  113. stock LoadMap(playerid, mapname[])
  114. {
  115. if(Player_MovingMap[playerid] == 0) return 1;
  116. new File:Handler = fopen(mapname, io_read);
  117. if(!Handler) return ShowPlayerDialog(playerid, 801, DIALOG_STYLE_MSGBOX, "Map Mover", "\n\n\tThe map could not load:\n\tFile not found.\n\n", "OK", "");
  118. new Index;
  119. while(fread(Handler, Object_String))
  120. {
  121. StripNewLine(Object_String);
  122. new t = 0;
  123. if(strfind(Object_String, "CreateObject(", true) != -1) strdel(Object_String, 0, 13), t = 1;
  124. if(strfind(Object_String, "CreateDynamicObject(", true) != -1) strdel(Object_String, 0, 20), t = 1;
  125. #if MAX_MAPMOVER_REMOVEBUILDING 1
  126. if(strfind(Object_String, "RemoveBuildingForPlayer(playerid,", true) != -1) strdel(Object_String, 0, 33), t = 2;
  127. #endif
  128. if(strfind(Object_String, ");", true) != -1)
  129. {
  130. new start = strfind(Object_String, ");", true);
  131. strdel(Object_String, start, 500);
  132. }
  133. if(t == 1)
  134. {
  135. if(!sscanf(Object_String, "p<,>dffffff",
  136. MAPMOVER_OBJECTS[Index][ModelID],
  137. MAPMOVER_OBJECTS[Index][PositionX], MAPMOVER_OBJECTS[Index][PositionY], MAPMOVER_OBJECTS[Index][PositionZ],
  138. MAPMOVER_OBJECTS[Index][RotationX], MAPMOVER_OBJECTS[Index][RotationY], MAPMOVER_OBJECTS[Index][RotationZ]))
  139. {
  140.  
  141. new objectid = CreateObject(MAPMOVER_OBJECTS[Index][ModelID],
  142. MAPMOVER_OBJECTS[Index][PositionX], MAPMOVER_OBJECTS[Index][PositionY], MAPMOVER_OBJECTS[Index][PositionZ],
  143. MAPMOVER_OBJECTS[Index][RotationX], MAPMOVER_OBJECTS[Index][RotationY], MAPMOVER_OBJECTS[Index][RotationZ]);
  144. MAPMOVER_OBJECTS[Index][ObjectID] = objectid;
  145. Index++;
  146. }
  147. }
  148. else if(t == 2)
  149. {
  150. new m, Float:x, Float:y, Float:z, Float:r;
  151. if(!sscanf(Object_String, "p<,>dffff", m, x, y, z, r)) RemoveBuildingForPlayer(playerid, m, x, y, z, r);
  152. }
  153. }
  154. fclose(Handler);
  155.  
  156. if(Index == 0) ShowPlayerDialog(playerid, 801, DIALOG_STYLE_MSGBOX, "Map Mover", "\n\n\tCan't find any map in this file.\n\n", "OK", "");
  157. else
  158. {
  159. ShowPlayerDialog(playerid, 802, DIALOG_STYLE_MSGBOX, "Map Mover", "\n\n\tMap loaded correctly.\n\n", "OK", "");
  160. format(mapnamefile, 24, "%s", mapname);
  161. }
  162. return true;
  163. }
  164.  
  165.  
  166.  
  167. stock StripNewLine(string[]) //DracoBlue (bugfix idea by Y_Less)
  168. {
  169. new len = strlen(string);
  170. if (string[0]==0) return ;
  171. if ((string[len - 1] == '\n') || (string[len - 1] == '\r')) {
  172. string[len - 1] = 0;
  173. if (string[0]==0) return ;
  174. if ((string[len - 2] == '\n') || (string[len - 2] == '\r')) string[len - 2] = 0;
  175. }
  176. }
  177.  
  178. public OnPlayerDisconnect(playerid, reason)
  179. {
  180. if(Player_MovingMap[playerid] == 1)
  181. {
  182. for(new i = 0; i != MAX_MAPMOVER_OBJECTS; i++)
  183. {
  184. if(MAPMOVER_OBJECTS[i][ModelID] != 0)
  185. {
  186. DestroyObject(MAPMOVER_OBJECTS[i][ObjectID]);
  187. MAPMOVER_OBJECTS[i][ModelID] = 0;
  188. MAPMOVER_OBJECTS[i][PositionX] = 0.0;
  189. MAPMOVER_OBJECTS[i][PositionY] = 0.0;
  190. MAPMOVER_OBJECTS[i][PositionZ] = 0.0;
  191. MAPMOVER_OBJECTS[i][RotationX] = 0.0;
  192. MAPMOVER_OBJECTS[i][RotationY] = 0.0;
  193. MAPMOVER_OBJECTS[i][RotationZ] = 0.0;
  194. MAPMOVER_OBJECTS[i][OffSetX] = 0.0;
  195. MAPMOVER_OBJECTS[i][OffSetY] = 0.0;
  196. MAPMOVER_OBJECTS[i][OffSetZ] = 0.0;
  197. MAPMOVER_OBJECTS[i][ObjectID] = 0;
  198. }
  199. }
  200. DestroyObject(ObjectCenter);
  201. ObjectCenter = 0;
  202. Player_MovingObjects[playerid] = 0;
  203. Player_MovingMap[playerid] = 0;
  204. }
  205. return 1;
  206. }
  207.  
  208. public OnPlayerCommandText(playerid, cmdtext[])
  209. {
  210. if(!strcmp(cmdtext, "/map", true))
  211. {
  212. if(GetPVarType(playerid, "FlyMode"))
  213. {
  214. if(Player_MovingObjects[playerid] >= 1) return SendClientMessage(playerid, -1, "{FFFF00}Map Mover: {FFFFFF}Finish move the map before showing the menu.");
  215. if(Player_MovingMap[playerid] == 1) ShowPlayerDialog(playerid, 803, DIALOG_STYLE_LIST, "Map Mover", "1. Locate\n2. Center position\n3. Edit positions\n4. Export map\n5. Exit (without saving)", "OK", "");
  216. }
  217. else
  218. {
  219. if(Player_MovingMap[playerid] == 1) return 1;
  220. Player_MovingMap[playerid] = 1;
  221. ShowPlayerDialog(playerid, 800, DIALOG_STYLE_INPUT, "Map Mover", "\n\nEnter the file name .txt with the map\nthat has been saved in the folder scriptfiles.\n\n\t(You must enter the extension .txt)\n\n", "Load", "X");
  222. FlyMode(playerid);
  223. }
  224. return 1;
  225. }
  226. return 0;
  227. }
  228.  
  229. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  230. {
  231. if(dialogid == 800)
  232. {
  233. if(response)
  234. {
  235. ShowPlayerDialog(playerid, 801, DIALOG_STYLE_MSGBOX, "Map Mover", "\n\n\tLoading Map...\n\n", "OK", "");
  236. LoadMap(playerid, inputtext);
  237. }
  238. else
  239. {
  240. Player_MovingMap[playerid] = 0;
  241. CancelFlyMode(playerid);
  242. }
  243. }
  244. if(dialogid == 801) ShowPlayerDialog(playerid, 800, DIALOG_STYLE_INPUT, "Map Mover", "\n\nEnter the file name .txt with the map\nthat has been saved in the folder scriptfiles.\n\n\t(You must enter the extension .txt)\n\n", "Load", "X");
  245. if(dialogid == 802) ShowPlayerDialog(playerid, 803, DIALOG_STYLE_LIST, "Map Mover", "1. Locate\n2. Center position\n3. Edit positions\n4. Export map\n5. Exit (without saving)", "OK", "");
  246. if(dialogid == 803)
  247. {
  248. if(response)
  249. {
  250. switch(listitem)
  251. {
  252. case 0:
  253. {
  254. if(ObjectCenter == 0)
  255. {
  256. new Float:CameraX = MAPMOVER_OBJECTS[0][PositionX];
  257. new Float:CameraY = MAPMOVER_OBJECTS[0][PositionY];
  258. new Float:CameraZ = MAPMOVER_OBJECTS[0][PositionZ];
  259. SetPlayerObjectPos(playerid, noclipdata[playerid][flyobject], CameraX, CameraY, CameraZ);
  260. SendClientMessage(playerid, -1, "{FFFF00}Map Mover: {FFFFFF}Use the {FFFF00}/map {FFFFFF}command again to show the main menu.");
  261. }
  262. else
  263. {
  264. new Float:CameraX;
  265. new Float:CameraY;
  266. new Float:CameraZ;
  267. GetObjectPos(ObjectCenter, CameraX, CameraY, CameraZ);
  268. SetPlayerObjectPos(playerid, noclipdata[playerid][flyobject], CameraX, CameraY, CameraZ);
  269. SendClientMessage(playerid, -1, "{FFFF00}Map Mover: {FFFFFF}Use the {FFFF00}/map {FFFFFF}command again to show the main menu.");
  270. }
  271. }
  272. case 1:
  273. {
  274. if(ObjectCenter == 0)
  275. {
  276. new Float:CameraX;
  277. new Float:CameraY;
  278. new Float:CameraZ;
  279. GetPlayerObjectPos(playerid, noclipdata[playerid][flyobject], CameraX, CameraY, CameraZ);
  280. ObjectCenter = CreateObject(1220, CameraX, CameraY, CameraZ, 0.0, 0.0, 0.0);
  281. SetObjectMaterial(ObjectCenter, 0, 18646, "matcolours", "white");
  282. EditObject(playerid, ObjectCenter);
  283. SendClientMessage(playerid, -1, "{FFFF00}Map Mover: {FFFFFF}Place your object in the center of the map loaded.");
  284. }
  285. else
  286. {
  287. SetObjectMaterial(ObjectCenter, 0, 18646, "matcolours", "white");
  288. EditObject(playerid, ObjectCenter);
  289. SendClientMessage(playerid, -1, "{FFFF00}Map Mover: {FFFFFF}Place your object in the center of the map loaded.");
  290. }
  291. }
  292. case 2:
  293. {
  294. if(ObjectCenter == 0) return SendClientMessage(playerid, -1, "{FFFF00}Map Mover: {FFFFFF}You must place the center first.");
  295. ShowPlayerDialog(playerid, 804, DIALOG_STYLE_LIST, "Map Mover - Move options", "1. Move with cursor (EditObject)\n2. Move with camera (new)", "OK", "<<");
  296. }
  297. case 3:
  298. {
  299. if(ObjectCenter == 0) return SendClientMessage(playerid, -1, "{FFFF00}Map Mover: {FFFFFF}Not noticed any change.");
  300. new f_name[24];
  301. format(f_name, 24, "%s_converted.txt", mapnamefile);
  302. new File:codefile = fopen(f_name, io_write);
  303. if(codefile)
  304. {
  305. new Year, Month, Day;
  306. getdate(Year, Month, Day);
  307. new Hour, Minute, Second;
  308. gettime(Hour, Minute, Second);
  309. new intro[128]; format(intro, 128, "Map Mover ~ %s ~ %02d/%02d/%d ~ %02d:%02d:%02d\r\n\r\n", mapnamefile, Day, Month, Year, Hour, Minute, Second);
  310. fwrite(codefile, intro);
  311. for(new i = 0; i != MAX_MAPMOVER_OBJECTS; i++)
  312. {
  313. if(MAPMOVER_OBJECTS[i][ModelID] != 0)
  314. {
  315. new line[128];
  316. format(line, 128, "CreateObject(%d, %f, %f, %f, %f, %f, %f);\r\n", MAPMOVER_OBJECTS[i][ModelID], MAPMOVER_OBJECTS[i][PositionX], MAPMOVER_OBJECTS[i][PositionY], MAPMOVER_OBJECTS[i][PositionZ], MAPMOVER_OBJECTS[i][RotationX], MAPMOVER_OBJECTS[i][RotationY], MAPMOVER_OBJECTS[i][RotationZ]);
  317. fwrite(codefile, line);
  318. }
  319. }
  320. fwrite(codefile, "\r\n");
  321. fwrite(codefile, "\r\n");
  322. fwrite(codefile, "RemoveBuildings no converted (not necessary).");
  323. fwrite(codefile, "Map Mover 1.1 by adri1.");
  324. fclose(codefile);
  325. }
  326.  
  327. }
  328. case 4:
  329. {
  330. for(new i = 0; i != MAX_MAPMOVER_OBJECTS; i++)
  331. {
  332. if(MAPMOVER_OBJECTS[i][ModelID] != 0)
  333. {
  334. DestroyObject(MAPMOVER_OBJECTS[i][ObjectID]);
  335. MAPMOVER_OBJECTS[i][ModelID] = 0;
  336. MAPMOVER_OBJECTS[i][PositionX] = 0.0;
  337. MAPMOVER_OBJECTS[i][PositionY] = 0.0;
  338. MAPMOVER_OBJECTS[i][PositionZ] = 0.0;
  339. MAPMOVER_OBJECTS[i][RotationX] = 0.0;
  340. MAPMOVER_OBJECTS[i][RotationY] = 0.0;
  341. MAPMOVER_OBJECTS[i][RotationZ] = 0.0;
  342. MAPMOVER_OBJECTS[i][OffSetX] = 0.0;
  343. MAPMOVER_OBJECTS[i][OffSetY] = 0.0;
  344. MAPMOVER_OBJECTS[i][OffSetZ] = 0.0;
  345. MAPMOVER_OBJECTS[i][ObjectID] = 0;
  346. }
  347. }
  348. DestroyObject(ObjectCenter);
  349. Player_MovingObjects[playerid] = 0;
  350. Player_MovingMap[playerid] = 0;
  351. ObjectCenter = 0;
  352. CancelFlyMode(playerid);
  353. CancelEdit(playerid);
  354. }
  355. }
  356. }
  357. else SendClientMessage(playerid, -1, "{FFFF00}Map Mover: {FFFFFF}Use the {FFFF00}/map {FFFFFF}command again to show the main menu.");
  358. }
  359. if(dialogid == 804)
  360. {
  361. if(response)
  362. {
  363. switch(listitem)
  364. {
  365. case 0:
  366. {
  367. new Float:CenterX, Float:CenterY, Float:CenterZ;
  368. GetObjectPos(ObjectCenter, CenterX, CenterY, CenterZ);
  369. for(new i = 0; i != MAX_MAPMOVER_OBJECTS; i++)
  370. {
  371. if(MAPMOVER_OBJECTS[i][ModelID] != 0)
  372. {
  373. new Float:aOffSetX, Float:aOffSetY, Float:aOffSetZ;
  374. aOffSetX = floatsub(MAPMOVER_OBJECTS[i][PositionX], CenterX);
  375. aOffSetY = floatsub(MAPMOVER_OBJECTS[i][PositionY], CenterY);
  376. aOffSetZ = floatsub(MAPMOVER_OBJECTS[i][PositionZ], CenterZ);
  377. MAPMOVER_OBJECTS[i][OffSetX] = aOffSetX;
  378. MAPMOVER_OBJECTS[i][OffSetY] = aOffSetY;
  379. MAPMOVER_OBJECTS[i][OffSetZ] = aOffSetZ;
  380. AttachObjectToObject(MAPMOVER_OBJECTS[i][ObjectID], ObjectCenter, aOffSetX, aOffSetY, aOffSetZ, MAPMOVER_OBJECTS[i][RotationX], MAPMOVER_OBJECTS[i][RotationY], MAPMOVER_OBJECTS[i][RotationZ], true);
  381. }
  382. }
  383. Player_MovingObjects[playerid] = 1;
  384. EditObject(playerid, ObjectCenter);
  385. }
  386. case 1:
  387. {
  388. SendClientMessage(playerid, -1, "{FFFF00}Map Mover: {FFFFFF}Move the camera to move the map. Press {FFFF00}~k~~PED_DUCK~ {FFFFFF}for stop.");
  389. new Float:CenterX, Float:CenterY, Float:CenterZ;
  390. GetObjectPos(ObjectCenter, CenterX, CenterY, CenterZ);
  391. for(new i = 0; i != MAX_MAPMOVER_OBJECTS; i++)
  392. {
  393. if(MAPMOVER_OBJECTS[i][ModelID] != 0)
  394. {
  395. new Float:aOffSetX, Float:aOffSetY, Float:aOffSetZ;
  396. aOffSetX = floatsub(MAPMOVER_OBJECTS[i][PositionX], CenterX);
  397. aOffSetY = floatsub(MAPMOVER_OBJECTS[i][PositionY], CenterY);
  398. aOffSetZ = floatsub(MAPMOVER_OBJECTS[i][PositionZ], CenterZ);
  399. MAPMOVER_OBJECTS[i][OffSetX] = aOffSetX;
  400. MAPMOVER_OBJECTS[i][OffSetY] = aOffSetY;
  401. MAPMOVER_OBJECTS[i][OffSetZ] = aOffSetZ;
  402. AttachObjectToObject(MAPMOVER_OBJECTS[i][ObjectID], ObjectCenter, aOffSetX, aOffSetY, aOffSetZ, MAPMOVER_OBJECTS[i][RotationX], MAPMOVER_OBJECTS[i][RotationY], MAPMOVER_OBJECTS[i][RotationZ], true);
  403. }
  404. }
  405. new Float:fVX, Float:fVY, Float:fVZ, Float:object_x, Float:object_y, Float:object_z;
  406. const Float:fScale = 50.0;
  407. GetPlayerCameraFrontVector(playerid, fVX, fVY, fVZ);
  408. object_x = floatmul(fVX, fScale);
  409. object_y = floatmul(fVY, fScale);
  410. object_z = floatmul(fVZ, fScale);
  411. AttachObjectToObject(ObjectCenter, noclipdata[playerid][flyobject], object_x, object_y, object_z, 0.0, 0.0, 0.0, true);
  412. CamOffSetX = object_x;
  413. CamOffSetY = object_y;
  414. CamOffSetZ = object_z;
  415. Player_MovingObjects[playerid] = 2;
  416. }
  417. }
  418. }
  419. else ShowPlayerDialog(playerid, 803, DIALOG_STYLE_LIST, "Map Mover", "1. Locate\n2. Center position\n3. Edit positions\n4. Export map\n5. Exit (without saving)", "OK", "");
  420. }
  421. return 0;
  422. }
  423.  
  424. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
  425. {
  426. if((newkeys & KEY_CROUCH))
  427. {
  428. if(Player_MovingObjects[playerid] == 2)
  429. {
  430. new Float:rPX, Float:rPY, Float:rPZ, Float:rRX, Float:rRY, Float:rRZ;
  431. AttachObjectToObjectEx(noclipdata[playerid][flyobject], CamOffSetX, CamOffSetY, CamOffSetZ, 0.0, 0.0, 0.0, rPX, rPY, rPZ, rRX, rRY, rRZ, playerid);
  432. new ResolveObject = CreateObject(0, rPX, rPY, rPZ, rRX, rRY, rRZ);
  433. for(new i = 0; i != MAX_MAPMOVER_OBJECTS; i++)
  434. {
  435. if(MAPMOVER_OBJECTS[i][ModelID] != 0)
  436. {
  437. new Float:PX, Float:PY, Float:PZ;
  438. new Float:RX, Float:RY, Float:RZ;
  439. AttachObjectToObjectEx(ResolveObject, MAPMOVER_OBJECTS[i][OffSetX], MAPMOVER_OBJECTS[i][OffSetY], MAPMOVER_OBJECTS[i][OffSetZ], MAPMOVER_OBJECTS[i][RotationX], MAPMOVER_OBJECTS[i][RotationY], MAPMOVER_OBJECTS[i][RotationZ], PX, PY, PZ, RX, RY, RZ);
  440.  
  441. MAPMOVER_OBJECTS[i][OffSetX] = 0.0;
  442. MAPMOVER_OBJECTS[i][OffSetY] = 0.0;
  443. MAPMOVER_OBJECTS[i][OffSetZ] = 0.0;
  444.  
  445. DestroyObject(MAPMOVER_OBJECTS[i][ObjectID]);
  446. MAPMOVER_OBJECTS[i][ObjectID] = CreateObject(MAPMOVER_OBJECTS[i][ModelID], PX, PY, PZ, RX, RY, RZ);
  447. MAPMOVER_OBJECTS[i][PositionX] = PX;
  448. MAPMOVER_OBJECTS[i][PositionY] = PY;
  449. MAPMOVER_OBJECTS[i][PositionZ] = PZ;
  450. MAPMOVER_OBJECTS[i][RotationX] = RX;
  451. MAPMOVER_OBJECTS[i][RotationY] = RY;
  452. MAPMOVER_OBJECTS[i][RotationZ] = RZ;
  453. }
  454. }
  455. DestroyObject(ResolveObject);
  456. DestroyObject(ObjectCenter);
  457. ObjectCenter = CreateObject(1220, rPX, rPY, rPZ, 0.0, 0.0, 0.0);
  458. Player_MovingObjects[playerid] = 0;
  459. return 1;
  460. }
  461. }
  462. return 1;
  463. }
  464.  
  465. public OnPlayerEditObject(playerid, playerobject, objectid, response, Float:fX, Float:fY, Float:fZ, Float:fRotX, Float:fRotY, Float:fRotZ)
  466. {
  467. if(response == EDIT_RESPONSE_FINAL || response == EDIT_RESPONSE_CANCEL)
  468. {
  469. if(objectid == ObjectCenter)
  470. {
  471. SetObjectPos(objectid, fX, fY, fZ);
  472. SetObjectRot(objectid, fRotX, fRotY, fRotZ);
  473. if(Player_MovingObjects[playerid] == 1)
  474. {
  475. for(new i = 0; i != MAX_MAPMOVER_OBJECTS; i++)
  476. {
  477. if(MAPMOVER_OBJECTS[i][ModelID] != 0)
  478. {
  479. new Float:PX, Float:PY, Float:PZ;
  480. new Float:RX, Float:RY, Float:RZ;
  481. AttachObjectToObjectEx(ObjectCenter, MAPMOVER_OBJECTS[i][OffSetX], MAPMOVER_OBJECTS[i][OffSetY], MAPMOVER_OBJECTS[i][OffSetZ], MAPMOVER_OBJECTS[i][RotationX], MAPMOVER_OBJECTS[i][RotationY], MAPMOVER_OBJECTS[i][RotationZ], PX, PY, PZ, RX, RY, RZ);
  482.  
  483. MAPMOVER_OBJECTS[i][OffSetX] = 0.0;
  484. MAPMOVER_OBJECTS[i][OffSetY] = 0.0;
  485. MAPMOVER_OBJECTS[i][OffSetZ] = 0.0;
  486.  
  487. DestroyObject(MAPMOVER_OBJECTS[i][ObjectID]);
  488. MAPMOVER_OBJECTS[i][ObjectID] = CreateObject(MAPMOVER_OBJECTS[i][ModelID], PX, PY, PZ, RX, RY, RZ);
  489. MAPMOVER_OBJECTS[i][PositionX] = PX;
  490. MAPMOVER_OBJECTS[i][PositionY] = PY;
  491. MAPMOVER_OBJECTS[i][PositionZ] = PZ;
  492. MAPMOVER_OBJECTS[i][RotationX] = RX;
  493. MAPMOVER_OBJECTS[i][RotationY] = RY;
  494. MAPMOVER_OBJECTS[i][RotationZ] = RZ;
  495. }
  496. }
  497. SetObjectRot(objectid, 0.0, 0.0, 0.0);
  498. Player_MovingObjects[playerid] = 0;
  499. return 1;
  500. }
  501. SetObjectMaterial(ObjectCenter, 0, 0, "null", "null");
  502. SendClientMessage(playerid, -1, "{FFFF00}Map Mover: {FFFFFF}Use the {FFFF00}/map {FFFFFF}command again to show the main menu.");
  503. SetObjectRot(objectid, 0.0, 0.0, 0.0);
  504. }
  505. }
  506. return 1;
  507. }
  508.  
  509. AttachObjectToObjectEx(attachoid, Float:off_x, Float:off_y, Float:off_z, Float:rot_x, Float:rot_y, Float:rot_z, &Float:X, &Float:Y, &Float:Z, &Float:RX, &Float:RY, &Float:RZ, pobject = -1) // By Stylock - http://forum.sa-mp.com/member.php?u=114165
  510. {
  511. static
  512. Float:sin[3],
  513. Float:cos[3],
  514. Float:pos[3],
  515. Float:rot[3];
  516. if(pobject == -1)
  517. {
  518. GetObjectPos(attachoid, pos[0], pos[1], pos[2]);
  519. GetObjectRot(attachoid, rot[0], rot[1], rot[2]);
  520. }
  521. else
  522. {
  523. GetPlayerObjectPos(pobject, attachoid, pos[0], pos[1], pos[2]);
  524. GetPlayerObjectRot(pobject, attachoid, rot[0], rot[1], rot[2]);
  525. }
  526. EDIT_FloatEulerFix(rot[0], rot[1], rot[2]);
  527. cos[0] = floatcos(rot[0], degrees); cos[1] = floatcos(rot[1], degrees); cos[2] = floatcos(rot[2], degrees); sin[0] = floatsin(rot[0], degrees); sin[1] = floatsin(rot[1], degrees); sin[2] = floatsin(rot[2], degrees);
  528. pos[0] = pos[0] + off_x * cos[1] * cos[2] - off_x * sin[0] * sin[1] * sin[2] - off_y * cos[0] * sin[2] + off_z * sin[1] * cos[2] + off_z * sin[0] * cos[1] * sin[2];
  529. pos[1] = pos[1] + off_x * cos[1] * sin[2] + off_x * sin[0] * sin[1] * cos[2] + off_y * cos[0] * cos[2] + off_z * sin[1] * sin[2] - off_z * sin[0] * cos[1] * cos[2];
  530. pos[2] = pos[2] - off_x * cos[0] * sin[1] + off_y * sin[0] + off_z * cos[0] * cos[1];
  531. rot[0] = asin(cos[0] * cos[1]); rot[1] = atan2(sin[0], cos[0] * sin[1]) + rot_z; rot[2] = atan2(cos[1] * cos[2] * sin[0] - sin[1] * sin[2], cos[2] * sin[1] - cos[1] * sin[0] * -sin[2]);
  532. cos[0] = floatcos(rot[0], degrees); cos[1] = floatcos(rot[1], degrees); cos[2] = floatcos(rot[2], degrees); sin[0] = floatsin(rot[0], degrees); sin[1] = floatsin(rot[1], degrees); sin[2] = floatsin(rot[2], degrees);
  533. rot[0] = asin(cos[0] * sin[1]); rot[1] = atan2(cos[0] * cos[1], sin[0]); rot[2] = atan2(cos[2] * sin[0] * sin[1] - cos[1] * sin[2], cos[1] * cos[2] + sin[0] * sin[1] * sin[2]);
  534. cos[0] = floatcos(rot[0], degrees); cos[1] = floatcos(rot[1], degrees); cos[2] = floatcos(rot[2], degrees); sin[0] = floatsin(rot[0], degrees); sin[1] = floatsin(rot[1], degrees); sin[2] = floatsin(rot[2], degrees);
  535. rot[0] = atan2(sin[0], cos[0] * cos[1]) + rot_x; rot[1] = asin(cos[0] * sin[1]); rot[2] = atan2(cos[2] * sin[0] * sin[1] + cos[1] * sin[2], cos[1] * cos[2] - sin[0] * sin[1] * sin[2]);
  536. cos[0] = floatcos(rot[0], degrees); cos[1] = floatcos(rot[1], degrees); cos[2] = floatcos(rot[2], degrees); sin[0] = floatsin(rot[0], degrees); sin[1] = floatsin(rot[1], degrees); sin[2] = floatsin(rot[2], degrees);
  537. rot[0] = asin(cos[1] * sin[0]); rot[1] = atan2(sin[1], cos[0] * cos[1]) + rot_y; rot[2] = atan2(cos[0] * sin[2] - cos[2] * sin[0] * sin[1], cos[0] * cos[2] + sin[0] * sin[1] * sin[2]);
  538. X = pos[0];
  539. Y = pos[1];
  540. Z = pos[2];
  541. RX = rot[0];
  542. RY = rot[1];
  543. RZ = rot[2];
  544. }
  545.  
  546.  
  547. EDIT_FloatEulerFix(&Float:rot_x, &Float:rot_y, &Float:rot_z)
  548. {
  549. EDIT_FloatGetRemainder(rot_x, rot_y, rot_z);
  550. if((!floatcmp(rot_x, 0.0) || !floatcmp(rot_x, 360.0))
  551. && (!floatcmp(rot_y, 0.0) || !floatcmp(rot_y, 360.0)))
  552. {
  553. rot_y = 0.0000002;
  554. }
  555. return 1;
  556. }
  557.  
  558. EDIT_FloatGetRemainder(&Float:rot_x, &Float:rot_y, &Float:rot_z)
  559. {
  560. EDIT_FloatRemainder(rot_x, 360.0);
  561. EDIT_FloatRemainder(rot_y, 360.0);
  562. EDIT_FloatRemainder(rot_z, 360.0);
  563. return 1;
  564. }
  565.  
  566. EDIT_FloatRemainder(&Float:remainder, Float:value)
  567. {
  568. if(remainder >= value)
  569. {
  570. while(remainder >= value)
  571. {
  572. remainder = remainder - value;
  573. }
  574. }
  575. else if(remainder < 0.0)
  576. {
  577. while(remainder < 0.0)
  578. {
  579. remainder = remainder + value;
  580. }
  581. }
  582. return 1;
  583. }
  584. //--------------------------------------------------
  585.  
  586. public OnPlayerUpdate(playerid)
  587. {
  588. if(noclipdata[playerid][cameramode] == CAMERA_MODE_FLY)
  589. {
  590. new keys,ud,lr;
  591. GetPlayerKeys(playerid,keys,ud,lr);
  592. if(noclipdata[playerid][mode] && (GetTickCount() - noclipdata[playerid][lastmove] > 100))
  593. {
  594. // If the last move was > 100ms ago, process moving the object the players camera is attached to
  595. MoveCamera(playerid);
  596. }
  597.  
  598. // Is the players current key state different than their last keystate?
  599. if(noclipdata[playerid][udold] != ud || noclipdata[playerid][lrold] != lr)
  600. {
  601. if((noclipdata[playerid][udold] != 0 || noclipdata[playerid][lrold] != 0) && ud == 0 && lr == 0)
  602. { // All keys have been released, stop the object the camera is attached to and reset the acceleration multiplier
  603. StopPlayerObject(playerid, noclipdata[playerid][flyobject]);
  604. noclipdata[playerid][mode] = 0;
  605. noclipdata[playerid][accelmul] = 0.0;
  606. }
  607. else
  608. { // Indicates a new key has been pressed
  609.  
  610. // Get the direction the player wants to move as indicated by the keys
  611. noclipdata[playerid][mode] = GetMoveDirectionFromKeys(ud, lr);
  612.  
  613. // Process moving the object the players camera is attached to
  614. MoveCamera(playerid);
  615. }
  616. }
  617. noclipdata[playerid][udold] = ud; noclipdata[playerid][lrold] = lr; // Store current keys pressed for comparison next update
  618. return 0;
  619. }
  620. return 1;
  621. }
  622.  
  623. //--------------------------------------------------
  624.  
  625. stock GetMoveDirectionFromKeys(ud, lr)
  626. {
  627. new direction = 0;
  628.  
  629. if(lr < 0)
  630. {
  631. if(ud < 0) direction = MOVE_FORWARD_LEFT; // Up & Left key pressed
  632. else if(ud > 0) direction = MOVE_BACK_LEFT; // Back & Left key pressed
  633. else direction = MOVE_LEFT; // Left key pressed
  634. }
  635. else if(lr > 0) // Right pressed
  636. {
  637. if(ud < 0) direction = MOVE_FORWARD_RIGHT; // Up & Right key pressed
  638. else if(ud > 0) direction = MOVE_BACK_RIGHT; // Back & Right key pressed
  639. else direction = MOVE_RIGHT; // Right key pressed
  640. }
  641. else if(ud < 0) direction = MOVE_FORWARD; // Up key pressed
  642. else if(ud > 0) direction = MOVE_BACK; // Down key pressed
  643.  
  644. return direction;
  645. }
  646.  
  647. //--------------------------------------------------
  648.  
  649. stock MoveCamera(playerid)
  650. {
  651. new Float:FV[3], Float:CP[3];
  652. GetPlayerCameraPos(playerid, CP[0], CP[1], CP[2]); // Cameras position in space
  653. GetPlayerCameraFrontVector(playerid, FV[0], FV[1], FV[2]); // Where the camera is looking at
  654.  
  655. // Increases the acceleration multiplier the longer the key is held
  656. if(noclipdata[playerid][accelmul] <= 1) noclipdata[playerid][accelmul] += ACCEL_RATE;
  657.  
  658. // Determine the speed to move the camera based on the acceleration multiplier
  659. new Float:speed = MOVE_SPEED * noclipdata[playerid][accelmul];
  660.  
  661. // Calculate the cameras next position based on their current position and the direction their camera is facing
  662. new Float:X, Float:Y, Float:Z;
  663. GetNextCameraPosition(noclipdata[playerid][mode], CP, FV, X, Y, Z);
  664. MovePlayerObject(playerid, noclipdata[playerid][flyobject], X, Y, Z, speed);
  665.  
  666. // Store the last time the camera was moved as now
  667. noclipdata[playerid][lastmove] = GetTickCount();
  668. return 1;
  669. }
  670.  
  671. //--------------------------------------------------
  672.  
  673. stock GetNextCameraPosition(move_mode, Float:CP[3], Float:FV[3], &Float:X, &Float:Y, &Float:Z)
  674. {
  675. // Calculate the cameras next position based on their current position and the direction their camera is facing
  676. #define OFFSET_X (FV[0]*6000.0)
  677. #define OFFSET_Y (FV[1]*6000.0)
  678. #define OFFSET_Z (FV[2]*6000.0)
  679. switch(move_mode)
  680. {
  681. case MOVE_FORWARD:
  682. {
  683. X = CP[0]+OFFSET_X;
  684. Y = CP[1]+OFFSET_Y;
  685. Z = CP[2]+OFFSET_Z;
  686. }
  687. case MOVE_BACK:
  688. {
  689. X = CP[0]-OFFSET_X;
  690. Y = CP[1]-OFFSET_Y;
  691. Z = CP[2]-OFFSET_Z;
  692. }
  693. case MOVE_LEFT:
  694. {
  695. X = CP[0]-OFFSET_Y;
  696. Y = CP[1]+OFFSET_X;
  697. Z = CP[2];
  698. }
  699. case MOVE_RIGHT:
  700. {
  701. X = CP[0]+OFFSET_Y;
  702. Y = CP[1]-OFFSET_X;
  703. Z = CP[2];
  704. }
  705. case MOVE_BACK_LEFT:
  706. {
  707. X = CP[0]+(-OFFSET_X - OFFSET_Y);
  708. Y = CP[1]+(-OFFSET_Y + OFFSET_X);
  709. Z = CP[2]-OFFSET_Z;
  710. }
  711. case MOVE_BACK_RIGHT:
  712. {
  713. X = CP[0]+(-OFFSET_X + OFFSET_Y);
  714. Y = CP[1]+(-OFFSET_Y - OFFSET_X);
  715. Z = CP[2]-OFFSET_Z;
  716. }
  717. case MOVE_FORWARD_LEFT:
  718. {
  719. X = CP[0]+(OFFSET_X - OFFSET_Y);
  720. Y = CP[1]+(OFFSET_Y + OFFSET_X);
  721. Z = CP[2]+OFFSET_Z;
  722. }
  723. case MOVE_FORWARD_RIGHT:
  724. {
  725. X = CP[0]+(OFFSET_X + OFFSET_Y);
  726. Y = CP[1]+(OFFSET_Y - OFFSET_X);
  727. Z = CP[2]+OFFSET_Z;
  728. }
  729. }
  730. }
  731. //--------------------------------------------------
  732.  
  733. stock CancelFlyMode(playerid)
  734. {
  735. DeletePVar(playerid, "FlyMode");
  736. CancelEdit(playerid);
  737. TogglePlayerSpectating(playerid, false);
  738.  
  739. DestroyPlayerObject(playerid, noclipdata[playerid][flyobject]);
  740. noclipdata[playerid][cameramode] = CAMERA_MODE_NONE;
  741. return 1;
  742. }
  743.  
  744. //--------------------------------------------------
  745.  
  746. stock FlyMode(playerid)
  747. {
  748. // Create an invisible object for the players camera to be attached to
  749. new Float:X, Float:Y, Float:Z;
  750. GetPlayerPos(playerid, X, Y, Z);
  751. noclipdata[playerid][flyobject] = CreatePlayerObject(playerid, 19300, X, Y, Z, 0.0, 0.0, 0.0);
  752.  
  753. // Place the player in spectating mode so objects will be streamed based on camera location
  754. TogglePlayerSpectating(playerid, true);
  755. // Attach the players camera to the created object
  756. AttachCameraToPlayerObject(playerid, noclipdata[playerid][flyobject]);
  757.  
  758. SetPVarInt(playerid, "FlyMode", 1);
  759. noclipdata[playerid][cameramode] = CAMERA_MODE_FLY;
  760. return 1;
  761. }
  762.  
  763. //--------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement