Advertisement
Guest User

Distance Traveled

a guest
Jun 9th, 2010
649
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.34 KB | None | 0 0
  1. /******************************************************************************-
  2.  
  3. Ethan's distance travelled include
  4. ----------------------------------
  5.  
  6. Version: 1.0
  7.  
  8. Install:
  9.     1. Place the following under the appropriate callbacks:
  10.     -   DT_OnGameModeInit();
  11.     -   DT_OnPlayerRequestClass(playerid);
  12.     -   DT_OnPlayerConnect(playerid);
  13.     -   DT_OnPlayerDisconnect(playerid);
  14.     -   DT_OnPlayerSpawn(playerid);
  15.     -   DT_OnPlayerDeath(playerid);
  16.     -   DT_OnPlayerInteriorChange(playerid);
  17.     And Place this at the top of your script:
  18.     -   #indlude <DT>
  19.     2. If you want to save players distance traveled use the folowing variable:
  20.     -   Distance[playerid]
  21.     3. Have Fun!
  22.    
  23. Note:
  24.     If your server has teleports, make sure to use the folowing when
  25.     a player is teleported or it will count the distance of the teleport:
  26.     -   CheckDelay[playerid] = 2;
  27.     The 2 means two seconds which is the time the timer will not count
  28.     the movement
  29.  
  30. Do not re-create my work as your own!
  31.  
  32. -******************************************************************************/
  33.  
  34. // ------- Setting  ( Toggle: 1=on, 0=off) -------
  35. #define USE_TEXTDRAW 1
  36. // ------- ------- ------- ------- ------- -------
  37.  
  38. // ------- Useable Functions -------
  39. // native GetPlayerDistanceTraveled(playerid);
  40. // native SetPlayerDistanceTraveled(platerid, dist);
  41.  
  42. #include <a_samp>
  43.  
  44. new
  45.     Float:PosX[MAX_PLAYERS],
  46.     Float:PosY[MAX_PLAYERS],
  47.     Float:PosZ[MAX_PLAYERS],
  48.     #if USE_TEXTDRAW == 1
  49.     Text:Status[MAX_PLAYERS],
  50.     #endif
  51.     Distance[MAX_PLAYERS],
  52.     CheckDelay[MAX_PLAYERS],
  53.     SpawnTimes[MAX_PLAYERS],
  54.     Alive[MAX_PLAYERS];
  55.  
  56. // ------- System Include Functions -------
  57.  
  58. DT_OnGameModeInit()
  59. {
  60.     SetTimer("DistanceCheck",1000,1);
  61.     print("+--------------------------------------------+");
  62.     print("| Distance Traveled Include By Ethan Loaded. |");
  63.     print("+--------------------------------------------+");
  64. }
  65.  
  66. DT_OnPlayerRequestClass(playerid)
  67. {
  68.     Alive[playerid] = 0;
  69. }
  70.  
  71. DT_OnPlayerConnect(playerid)
  72. {
  73.     #if USE_TEXTDRAW == 1
  74.     Status[playerid] = TextDrawCreate(88.000000,312.000000," ");
  75.     TextDrawAlignment(Status[playerid],2);
  76.     TextDrawBackgroundColor(Status[playerid],0x000000ff);
  77.     TextDrawFont(Status[playerid],1);
  78.     TextDrawLetterSize(Status[playerid],0.299999,1.200000);
  79.     TextDrawColor(Status[playerid],0xffffffff);
  80.     TextDrawSetOutline(Status[playerid],1);
  81.     TextDrawSetProportional(Status[playerid],1);
  82.     TextDrawSetShadow(Status[playerid],1);
  83.     #endif
  84.     Distance[playerid] = 0;
  85.     Alive[playerid] = 0;
  86.     CheckDelay[playerid] = 0;
  87.     SpawnTimes[playerid] = 0;
  88. }
  89.  
  90. DT_OnPlayerDisconnect(playerid)
  91. {
  92.     #if USE_TEXTDRAW == 1
  93.     TextDrawDestroy(Status[playerid]);
  94.     #endif
  95.     Distance[playerid] = 0;
  96.     Alive[playerid] = 0;
  97.     CheckDelay[playerid] = 0;
  98.     SpawnTimes[playerid] = 0;
  99. }
  100.  
  101. DT_OnPlayerSpawn(playerid)
  102. {
  103.     Alive[playerid] = 1;
  104.     CheckDelay[playerid] = 2;
  105.     SpawnTimes[playerid]++;
  106.     if(SpawnTimes[playerid]==1) Distance[playerid] = 0;
  107. }
  108.  
  109. DT_OnPlayerDeath(playerid)
  110. {
  111.     Alive[playerid] = 0;
  112.     CheckDelay[playerid] = 10;
  113.     #if USE_TEXTDRAW == 1
  114.     TextDrawHideForPlayer(playerid, Status[playerid]);
  115.     #endif
  116. }
  117.  
  118. DT_OnPlayerInteriorChange(playerid)
  119. {
  120.     CheckDelay[playerid] = 2;
  121. }
  122.  
  123. // ------- Extra Functions -------
  124.  
  125. stock GetPlayerDistanceTraveled(playerid)
  126. {
  127.     return Distance[playerid];
  128. }
  129.  
  130. stock SetPlayerDistanceTraveled(playerid, dist)
  131. {
  132.     Distance[playerid] = dist;
  133.     return Distance[playerid];
  134. }
  135.  
  136. // ------- Main System -------
  137.  
  138. forward DistanceCheck();
  139. public DistanceCheck()
  140. {
  141.     for(new i=0; i<MAX_PLAYERS; i++)
  142.     {
  143.         if(IsPlayerConnected(i) && Alive[i] == 1)
  144.         {
  145.             new
  146.                 Float:dist,
  147.                 Float:X,
  148.                 Float:Y,
  149.                 Float:Z;
  150.             if(IsPlayerInAnyVehicle(i))
  151.             {
  152.                 GetVehiclePos(GetPlayerVehicleID(i),X,Y,Z);
  153.             }
  154.             else
  155.             {
  156.                 GetPlayerPos(i,X,Y,Z);
  157.             }
  158.             dist = floatsqroot(floatpower(floatabs(floatsub(PosX[i],X)),2)+floatpower(floatabs(floatsub(PosY[i],Y)),2)+floatpower(floatabs(floatsub(PosZ[i],Z)),2));
  159.             if(CheckDelay[i] >= 1)
  160.             {
  161.                 CheckDelay[i]--;
  162.             }
  163.             else
  164.             {
  165.                 if(floatround(dist) < 1000) Distance[i] += floatround(dist);
  166.             }
  167.             GetPlayerPos(i,PosX[i],PosY[i],PosZ[i]);
  168.             #if USE_TEXTDRAW == 1
  169.             new Str[64];
  170.             format(Str, sizeof(Str),"Distance Traveled: ~y~%d ft", Distance[i]);
  171.             TextDrawHideForPlayer(i,Status[i]);
  172.             TextDrawSetString(Status[i], Str);
  173.             TextDrawShowForPlayer(i,Status[i]);
  174.             #endif
  175.         }
  176.     }
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement