Advertisement
Chip7

[FS] Sistema de GPS Avançado

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