Guest User

klavins21

a guest
Jan 27th, 2009
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.02 KB | None | 0 0
  1. /* CPS by DragSta */
  2.  
  3. /* natives
  4. native CreateCheckpoint(playerid, Float:cpX, Float:cpY, Float:cpZ, Float:cpS, Float:viewdiss);
  5. native DestroyCheckpoint(cPid);
  6. native SyncCheckpoints(playerid);
  7. native StartSystem();
  8. native ClearVars(playerid);
  9. native CheckpointCheck(playerid);
  10. native TogglePlayerCheckpoint(playerid, Cpid, bool:toggle);
  11. */
  12.  
  13. #include <a_samp>
  14.  
  15. #define CP_TIMER_INTERVAL 300
  16.  
  17. #define ClearVars(%1); for(new i; i < MAX_STREAMED_CPS; i ++) pCPActive[ %1 ][ i ] = false;
  18. #define SyncCheckpoints(%1); for(new i; i < MAX_STREAMED_CPS; i ++) { if(gCheckPoints[ i ][ global ]) { for(new k; k < MAX_PLAYERS; k ++) { pShown[ k ][ i ] = true; } } }
  19. #define CheckpointCheck(%1); if(pCPID[ %1 ] != INVALID_CP_VALUE) { OnPlayerEnterStreamedCheckpoint(%1, pCPID[ %1 ]); return 1; }
  20. #define VERSION "0.1a"
  21. #define INVALID_CP_VALUE -255
  22. #define INVALID_CP_VALUEF -255.0
  23. #define MAX_STREAMED_CPS 200
  24.  
  25. forward OnPlayerEnterStreamedCheckpoint(playerid, streamid);
  26.  
  27. new cpID = -1;
  28. enum CP_ENUM
  29. {
  30. cpid,
  31. Float:Xx,
  32. Float:Yy,
  33. Float:Zz,
  34. Float:Size,
  35. bool:active,
  36. Float:viewdis,
  37. bool:global
  38. };
  39. new gCheckPoints[MAX_STREAMED_CPS][CP_ENUM];
  40.  
  41. new bool:pCPActive[MAX_PLAYERS][MAX_STREAMED_CPS];
  42. new bool:pShown[MAX_PLAYERS][MAX_STREAMED_CPS];
  43. new pCPID[MAX_PLAYERS];
  44.  
  45. stock CreateCheckpoint(playerid, Float:cpX, Float:cpY, Float:cpZ, Float:cpS, Float:viewdiss)
  46. {
  47. cpID ++;
  48. gCheckPoints[ cpID ][ cpid ] = cpID;
  49. gCheckPoints[ cpID ][ Xx ] = cpX;
  50. gCheckPoints[ cpID ][ Yy ] = cpY;
  51. gCheckPoints[ cpID ][ Zz ] = cpZ;
  52. gCheckPoints[ cpID ][ Size ] = cpS;
  53. gCheckPoints[ cpID ][ active ] = true;
  54. gCheckPoints[ cpID ][ viewdis ] = viewdiss;
  55. if(playerid == -1)
  56. {
  57. gCheckPoints[ cpID ][ global ] = true;
  58. for(new i; i < MAX_PLAYERS; i ++)
  59. {
  60. pShown[ i ][ cpID ] = true;
  61. }
  62. }
  63. else if(playerid != -1)
  64. {
  65. pShown[ playerid ][ cpID ] = true;
  66. gCheckPoints[ cpID ][ global ] = false;
  67. for(new i; i < MAX_PLAYERS; i ++)
  68. {
  69. if(i != playerid)
  70. {
  71. pShown[ i ][ cpID ] = false;
  72. }
  73. }
  74. }
  75. return cpID;
  76. }
  77.  
  78. stock TogglePlayerCheckpoint(playerid, Cpid, bool:toggle)
  79. {
  80. pShown[ playerid ][ Cpid ] = toggle;
  81. return 1;
  82. }
  83.  
  84. stock DestroyCheckpoint(cPid)
  85. {
  86. gCheckPoints[ cPid ][ cpid ] = INVALID_CP_VALUE;
  87. gCheckPoints[ cPid ][ Xx ] = INVALID_CP_VALUEF;
  88. gCheckPoints[ cPid ][ Yy ] = INVALID_CP_VALUEF;
  89. gCheckPoints[ cPid ][ Zz ] = INVALID_CP_VALUEF;
  90. gCheckPoints[ cPid ][ Size ] = INVALID_CP_VALUEF;
  91. gCheckPoints[ cPid ][ active ] = false;
  92. gCheckPoints[ cPid ][ viewdis ] = INVALID_CP_VALUEF;
  93. return 1;
  94. }
  95.  
  96. stock StartSystem()
  97. {
  98. SetTimer("CPUpdate", CP_TIMER_INTERVAL, 1);
  99. return 1;
  100. }
  101.  
  102. forward CPUpdate();
  103. public CPUpdate()
  104. {
  105. new Float:pPos[3];
  106. for(new i; i < MAX_PLAYERS; i ++)
  107. {
  108. if(IsPlayerConnected(i))
  109. {
  110. GetPlayerPos(i, pPos[ 0 ], pPos[ 1 ], pPos[ 2 ]);
  111. for(new j; j < MAX_STREAMED_CPS; j ++)
  112. {
  113. if(gCheckPoints[ j ][ active ])
  114. {
  115. if(pShown[ i ][ j ] && DistanceBetweenPoints(pPos[ 0 ], pPos[ 1 ], pPos[ 2 ], gCheckPoints[ j ][ Xx ], gCheckPoints[ j ][ Yy ], gCheckPoints[ j ][ Zz ]) <= gCheckPoints[ j ][ viewdis ])
  116. {
  117. if(!pCPActive[ i ][ j ])
  118. {
  119. SetPlayerCheckpoint(i, gCheckPoints[ j ][ Xx ], gCheckPoints[ j ][ Yy ], gCheckPoints[ j ][ Zz ], gCheckPoints[ j ][ Size ]);
  120. pCPActive[ i ][ j ] = true;
  121. pCPID[ i ] = j;
  122. }
  123. }
  124. else
  125. {
  126. if(pCPActive[ i ][ j ])
  127. {
  128. DisablePlayerCheckpoint(i);
  129. pCPActive[ i ][ j ] = false;
  130. pCPID[ i ] = INVALID_CP_VALUE;
  131. }
  132. }
  133. }
  134. }
  135. }
  136. }
  137. }
  138.  
  139. //forward Float:DistanceBetweenPoints(Float:x11, Float:y11, Float:z11, Float:x22, Float:y22, Float:z22);
  140. Float:DistanceBetweenPoints(Float:x11, Float:y11, Float:z11, Float:x22, Float:y22, Float:z22)
  141. return floatsqroot(floatpower(floatabs(floatsub(x22,x11)),2)+floatpower(floatabs(floatsub(y22,y11)),2)+floatpower(floatabs(floatsub(z22,z11)),2));
  142.  
Advertisement
Add Comment
Please, Sign In to add comment