Guest User

Untitled

a guest
May 13th, 2020
1,581
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.00 KB | None | 0 0
  1. //Gps System By Shaheen//.........
  2.  
  3.  
  4. #define MAX_LIMITOBJ 25 //do not change
  5. #include <a_samp>
  6. #include <zcmd>
  7. #include <sscanf2>
  8. #include <GPS>
  9.  
  10. //------------------ //
  11. new GpsObject[MAX_PLAYERS][MAX_LIMITOBJ];
  12. new GpsUpdateTimer[MAX_PLAYERS];
  13. new MapNode:Nodess[MAX_PLAYERS][MAX_LIMITOBJ];
  14. new bool:IsinGps[MAX_PLAYERS];
  15. new MapNode:ChangeNode[MAX_PLAYERS][7];
  16.  
  17. //----------------------//
  18. forward destroyGpsObjects(playerid,size);
  19. forward FindPathGpsUpdate(playerid,Float:TarX,Float:TarY,Float:TarZ,size);
  20. forward FindPathGps(playerid,Float:TarX,Float:TarY,Float:TarZ);
  21.  
  22.  
  23. public FindPathGps(playerid,Float:TarX,Float:TarY,Float:TarZ)
  24. {
  25. new Float:x, Float:y, Float:z, MapNode:start,MapNode:target,Path:pathid;
  26. GetPlayerPos(playerid, x, y, z);
  27. GetClosestMapNodeToPoint(x, y, z, start);
  28. GetClosestMapNodeToPoint(TarX,TarY,TarZ, target);
  29. FindPath(start, target, pathid);
  30. new MapNode:nodeid, Float:xxx, Float:yyy, Float:zzz , Float:ANGLE;
  31. for (new index; index < 25; index++)
  32. {
  33. GetPathNode(pathid, index, nodeid);
  34. if(index != 0)
  35. {
  36. GetMapNodePos(ChangeNode[playerid][6], xxx, yyy, zzz);
  37. GetMapNodeAngleFromPoint(nodeid,xxx, yyy, ANGLE);
  38. }
  39. GpsObject[playerid][index] = CreatePlayerObject(playerid, 1318, xxx, yyy, zzz+0.7,0,120, ANGLE);
  40. if(index == 20)
  41. {
  42. ChangeNode[playerid][4] = nodeid;
  43. }
  44. if(index == 19)
  45. {
  46. ChangeNode[playerid][5] = nodeid;
  47. }
  48. if(index == 21)
  49. {
  50. ChangeNode[playerid][0] = nodeid;
  51. }
  52. if(index == 22)
  53. {
  54. ChangeNode[playerid][1] = nodeid;
  55. }
  56. if(index == 23)
  57. {
  58. ChangeNode[playerid][2] = nodeid;
  59. }
  60. if(index == 24)
  61. {
  62. ChangeNode[playerid][3] = nodeid;
  63. }
  64. Nodess[playerid][index] = nodeid;
  65. ChangeNode[playerid][6] = nodeid;
  66. }
  67. GpsUpdateTimer[playerid] = SetTimerEx("FindPathGpsUpdate", 1500, true, "dfffd", playerid,TarX, TarY, TarZ,25);
  68. IsinGps[playerid] = true;
  69. return 1;
  70. }
  71.  
  72. public FindPathGpsUpdate(playerid,Float:TarX,Float:TarY,Float:TarZ,size)
  73. {
  74. if(IsinGps[playerid])
  75. {
  76. new Float:x,Float:y,Float:z,MapNode:Source,MapNode:Target;
  77. GetPlayerPos(playerid,x,y,z);
  78. GetClosestMapNodeToPoint(x, y, z, Source);
  79. GetClosestMapNodeToPoint(TarX, TarY, TarZ, Target);
  80. if (Source == Target)
  81. {
  82. KillTimer(GpsUpdateTimer[playerid]);
  83. destroyGpsObjects(playerid,25);
  84. SendClientMessage(playerid,-1,"Reached Destination");
  85. IsinGps[playerid] = false;
  86. return 1;
  87. }
  88. new bool:found=false;
  89. for(new i=0; i < 25; i++)
  90. {
  91. if (Source == ChangeNode[playerid][5] || Source == ChangeNode[playerid][3] || Source == ChangeNode[playerid][4] || Source == ChangeNode[playerid][0] ||Source == ChangeNode[playerid][1] || Source == ChangeNode[playerid][2] )
  92. {
  93. found = true;
  94. break;
  95. }
  96. else if(Nodess[playerid][i] == Source)
  97. {
  98. return 1;
  99. }
  100. else
  101. {
  102. found = true;
  103. }
  104. }
  105. if(found)
  106. {
  107. KillTimer(GpsUpdateTimer[playerid]);
  108. destroyGpsObjects(playerid,25);
  109. FindPathGps(playerid,TarX, TarY, TarZ);
  110. return 1;
  111. }
  112. }
  113. return 1;
  114. }
  115.  
  116.  
  117. public destroyGpsObjects(playerid,size)
  118. {
  119. for(new i=0; i< 25; i++)
  120. {
  121. if(IsValidPlayerObject(playerid, GpsObject[playerid][i])) //only destroy if its valid
  122. {
  123. DestroyPlayerObject(playerid, GpsObject[playerid][i]);
  124. }
  125. }
  126. return 1;
  127. }
  128.  
  129.  
  130. CMD:gpsoff(playerid)
  131. {
  132. destroyGpsObjects(playerid,MAX_LIMITOBJ);
  133. KillTimer(GpsUpdateTimer[playerid]);
  134. IsinGps[playerid] = false;
  135. SendClientMessage(playerid,-1,"Gps has been Turned Off");
  136. return 1;
  137. }
  138.  
  139.  
  140. COMMAND:findpath(playerid, params[])
  141. {
  142. new Float:x, Float:y, Float:z;
  143. if(sscanf(params, "p<,>fff", x, y, z))
  144. {
  145. SendClientMessage(playerid,-1,"Usage: /findpath <x,y,z>");
  146. }
  147. else
  148. {
  149. FindPathGps(playerid, x, y, z);
  150. SendClientMessage(playerid,-1,"Gps has been Turned On");
  151. }
  152. return 1;
  153. }
Add Comment
Please, Sign In to add comment