Advertisement
Guest User

Enhanced Gps System

a guest
Jan 25th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.32 KB | None | 0 0
  1. /*
  2. GPS - GPS System
  3. by BOSS
  4.  
  5.  
  6. ~ Features ~
  7. * You can easily add your locations by typing {"Location Name", X, Y, Z} in the location list below.
  8. * You can open and use the GPS by typing /GPS if not working do /nav in the game.
  9. * After selecting a location, the selected position is marked on the map, and also you can see the direction of the location by the arrow that appears on the vehicle.
  10. * You can also see how much distance to the destination with textdraw, which is shown on the screen.
  11. * GPS closes when you get out of the car, when you type /GPSclose or when you reach the destination.
  12.  
  13.  
  14. */
  15.  
  16. #include <a_samp>
  17. #include <zcmd>
  18.  
  19. new
  20. ok[MAX_PLAYERS],
  21. pGPSState[MAX_PLAYERS],
  22. pGPSID[MAX_PLAYERS],
  23. pGPSTimer[MAX_PLAYERS],
  24. PlayerText:GPSpTD[MAX_PLAYERS],
  25. Text:GPSTD[2]
  26. ;
  27.  
  28. enum GPS_DATA {
  29. GPS_NAME[32],
  30. Float:GPS_X,
  31. Float:GPS_Y,
  32. Float:GPS_Z
  33. };
  34.  
  35. new const GPSData[][GPS_DATA] = { // Location list in GPS:
  36. {"Construction Worker Job", 1266.3311,-1260.1604,13.2039}, // {"Location Name", X, Y, Z}
  37. {"Ammunation", 1365.3500,-1279.0601,13.5469}, // You can add your locations like this.
  38. {"Courier job", 2011.3181,-2219.6333,13.5469}, // Make sure that no comma at the end of the last one.
  39. {"Pay And Spray", 2073.4626,-1826.2062,13.5469} //For making more just copy this line and replace x,y,z
  40. };
  41.  
  42. public OnFilterScriptInit()
  43. {
  44.  
  45. print("\n+----------------------------------------------------+");
  46. print("| |");
  47. print("| Gps - GPS System ~ Loaded! |");
  48. print("| by BOSS |");
  49. print("| |");
  50. print("+----------------------------------------------------+\n");
  51.  
  52. GPSTD[0] = TextDrawCreate(404.319183, 409.916809, "box");
  53. TextDrawLetterSize(GPSTD[0], 0.000000, 1.941436);
  54. TextDrawTextSize(GPSTD[0], 498.000000, 0.000000);
  55. TextDrawAlignment(GPSTD[0], 1);
  56. TextDrawColor(GPSTD[0], -1);
  57. TextDrawUseBox(GPSTD[0], 1);
  58. TextDrawBoxColor(GPSTD[0], 100);
  59. TextDrawSetShadow(GPSTD[0], 0);
  60. TextDrawSetOutline(GPSTD[0], 0);
  61. TextDrawBackgroundColor(GPSTD[0], 255);
  62. TextDrawFont(GPSTD[0], 1);
  63. TextDrawSetProportional(GPSTD[0], 1);
  64. TextDrawSetShadow(GPSTD[0], 0);
  65.  
  66. GPSTD[1] = TextDrawCreate(404.787597, 399.999847, "GPS Info");
  67. TextDrawLetterSize(GPSTD[1], 0.299736, 1.115833);
  68. TextDrawAlignment(GPSTD[1], 1);
  69. TextDrawColor(GPSTD[1], -5963521);
  70. TextDrawSetShadow(GPSTD[1], 1);
  71. TextDrawSetOutline(GPSTD[1], 0);
  72. TextDrawBackgroundColor(GPSTD[1], 255);
  73. TextDrawFont(GPSTD[1], 0);
  74. TextDrawSetProportional(GPSTD[1], 1);
  75. TextDrawSetShadow(GPSTD[1], 1);
  76. return 1;
  77. }
  78.  
  79. public OnPlayerConnect(playerid)
  80. {
  81. GPSpTD[playerid] = CreatePlayerTextDraw(playerid, 405.724487, 415.166564, "Distance Left: ~y~0000.00m");
  82. PlayerTextDrawLetterSize(playerid, GPSpTD[playerid], 0.179326, 1.109999);
  83. PlayerTextDrawAlignment(playerid, GPSpTD[playerid], 1);
  84. PlayerTextDrawColor(playerid, GPSpTD[playerid], -1);
  85. PlayerTextDrawSetShadow(playerid, GPSpTD[playerid], 0);
  86. PlayerTextDrawSetOutline(playerid, GPSpTD[playerid], 0);
  87. PlayerTextDrawBackgroundColor(playerid, GPSpTD[playerid], 255);
  88. PlayerTextDrawFont(playerid, GPSpTD[playerid], 2);
  89. PlayerTextDrawSetProportional(playerid, GPSpTD[playerid], 1);
  90. PlayerTextDrawSetShadow(playerid, GPSpTD[playerid], 0);
  91. return 1;
  92. }
  93.  
  94. public OnPlayerDisconnect(playerid, reason)
  95. {
  96. if(pGPSState[playerid])
  97. {
  98. KillTimer(pGPSTimer[playerid]);
  99. DestroyObject(ok[playerid]);
  100. DisablePlayerCheckpoint(playerid);
  101. pGPSState[playerid] = 0;
  102. }
  103. return 1;
  104. }
  105.  
  106. CMD:GPS(playerid, params[])
  107. {
  108. if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, -1, "{FF0000}<!> You must be in a vehicle to use GPS!");
  109. static string[sizeof(GPSData) * 64];
  110.  
  111. if (string[0] == EOS)
  112. {
  113. for (new i; i < sizeof(GPSData); i++)
  114. {
  115. format(string, sizeof string, "%s{f4a442}ยป {f7f5bb}%s\n", string, GPSData[i][GPS_NAME]);
  116. }
  117. }
  118. ShowPlayerDialog(playerid, 112, DIALOG_STYLE_LIST, "[GPS] Locations", string, "Select", "Close");
  119. return 1;
  120. }
  121.  
  122. CMD:GPSclose(playerid, params[])
  123. {
  124. if(pGPSState[playerid])
  125. {
  126. KillTimer(pGPSTimer[playerid]);
  127. DestroyObject(ok[playerid]);
  128. for(new i; i<sizeof(GPSTD); i++) TextDrawHideForPlayer(playerid, GPSTD[i]);
  129. PlayerTextDrawHide(playerid, GPSpTD[playerid]);
  130. PlayerPlaySound(playerid,1137,0.0,0.0,0.0);
  131. DisablePlayerCheckpoint(playerid);
  132. pGPSState[playerid] = 0;
  133. SendClientMessage(playerid, -1, "{FF0000}<!> GPS cancelled!");
  134. } else SendClientMessage(playerid, -1, "{FF0000}<!> GPS is already off!");
  135. return 1;
  136. }
  137.  
  138. public OnPlayerStateChange(playerid, newstate, oldstate)
  139. {
  140. if(pGPSState[playerid])
  141. {
  142. KillTimer(pGPSTimer[playerid]);
  143. DestroyObject(ok[playerid]);
  144. for(new i; i<sizeof(GPSTD); i++) TextDrawHideForPlayer(playerid, GPSTD[i]);
  145. PlayerTextDrawHide(playerid, GPSpTD[playerid]);
  146. PlayerPlaySound(playerid,1150,0.0,0.0,0.0);
  147. DisablePlayerCheckpoint(playerid);
  148. pGPSState[playerid] = 0;
  149. SendClientMessage(playerid, -1, "{FF0000}<!> GPS is cancelled because you are off the vehicle!");
  150. }
  151. return 1;
  152. }
  153.  
  154. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  155. {
  156. if(dialogid == 112)
  157. {
  158. if(response)
  159. {
  160. if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, -1, "{FF0000}<!> You must be in a vehicle to use GPS!");
  161. pGPSID[playerid] = listitem;
  162. new str[128];
  163. SetPlayerCheckpoint(playerid, GPSData[pGPSID[playerid]][GPS_X], GPSData[pGPSID[playerid]][GPS_Y], GPSData[pGPSID[playerid]][GPS_Z], 3.0);
  164. format(str, 128, "{00FF00}<!> Destination is set to {FFA500}%s", GPSData[pGPSID[playerid]][GPS_NAME]);
  165. SendClientMessage(playerid, -1, str);
  166. SendClientMessage(playerid, -1, "{00FF00}<!> You can type {FF7D0A}/GPSclose {00FF00}to cancel the GPS.");
  167. if(IsValidObject(ok[playerid])) DestroyObject(ok[playerid]);
  168. ok[playerid] = CreateObject(19134, 0, 0, 0, 0, 0, 0);
  169. Refresh(playerid);
  170. KillTimer(pGPSTimer[playerid]);
  171. pGPSTimer[playerid] = SetTimerEx("Refresh", 100, true, "d", playerid);
  172. for(new i; i<sizeof(GPSTD); i++) TextDrawShowForPlayer(playerid, GPSTD[i]);
  173. PlayerTextDrawShow(playerid, GPSpTD[playerid]);
  174. PlayerPlaySound(playerid,1139,0.0,0.0,0.0);
  175. pGPSState[playerid] = 1;
  176. }
  177. }
  178. return 1;
  179. }
  180.  
  181. stock Float:PointAngle(playerid, Float:xa, Float:ya, Float:xb, Float:yb) // Don't know the owner.
  182. {
  183. new Float:carangle;
  184. new Float:xc, Float:yc;
  185. new Float:angle;
  186. xc = floatabs(floatsub(xa,xb));
  187. yc = floatabs(floatsub(ya,yb));
  188. if (yc == 0.0 || xc == 0.0)
  189. {
  190. if(yc == 0 && xc > 0) angle = 0.0;
  191. else if(yc == 0 && xc < 0) angle = 180.0;
  192. else if(yc > 0 && xc == 0) angle = 90.0;
  193. else if(yc < 0 && xc == 0) angle = 270.0;
  194. else if(yc == 0 && xc == 0) angle = 0.0;
  195. }
  196. else
  197. {
  198. angle = atan(xc/yc);
  199. if(xb > xa && yb <= ya) angle += 90.0;
  200. else if(xb <= xa && yb < ya) angle = floatsub(90.0, angle);
  201. else if(xb < xa && yb >= ya) angle -= 90.0;
  202. else if(xb >= xa && yb > ya) angle = floatsub(270.0, angle);
  203. }
  204. GetVehicleZAngle(GetPlayerVehicleID(playerid), carangle);
  205. return floatadd(angle, -carangle);
  206. }
  207.  
  208. forward Refresh(playerid);
  209. public Refresh(playerid)
  210. {
  211. new Float:pos[3], Float:pPos[3];
  212. pPos[0] = GPSData[pGPSID[playerid]][GPS_X];
  213. pPos[1] = GPSData[pGPSID[playerid]][GPS_Y];
  214. pPos[2] = GPSData[pGPSID[playerid]][GPS_Z];
  215. GetVehiclePos(GetPlayerVehicleID(playerid), pos[0], pos[1], pos[2]);
  216. new Float:rot = PointAngle(playerid, pos[0], pos[1], pPos[0], pPos[1]);
  217. AttachObjectToVehicle(ok[playerid], GetPlayerVehicleID(playerid), 0.000000, 0.000000, 1.399998, 0.000000, 90.0, rot + 180);
  218. new Float:mesafe, str[32];
  219. mesafe = GetPlayerDistanceFromPoint(playerid, pPos[0], pPos[1], pPos[2]);
  220. format(str, sizeof(str), "Distance Left: ~y~%0.2fm", mesafe);
  221. PlayerTextDrawSetString(playerid, GPSpTD[playerid], str);
  222. if(IsPlayerInRangeOfPoint(playerid, 10.0, pPos[0], pPos[1], pPos[2]))
  223. {
  224. KillTimer(pGPSTimer[playerid]);
  225. DestroyObject(ok[playerid]);
  226. for(new i; i<sizeof(GPSTD); i++) TextDrawHideForPlayer(playerid, GPSTD[i]);
  227. PlayerTextDrawHide(playerid, GPSpTD[playerid]);
  228. DisablePlayerCheckpoint(playerid);
  229. PlayerPlaySound(playerid,1137,0.0,0.0,0.0);
  230. pGPSState[playerid] = 0;
  231. SendClientMessage(playerid, -1, "{00FF00}<!> You have reached your destination!");
  232. }
  233. return 1;
  234. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement