Advertisement
Guest User

Untitled

a guest
Nov 26th, 2012
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. #pragma once
  2.  
  3. /*
  4. ROUTER PLUGIN
  5. - GPS ADDITION TO SA-MP
  6. - Made By Gamer_Z a.k.a. grasmanek94 , Rafal Grasman
  7.  
  8. October-2011
  9.  
  10.  
  11. contact: grasmanek94@live.nl
  12.  
  13. */
  14. cell ppamx_addr = NULL;
  15. cell * ppamx_physAddr = NULL;
  16. PLUGIN_EXPORT void PLUGIN_CALL
  17. ProcessTick()
  18. {
  19. if(g_Ticked++ == g_TickMax)
  20. {
  21. if(!PassVector.empty())
  22. {
  23. Lock q (mutex_p);
  24. int tries = 0;
  25. while (q.acquire (1) == false && ++tries < 10)
  26. {
  27. }
  28. if(q.locked)
  29. {
  30. int ptr;
  31. float Cx;
  32. for (std::vector<AMX *>::iterator a = amx_list.begin(); a != amx_list.end(); ++a)
  33. {
  34. if (!amx_FindPublic(* a, "GPS_WhenRouteIsCalculated", &ptr) && PassVector.front().script == *a)
  35. {
  36. Cx = (float)PassVector.front().MoveCost;
  37. amx_Push(* a, amx_ftoc(Cx));
  38. amx_Push(* a, PassVector.front().Paths.size());
  39. cell * RawPath = new cell[PassVector.front().Paths.size()+1];
  40. copy(PassVector.front().Paths.begin(),PassVector.front().Paths.end(),RawPath);
  41. amx_PushArray(* a, &ppamx_addr, &ppamx_physAddr, RawPath, PassVector.front().Paths.size()+1);
  42. amx_Push(* a, PassVector.front().extraid);
  43. amx_Exec(* a, NULL, ptr);
  44. amx_Release(* a,ppamx_addr);
  45. free(RawPath);
  46. }
  47. }
  48. PassVector.pop();
  49. q.release ();
  50. }
  51. }
  52. if(OnPCNIDCenable == true)
  53. {
  54. int playerid = 0;
  55. int size = PlayerLoopList.size();
  56. for (int index = 0; index < size; ++index)
  57. {
  58. playerid = PlayerLoopList.at(index);
  59.  
  60. if(CheckPlayerOCNIDC[playerid] == false)
  61. {
  62. continue;
  63. }
  64. int Nearest = -1;
  65. double prevdist = 4800000000.11f;//(40000*40000)*3+0.11
  66. double newdist;
  67.  
  68. float X;
  69. float Y;
  70. float Z;
  71.  
  72. GetPlayerPos(playerid,&X,&Y,&Z);
  73. if(UseRealClosestDistance == true)
  74. {
  75. ChangeNode[playerid].lastID = ChangeNode[playerid].newID;
  76. for(int i = 0; i < MAX_NODES; ++i)
  77. {
  78. if(xNode[i].Exists == false)
  79. continue;
  80. newdist = sqrt(pow(xNode[i].xPOS-X,2.0f)+pow(xNode[i].yPOS-Y,2.0f)+pow(xNode[i].zPOS-Z,2.0f));
  81. if(newdist < prevdist)
  82. {
  83. prevdist = newdist;
  84. Nearest = i;
  85. }
  86. }
  87. }
  88. else
  89. {
  90. int Xloc = 0, Yloc = 0;
  91. GetArea(Xloc,Yloc,X,Y);
  92. ChangeNode[playerid].lastID = ChangeNode[playerid].newID;
  93. for(int i = 0,j = (int)Area[Xloc][Yloc].size(); i < j; ++i)
  94. {
  95. int NDX = Area[Xloc][Yloc].at(i).NodeID;
  96. if(xNode[NDX].Exists == false)
  97. continue;
  98. newdist = sqrt(pow(xNode[NDX].xPOS-X,2.0f)+pow(xNode[NDX].yPOS-Y,2.0f)+pow(xNode[NDX].zPOS-Z,2.0f));
  99. if(newdist < prevdist)
  100. {
  101. prevdist = newdist;
  102. Nearest = NDX;
  103. }
  104. }
  105. }
  106. ChangeNode[playerid].newID = Nearest;
  107. if(ChangeNode[playerid].lastID != ChangeNode[playerid].newID && ChangeNode[playerid].lastID != (-1))
  108. {
  109. OnPlayerClosestNodeIDChange(playerid, ChangeNode[playerid].lastID,ChangeNode[playerid].newID);
  110. }
  111. }
  112. }
  113. g_Ticked = 0;
  114. }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement