Advertisement
Guest User

LDTLuxurY

a guest
Jan 6th, 2010
653
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.48 KB | None | 0 0
  1. /*<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
  2. ^           Title: LuxurY Checkpoint Streamer (LCS)                            ^
  3. ^           Version: 1.1.1                                                     ^
  4. ^           Reliase: final                                                     ^
  5. ^           Date: 6 August 2008                                                ^
  6. ^           Developer: [LDT]LuxurY                                             ^
  7. <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>*/
  8.  
  9. #include <a_samp>
  10.  
  11. #define MAX_DYNCHECK 1024
  12. #define MAX_CHDIS 50.0 //uses to disable checkpoint if distanse is above 50
  13.  
  14. forward LCS_OnPlayerEnterCheckpoint( playerid , checkpointid );
  15. forward LCS_OnPlayerLeaveCheckpoint( playerid , checkpointid );
  16. forward LCS_ChCh( );
  17.  
  18. new
  19.     Float:dyncheckcoords[MAX_DYNCHECK][4],
  20.     LCScount,
  21.     playertmpch[MAX_PLAYERS],
  22.     tmpi[MAX_PLAYERS],
  23.     lockch[MAX_PLAYERS][2];
  24.  
  25. stock LCS_Load( )
  26. {
  27.     SetTimer( "LCS_ChCh" , 1000 , 1 );
  28.     for ( new i = 0; i < MAX_PLAYERS; i++ )
  29.     {
  30.         playertmpch[i] = -1;
  31.         lockch[i][1] = -1;
  32.     }
  33.     return 1;
  34. }
  35.  
  36. stock LCS_SetPlayerStaticCheck( playerid , checkpointid )
  37. {
  38.     if ( LCS_IsValidCheckpoint( checkpointid ) == 1 )
  39.     {
  40.         new
  41.             Float:tx,
  42.             Float:ty,
  43.             Float:tz,
  44.             Float:ts;
  45.            
  46.         LCS_GetCheckpointData( checkpointid , tx , ty , tz , ts );
  47.         SetPlayerCheckpoint( i , tx , ty , tz , ts );
  48.         lockch[playerid][0] = 1;
  49.         lockch[playerid][1] = checkpointid;
  50.     }
  51.     return 1;
  52. }
  53.  
  54. stock LCS_IsPlayerInCheckpoint( playerid , checkpointid )
  55. {
  56.     new
  57.         result,
  58.         ChiD = LCS_GetClosestCheckpoint( playerid );
  59.        
  60.     if ( ChiD == checkpointid && IsPlayerInCheckpoint( playerid ) == 1 )
  61.     {
  62.         result = 1;
  63.     }
  64.     if ( lockch[playerid][0] == 1 && lockch[playerid][1] == checkpointid && IsPlayerInCheckpoint( playerid ) == 1 )
  65.     {
  66.         result = 1;
  67.     }
  68.     return result;
  69. }
  70.  
  71. stock LCS_SetCheckpointData( checkpointid , Float:x , Float:y , Float:z , Float:size )
  72. {
  73.     if ( LCS_IsValidCheckpoint( checkpointid ) == 1 )
  74.     {
  75.         dyncheckcoords[checkpointid][0] = x;
  76.         dyncheckcoords[checkpointid][1] = y;
  77.         dyncheckcoords[checkpointid][2] = z;
  78.         dyncheckcoords[checkpointid][3] = size;
  79.         for ( new i = 0, i < MAX_PLAYERS; i++ )
  80.         {
  81.             if ( checkpointid == playertmpch[i] )
  82.             {
  83.                 DisablePlayerCheckpoint( i );
  84.                 new
  85.                     Float:tx,
  86.                     Float:ty,
  87.                     Float:tz,
  88.                     Float:ts;
  89.                 LCS_GetCheckpointData( checkpointid , tx , ty , tz , ts );
  90.                 SetPlayerCheckpoint( i , tx , ty , tz , ts );
  91.             }
  92.         }
  93.     }
  94.     return 1;
  95. }
  96.  
  97. stock LCS_GetPlayerCheckpointIn( playerid )
  98. {
  99.     new
  100.         result = -1,
  101.         ChiD = LCS_GetClosestCheckpoint( playerid );
  102.        
  103.     if ( IsPlayerInCheckpoint( playerid ) == 1 )
  104.     {
  105.         if ( lockch[playerid][0] == 1 )
  106.         {
  107.             result = lockch[playerid][1];
  108.         }
  109.         else
  110.         {
  111.             result = ChiD;
  112.         }
  113.     }
  114.     return result;
  115. }
  116.  
  117. stock LCS_IsPlayerInAnyCheckpoint( playerid )
  118. {
  119.     new
  120.         result;
  121.     if ( IsPlayerInCheckpoint( playerid ) == 1 && LCS_GetClosestCheckpoint( playerid ) != -1 )
  122.     {
  123.         result = 1;
  124.     }
  125.     return result;
  126. }
  127.  
  128. stock LCS_IsAnyPlayerInCheckpoint( checkpointid )
  129. {
  130.     new
  131.         result;
  132.     for ( new i = 0; i < MAX_PLAYERS; i++ )
  133.     {
  134.         if ( LCS_IsPlayerInCheckpoint( i , checkpointid ) == 1 )
  135.         {
  136.             result = 1;
  137.         }
  138.     }
  139.     return result;
  140. }
  141.  
  142. stock LCS_RemovePlayerStaticCheck( playerid )
  143. {
  144.     if ( lockch[playerid][0] == 1 )
  145.     {
  146.         DisablePlayerCheckpoint( playerid );
  147.         lockch[playerid][0] = 0;
  148.         lockch[playerid][1] = -1;
  149.     }
  150.     return 1;
  151. }
  152.  
  153. stock LCS_GetPlayerStaticCheck( playerid )
  154. {
  155.     return lockch[playerid][1];
  156. }
  157.  
  158. stock LCS_CreateCheckpoint( Float:x , Float:y , Float:z , Float:size )
  159. {
  160.     dyncheckcoords[LCScount][0] = x;
  161.     dyncheckcoords[LCScount][1] = y;
  162.     dyncheckcoords[LCScount][2] = z;
  163.     dyncheckcoords[LCScount][3] = size;
  164.     LCScount++;
  165.     LCScount %= MAX_DYNCHECK;
  166.     return LCScount-1;
  167. }
  168.  
  169. stock LCS_IsValidCheckpoint( checkpointid )
  170. {
  171.     new
  172.         result;
  173.     if ( dyncheckcoords[checkpointid][0] == 0 && dyncheckcoords[checkpointid][1] == 0 && dyncheckcoords[checkpointid][2] == 0 && dyncheckcoords[checkpointid][3] == 0 )
  174.     {
  175.         result = 0;
  176.     }
  177.     else
  178.     {
  179.         result = 1;
  180.     }
  181.     return result;
  182. }
  183.  
  184. stock LCS_DestroyCheckpoint( checkpointid )
  185. {
  186.     if ( LCS_IsValidCheckpoint( checkpointid ) == 1 )
  187.     {
  188.         dyncheckcoords[LCScount][0] = 0;
  189.         dyncheckcoords[LCScount][1] = 0;
  190.         dyncheckcoords[LCScount][2] = 0;
  191.         dyncheckcoords[LCScount][3] = 0;
  192.     }
  193.     return checkpointid;
  194. }
  195.  
  196. stock LCS_GetCheckpointData( checkpointid , &Float:x , &Float:y , &Float:z , &Float:size )
  197. {
  198.     x = dyncheckcoords[checkpointid][0];
  199.     y = dyncheckcoords[checkpointid][1];
  200.     z = dyncheckcoords[checkpointid][2];
  201.     size = dyncheckcoords[checkpointid][3];
  202. }
  203.  
  204. stock LCS_GetDistanceBetweenPAC( playerid , checkpointid )
  205. {
  206.     new
  207.         Float:dis,
  208.         Float:x1,
  209.         Float:y1,
  210.         Float:z1,
  211.         Float:x2,
  212.         Float:y2,
  213.         Float:z2,
  214.         Float:size;
  215.     GetPlayerPos( playerid , x1 , y1 , z1 );
  216.     LCS_GetCheckpointData( checkpointid , x2 , y2 , z2 , size );
  217.     dis = floatsqroot( floatpower( floatabs( floatsub( x2 , x1 ) ) , 2 ) + floatpower( floatabs( floatsub( y2 , y1 ) ) , 2 ) + floatpower( floatabs( floatsub( z2 , z1 ) ) , 2 ) );
  218.     return floatround( dis );
  219. }
  220.  
  221. stock LCS_GetClosestCheckpoint( playerid )
  222. {
  223.     new
  224.         check = -1,
  225.         Float:distmp = 99999.0,
  226.         Float:distmp2;
  227.     for( new i = 0; i < LCScount; i++ )
  228.     {
  229.         distmp2 = LCS_GetDistanceBetweenPAC( playerid , i );
  230.         if( distmp2 < distmp )
  231.         {
  232.             distmp = distmp2;
  233.             check = i;
  234.         }
  235.     }
  236.     return check;
  237. }
  238.  
  239. public LCS_ChCh( )
  240. {
  241.     for( new i = 0; i < MAX_PLAYERS; i++ )
  242.     {
  243.         if ( IsPlayerConnected( i ) == 1 )
  244.         {
  245.             if ( lockch[i][0] == 0 )
  246.             {
  247.                 tmpi[i] = LCS_GetClosestCheckpoint( i );
  248.                 if ( tmpi[i] != playertmpch[i] && tmpi[i] != -1 && LCS_IsValidCheckpoint( tmpi[i] ) == 1 )
  249.                 {
  250.                     playertmpch[i] = tmpi[i];
  251.                     DisablePlayerCheckpoint( i );
  252.                     new
  253.                         Float:tx,
  254.                         Float:ty,
  255.                         Float:tz,
  256.                         Float:ts;
  257.                     LCS_GetCheckpointData( tmpi[i] , tx , ty , tz , ts );
  258.                     SetPlayerCheckpoint( i , tx , ty , tz , ts );
  259.                 }
  260.                 new
  261.                     distmp = LCS_GetDistanceBetweenPAC( i , tmpi[i] );
  262.                 if ( distmp > MAX_CHDIS )
  263.                 {
  264.                     DisablePlayerCheckpoint( i );
  265.                     playertmpch[i] = -1;
  266.                 }
  267.             }
  268.         }
  269.     }
  270.     return 1;
  271. }
  272.  
  273. public OnPlayerEnterCheckpoint( playerid )
  274. {
  275.     new
  276.         ChiD = LCS_GetClosestCheckpoint( playerid );
  277.     LCS_OnPlayerEnterCheckpoint( playerid , ChiD );
  278.     return 1;
  279. }
  280.  
  281. public OnPlayerLeaveCheckpoint(playerid)
  282. {
  283.     new
  284.         ChiD = LCS_GetClosestCheckpoint( playerid );
  285.     LCS_OnPlayerLeaveCheckpoint( playerid , ChiD );
  286.     return 1;
  287. }
  288.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement