Guest User

Untitled

a guest
Jul 19th, 2018
87
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. //forward Float:DistanceBetweenPoints(Float:x11, Float:y11, Float:z11, Float:x22, Float:y22, Float:z22);
  28. Float:DistanceBetweenPoints(Float:x11, Float:y11, Float:z11, Float:x22, Float:y22, Float:z22)
  29. return floatsqroot(floatpower(floatabs(floatsub(x22,x11)),2)+floatpower(floatabs(floatsub(y22,y11)),2)+floatpower(floatabs(floatsub(z22,z11)),2));
  30.  
  31. new cpID = -1;
  32. enum CP_ENUM
  33. {
  34. cpid,
  35. Float:Xx,
  36. Float:Yy,
  37. Float:Zz,
  38. Float:Size,
  39. bool:active,
  40. Float:viewdis,
  41. bool:global
  42. };
  43. new gCheckPoints[MAX_STREAMED_CPS][CP_ENUM];
  44.  
  45. new bool:pCPActive[MAX_PLAYERS][MAX_STREAMED_CPS];
  46. new bool:pShown[MAX_PLAYERS][MAX_STREAMED_CPS];
  47. new pCPID[MAX_PLAYERS];
  48.  
  49. stock CreateCheckpoint(playerid, Float:cpX, Float:cpY, Float:cpZ, Float:cpS, Float:viewdiss)
  50. {
  51. cpID ++;
  52. gCheckPoints[ cpID ][ cpid ] = cpID;
  53. gCheckPoints[ cpID ][ Xx ] = cpX;
  54. gCheckPoints[ cpID ][ Yy ] = cpY;
  55. gCheckPoints[ cpID ][ Zz ] = cpZ;
  56. gCheckPoints[ cpID ][ Size ] = cpS;
  57. gCheckPoints[ cpID ][ active ] = true;
  58. gCheckPoints[ cpID ][ viewdis ] = viewdiss;
  59. if(playerid == -1)
  60. {
  61. gCheckPoints[ cpID ][ global ] = true;
  62. for(new i; i < MAX_PLAYERS; i ++)
  63. {
  64. pShown[ i ][ cpID ] = true;
  65. }
  66. }
  67. else if(playerid != -1)
  68. {
  69. pShown[ playerid ][ cpID ] = true;
  70. gCheckPoints[ cpID ][ global ] = false;
  71. for(new i; i < MAX_PLAYERS; i ++)
  72. {
  73. if(i != playerid)
  74. {
  75. pShown[ i ][ cpID ] = false;
  76. }
  77. }
  78. }
  79. return cpID;
  80. }
  81.  
  82. stock TogglePlayerCheckpoint(playerid, Cpid, bool:toggle)
  83. {
  84. pShown[ playerid ][ Cpid ] = toggle;
  85. return 1;
  86. }
  87.  
  88. stock DestroyCheckpoint(cPid)
  89. {
  90. gCheckPoints[ cPid ][ cpid ] = INVALID_CP_VALUE;
  91. gCheckPoints[ cPid ][ Xx ] = INVALID_CP_VALUEF;
  92. gCheckPoints[ cPid ][ Yy ] = INVALID_CP_VALUEF;
  93. gCheckPoints[ cPid ][ Zz ] = INVALID_CP_VALUEF;
  94. gCheckPoints[ cPid ][ Size ] = INVALID_CP_VALUEF;
  95. gCheckPoints[ cPid ][ active ] = false;
  96. gCheckPoints[ cPid ][ viewdis ] = INVALID_CP_VALUEF;
  97. return 1;
  98. }
  99.  
  100. stock StartSystem()
  101. {
  102. SetTimer("CPUpdate", CP_TIMER_INTERVAL, 1);
  103. return 1;
  104. }
  105.  
  106. forward CPUpdate();
  107. public CPUpdate()
  108. {
  109. new Float:pPos[3];
  110. for(new i; i < MAX_PLAYERS; i ++)
  111. {
  112. if(IsPlayerConnected(i))
  113. {
  114. GetPlayerPos(i, pPos[ 0 ], pPos[ 1 ], pPos[ 2 ]);
  115. for(new j; j < MAX_STREAMED_CPS; j ++)
  116. {
  117. if(gCheckPoints[ j ][ active ])
  118. {
  119. if(pShown[ i ][ j ] && DistanceBetweenPoints(pPos[ 0 ], pPos[ 1 ], pPos[ 2 ], gCheckPoints[ j ][ Xx ], gCheckPoints[ j ][ Yy ], gCheckPoints[ j ][ Zz ]) <= gCheckPoints[ j ][ viewdis ])
  120. {
  121. if(!pCPActive[ i ][ j ])
  122. {
  123. SetPlayerCheckpoint(i, gCheckPoints[ j ][ Xx ], gCheckPoints[ j ][ Yy ], gCheckPoints[ j ][ Zz ], gCheckPoints[ j ][ Size ]);
  124. pCPActive[ i ][ j ] = true;
  125. pCPID[ i ] = j;
  126. }
  127. }
  128. else
  129. {
  130. if(pCPActive[ i ][ j ])
  131. {
  132. DisablePlayerCheckpoint(i);
  133. pCPActive[ i ][ j ] = false;
  134. pCPID[ i ] = INVALID_CP_VALUE;
  135. }
  136. }
  137. }
  138. }
  139. }
  140. }
  141. }
Add Comment
Please, Sign In to add comment