Advertisement
Guest User

Dark_Team PT

a guest
Nov 14th, 2009
1,424
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. #include <a_samp>
  2. new GPSTimer[MAX_PLAYERS];
  3. new bool:HaveGPS[MAX_PLAYERS];
  4.  
  5. strtok(const string[], &index)
  6. {
  7. new length = strlen(string);
  8. while ((index < length) && (string[index] <= ' '))
  9. {
  10. index++;
  11. }
  12.  
  13. new offset = index;
  14. new result[20];
  15. while ((index < length) && (string[index] > ' ') && ((index - offset) < (sizeof(result) - 1)))
  16. {
  17. result[index - offset] = string[index];
  18. index++;
  19. }
  20. result[index - offset] = EOS;
  21. return result;
  22. }
  23.  
  24. stock GetDistanceBetweenPlayers(playerid,playerid2){
  25. new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
  26. new Float:dis;
  27. GetPlayerPos(playerid,x1,y1,z1);
  28. GetPlayerPos(playerid2,x2,y2,z2);
  29. dis = floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
  30. return floatround(dis);
  31. }
  32.  
  33. forward GPSUpdate(playerid,playerid2);
  34. public GPSUpdate(playerid,playerid2){
  35. if(IsPlayerConnected(playerid2)){
  36. new Float:Distnace;
  37. Distnace = GetDistanceBetweenPlayers(playerid,playerid2);
  38. new Float:X,Float:Y,Float:Z;
  39. GetPlayerPos(playerid2,X,Y,Z);
  40. DisablePlayerCheckpoint(playerid);
  41. SetPlayerCheckpoint(playerid,X,Y,Z,0.1);
  42. new string[128];
  43. format(string, sizeof(string), "~n~~n~~n~~n~~n~~n~~n~~n~~p~Distancia: ~r~%.1f ~y~m",Distnace);
  44. GameTextForPlayer(playerid, string, 1100, 5);
  45. if(Distnace <= 4.0) {
  46. DisablePlayerCheckpoint(playerid);
  47. KillTimer(GPSTimer[playerid]);
  48. HaveGPS[playerid] = false;
  49. GPSTimer[playerid] = 0;
  50. }
  51. }else{
  52. DisablePlayerCheckpoint(playerid);
  53. KillTimer(GPSTimer[playerid]);
  54. HaveGPS[playerid] = false;
  55. GPSTimer[playerid] = 0;
  56. SendClientMessage(playerid, 0xFF0000AA, "GPS: N�o encontrado.");
  57. }
  58. return 1;
  59. }
  60.  
  61. public OnFilterScriptInit()
  62. {
  63. print("\n* GPS by Jefff carregado...\n");
  64. return 1;
  65. }
  66.  
  67. public OnFilterScriptExit()
  68. {
  69. print("\n* GPS by Jefff desligado...\n");
  70. return 1;
  71. }
  72.  
  73. public OnPlayerConnect(playerid)
  74. {
  75. GPSTimer[playerid] = 0;
  76. HaveGPS[playerid] = false;
  77. SendClientMessage(playerid, 0xFFFFFFAA, "Este servidor usa um sistema de GPS feito por Jefff (/gps)");
  78. return 1;
  79. }
  80.  
  81. public OnPlayerDisconnect(playerid, reason)
  82. {
  83. if(HaveGPS[playerid]) {
  84. KillTimer(GPSTimer[playerid]);
  85. HaveGPS[playerid] = false;
  86. GPSTimer[playerid] = 0;
  87. }
  88. return 1;
  89. }
  90.  
  91. public OnPlayerDeath(playerid, killerid, reason)
  92. {
  93. if(HaveGPS[playerid]) {
  94. KillTimer(GPSTimer[playerid]);
  95. HaveGPS[playerid] = false;
  96. GPSTimer[playerid] = 0;
  97. }
  98. return 1;
  99. }
  100.  
  101. public OnPlayerCommandText(playerid, cmdtext[])
  102. {
  103. new cmd[64],tmp[64],idx;
  104. cmd = strtok(cmdtext,idx);
  105. if(!strcmp(cmd, "/gps", true))
  106. {
  107. tmp = strtok(cmdtext,idx);
  108. if(!strlen(tmp)) return SendClientMessage(playerid, 0xFFFFFFAA, "Use: /gps [playerid / off]");
  109. if(!strcmp(tmp, "off", true)) {
  110. if(HaveGPS[playerid]) {
  111. KillTimer(GPSTimer[playerid]);
  112. HaveGPS[playerid] = false;
  113. GPSTimer[playerid] = 0;
  114. DisablePlayerCheckpoint(playerid);
  115. SendClientMessage(playerid, 0xFFFF00AA, "GPS: Desligado.");
  116. }else SendClientMessage(playerid, 0xFF0000AA, "GPS: Seu GPS est� desligado !");
  117. return 1;
  118. }
  119. if(IsPlayerConnected(strval(tmp))) {
  120. if(strval(tmp) != playerid) {
  121. if(HaveGPS[playerid]) {
  122. KillTimer(GPSTimer[playerid]);
  123. HaveGPS[playerid] = false;
  124. GPSTimer[playerid] = 0;
  125. }
  126. GPSTimer[playerid] = SetTimerEx("GPSUpdate", 500, true, "dd", playerid,strval(tmp));
  127. HaveGPS[playerid] = true;
  128. new str[128],nick[24];
  129. GetPlayerName(strval(tmp),nick,24);
  130. format(str,128,"GPS: Ligado, alvo: %s (ID: %d)",nick,strval(tmp));
  131. SendClientMessage(playerid, 0xFFFF00AA, str);
  132. }else SendClientMessage(playerid, 0xFF0000AA, "GPS: Use corretamente o seu GPS !");
  133. }else SendClientMessage(playerid, 0xFF0000AA, "GPS: Alvo n�o encontrado(ID errado) !");
  134. return 1;
  135. }
  136. return 0;
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement