Advertisement
Bebras

[INC]Coloured checkpoints v0.1 - Bebras

Aug 29th, 2014
1,277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.76 KB | None | 0 0
  1.  
  2.  
  3. /*
  4.  
  5.         Spalvotų checkpoint kūrimo include/Coloured checkpoint include
  6.         Autorius/Author "Bebras" 2014 ©
  7.         v0.1
  8.  
  9.         Thanks to Vince from forum.sa-mp.com for the idea!
  10.                                
  11. */
  12.  
  13.  
  14.  
  15.  
  16. /*
  17.  
  18.         native CreateColouredCheckpoint(Float:x,Float:y,Float:z,color);
  19.         native DestroyColouredCheckpoint(cpid);
  20.         native IsPlayerInAnyColouredCheckpoint(playerid);
  21.         native IsPlayerInColouredCheckpoint(playerid,cpid);
  22.         native ChangeColouredCheckpointColour(cpid,newcolor);
  23. */
  24.  
  25.  
  26.  
  27.  
  28.  
  29. #define CHECKPOINT_COLOUR_BLACK         1
  30. #define CHECKPOINT_COLOUR_BLUE          2
  31. #define CHECKPOINT_COLOUR_GREEN         3
  32. #define CHECKPOINT_COLOUR_GREY          4
  33. #define CHECKPOINT_COLOUR_ORANGE        5
  34. #define CHECKPOINT_COLOUR_WHITE         6
  35. #define CHECKPOINT_COLOUR_YELLOW        7
  36.  
  37. #define CHECKPOINT_COLOR_BLACK          CHECKPOINT_COLOUR_BLACK
  38. #define CHECKPOINT_COLOR_BLUE           CHECKPOINT_COLOUR_BLUE
  39. #define CHECKPOINT_COLOR_GREEN          CHECKPOINT_COLOUR_GREEN
  40. #define CHECKPOINT_COLOR_GREY           CHECKPOINT_COLOUR_GREY
  41. #define CHECKPOINT_COLOR_ORANGE         CHECKPOINT_COLOUR_ORANGE
  42. #define CHECKPOINT_COLOR_WHITE          CHECKPOINT_COLOUR_WHITE
  43. #define CHECKPOINT_COLOR_YELLOW         CHECKPOINT_COLOUR_YELLOW
  44.  
  45. #define COLOURED_CHECKPOINT_DIAMETER    1.0
  46. #define COLOURED_CHECKPOINT_HEIGHT      2.0
  47.  
  48. #define MAX_COLOURED_CHECKPOINTS                40
  49.  
  50.  
  51. forward OnPlayerExitColouredCheckpoint(playerid,cpid);
  52. forward OnPlayerEnterColouredCheckpoint(playerid,cpid);
  53.  
  54. enum E_COLOURED_CHECKPOINTS {
  55.     ObjectId,
  56.     #if defined _inc_streamer
  57.         AreaId
  58.     #else
  59.         Float:PosX,
  60.         Float:PosY,
  61.         Float:PosZ
  62.     #endif
  63. };
  64.  
  65.  
  66. static CCPData[MAX_COLOURED_CHECKPOINTS][E_COLOURED_CHECKPOINTS];
  67.  
  68. #if !defined _inc_streamer
  69.     static bool:IsPlayerInCCP[MAX_PLAYERS][MAX_COLOURED_CHECKPOINTS];
  70. #endif
  71.  
  72.  
  73. stock CreateColouredCheckpoint(Float:x,Float:y,Float:z,color)
  74. {
  75.     for(new i = 0; i < sizeof(CCPData); i++)
  76.     {
  77.         if(IsValidObject(CCPData[i][ObjectId])) continue;
  78.  
  79.  
  80.         CCPData[i][ObjectId] = CreateObject(1317, x, y, z, 0.0, 0.0, 0.0);
  81.         SetObjectMaterial(CCPData[i][ObjectId], 0, 18646, "matcolours", CCP_GetColourName(color), CCP_GetColourARGB(color));
  82.  
  83.         #if !defined _inc_streamer
  84.             CCPData[i][PosX] = x;
  85.             CCPData[i][PosY] = y;
  86.             CCPData[i][PosZ] = z;
  87.         #else
  88.             CCPData[i][AreaId] = CreateDynamicCylinder(x,y,z,z + COLOURED_CHECKPOINT_HEIGHT, COLOURED_CHECKPOINT_DIAMETER);
  89.         #endif
  90.  
  91.         return i;
  92.     }
  93.     return -1;
  94. }
  95. stock DestroyColouredCheckpoint(cpid)
  96. {
  97.     if(-1 < cpid < MAX_COLOURED_CHECKPOINTS)
  98.     {
  99.         #if defined _inc_streamer
  100.             DestroyDynamicArea(CCPData[cpid][AreaId]);
  101.         #endif
  102.         return DestroyObject(CCPData[cpid][ObjectId]);
  103.     }
  104.     return 0;
  105. }
  106.  
  107. stock IsPlayerInAnyColouredCheckpoint(playerid)
  108. {
  109.     #if defined _inc_streamer
  110.         for(new i = 0; i < sizeof(CCPData); i++)
  111.         {
  112.             if(!IsValidObject(CCPData[i][ObjectId])) continue;
  113.             if(IsPlayerInDynamicArea(playerid, CCPData[i][AreaId]))
  114.                 return true;
  115.         }
  116.         return false;
  117.     #else
  118.         for(new i = 0; i < sizeof(IsPlayerInCCP[]); i++)
  119.         {
  120.             if(IsPlayerInCCP[playerid][i])
  121.                 return true;
  122.         }
  123.         return false;
  124.  
  125.     #endif
  126. }
  127. stock IsPlayerInColouredCheckpoint(playerid,cpid)
  128. {
  129.     if(-1 > cpid > MAX_COLOURED_CHECKPOINTS) return false;
  130.     #if defined _inc_streamer
  131.         if(!IsValidObject(CCPData[cpid][ObjectId])) return false;
  132.         return IsPlayerInDynamicArea(playerid, CCPData[cpid][AreaId]);
  133.     #else
  134.         return IsPlayerInCCP[playerid][cpid];
  135.     #endif
  136. }
  137.  
  138. stock ChangeColouredCheckpointColour(cpid,newcolor)
  139. {
  140.     if(-1 > cpid > MAX_COLOURED_CHECKPOINTS) return 0;
  141.     SetObjectMaterial(CCPData[cpid][ObjectId], 0, 18646, "matcolours", CCP_GetColourName(newcolor), CCP_GetColourARGB(newcolor));
  142.     return 1;
  143. }  
  144.  
  145. //////////////////////////////////////////////////////////////////////////////////////////////////
  146. ////////////                        Internal STUFF                                    ////////////
  147. //////////////////////////////////////////////////////////////////////////////////////////////////
  148.  
  149. #if defined _inc_streamer
  150.    
  151.     public OnPlayerEnterDynamicArea(playerid, areaid)
  152.     {
  153.         for(new i = 0; i < sizeof(CCPData); i++)
  154.         {
  155.             if(!IsValidObject(CCPData[i][ObjectId])) continue;
  156.             if(CCPData[i][AreaId] != areaid) continue;
  157.            
  158.             #if defined OnPlayerEnterColouredCheckpoint
  159.                 OnPlayerEnterColouredCheckpoint(playerid,i);
  160.             #endif
  161.         }
  162.         #if defined CCP_OnPlayerEnterDynamicArea
  163.             return CCP_OnPlayerEnterDynamicArea(playerid,areaid);
  164.         #endif
  165.     }
  166.     #if defined _ALS_OnPlayerEnterDynamicArea
  167.         #undef OnPlayerEnterDynamicArea
  168.     #else
  169.         #define _ALS_OnPlayerEnterDynamicArea
  170.     #endif
  171.     #define OnPlayerEnterDynamicArea CCP_OnPlayerEnterDynamicArea
  172.     #if defined CCP_OnPlayerEnterDynamicArea
  173.         forward CCP_OnPlayerEnterDynamicArea(playerid,areaid);
  174.     #endif
  175.  
  176.     public OnPlayerLeaveDynamicArea(playerid, areaid)
  177.     {
  178.         for(new i = 0; i < sizeof(CCPData); i++)
  179.         {
  180.             if(!IsValidObject(CCPData[i][ObjectId])) continue;
  181.             if(CCPData[i][AreaId] != areaid) continue;
  182.  
  183.             #if defined OnPlayerExitColouredCheckpoint
  184.                 OnPlayerExitColouredCheckpoint(playerid,i);
  185.             #endif
  186.         }
  187.         #if defined CCP_OnPlayerLeaveDynamicArea
  188.             return CCP_OnPlayerLeaveDynamicArea(playerid,areaid);
  189.         #endif
  190.     }
  191.     #if defined CCP_OnPlayerLeaveDynamicArea
  192.         #undef OnPlayerLeaveDynamicArea
  193.     #else
  194.         #define _ALS_OnPlayerLeaveDynamicArea
  195.     #endif
  196.     #define OnPlayerLeaveDynamicArea CCP_OnPlayerLeaveDynamicArea
  197.     #if defined CCP_OnPlayerLeaveDynamicArea
  198.         forward CCP_OnPlayerLeaveDynamicArea(playerid,areaid);
  199.     #endif
  200.  
  201. #else
  202.  
  203.     // If streamer isn't used, we need our own timer :(
  204.     // Also we need to monitor all player locations
  205.  
  206.     public OnGameModeInit()
  207.     {
  208.         SetTimer("CCP_CheckForEntries", 50, true);
  209.         #if defined CCP_OnGameModeInit
  210.             CCP_OnGameModeInit();
  211.         #endif
  212.     }
  213.  
  214.     #if defined _ALS_OnGameModeInit
  215.         #undef OnGameModeInit
  216.     #else
  217.         #define _ALS_OnGameModeInit
  218.     #endif
  219.     #define OnGameModeInit CCP_OnGameModeInit
  220.     #if defined CCP_OnGameModeInit
  221.         forward CCP_OnGameModeInit();
  222.     #endif
  223.  
  224.     forward CCP_CheckForEntries();
  225.     public CCP_CheckForEntries()
  226.     {
  227.         for(new j = 0; j < MAX_PLAYERS; j++)
  228.         {
  229.             if(!IsPlayerConnected(j)) continue;
  230.  
  231.             for(new i = 0; i < sizeof(CCPData); i++)
  232.             {
  233.                 if(!IsValidObject(CCPData[i][ObjectId])) continue;
  234.  
  235.                 // If the player is in range
  236.                 new Float:x,Float:y,Float:z;
  237.                 GetPlayerPos(j, x, y, z);
  238.                 if(floatabs(CCPData[i][PosX] - x) < COLOURED_CHECKPOINT_DIAMETER / 2 &&
  239.                     floatabs(CCPData[i][PosY] - y) < COLOURED_CHECKPOINT_DIAMETER / 2 &&
  240.                     floatabs(CCPData[i][PosZ] - z) < COLOURED_CHECKPOINT_HEIGHT)
  241.                 {
  242.                     // If he wasn't in checkpoint at previous check
  243.                     if(!IsPlayerInCCP[j][i])
  244.                     {
  245.                         IsPlayerInCCP[j][i] = true;
  246.                         #if defined OnPlayerEnterColouredCheckpoint
  247.                             OnPlayerEnterColouredCheckpoint(j,i);
  248.                         #endif
  249.                     }
  250.                 }
  251.                 // IF hes not in range but he WAS in checkpoint at previous check.
  252.                 else if(IsPlayerInCCP[j][i])
  253.                 {
  254.                     IsPlayerInCCP[j][i] = false;
  255.                     #if defined OnPlayerExitColouredCheckpoint
  256.                         OnPlayerExitColouredCheckpoint(j,i);
  257.                     #endif
  258.                 }
  259.             }
  260.         }
  261.     }
  262.  
  263. #endif
  264.  
  265.  
  266.  
  267.  
  268. CCP_GetColourName(color)
  269. {
  270.     new s[7];
  271.     switch(color)
  272.     {
  273.         case CHECKPOINT_COLOUR_BLACK:       s = "black";
  274.         case CHECKPOINT_COLOUR_BLUE:        s = "blue";
  275.         case CHECKPOINT_COLOUR_GREEN:       s = "green";
  276.         case CHECKPOINT_COLOUR_GREY:        s = "grey";
  277.         case CHECKPOINT_COLOUR_ORANGE:      s = "orange";
  278.         case CHECKPOINT_COLOUR_WHITE:       s = "white";
  279.         case CHECKPOINT_COLOUR_YELLOW:      s = "yellow";
  280.     }
  281.     return s;
  282. }
  283. CCP_GetColourARGB(color)
  284. {
  285.     switch(color)
  286.     {
  287.         case CHECKPOINT_COLOUR_BLACK:       return 0xAA000000;
  288.         case CHECKPOINT_COLOUR_BLUE:        return 0xAA0000FF;
  289.         case CHECKPOINT_COLOUR_GREEN:       return 0xAA00FF00;
  290.         case CHECKPOINT_COLOUR_GREY:        return 0xAAC0C0C0;
  291.         case CHECKPOINT_COLOUR_ORANGE:      return 0xAAFF8000;
  292.         case CHECKPOINT_COLOUR_WHITE:       return 0xAAFFFFFF;
  293.         case CHECKPOINT_COLOUR_YELLOW:      return 0xAAFFFF00;
  294.     }
  295.     return 0;
  296. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement