Advertisement
Guest User

Fake Checkpoints Include by NaS

a guest
Jan 6th, 2014
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 10.53 KB | None | 0 0
  1. /*
  2. Fake CP include by NaS (c)2013-2014
  3.  
  4. Version: 1.0 (First Release)
  5.  
  6. This include file let's you create a different kind of Checkpoint.
  7. It consists of 3DText Labels and can be made any size, height and color.
  8.  
  9. Re-realease, change and use as you like, but please leave this credit here.
  10.  
  11. Any bug found? Please PM me (NaS) on forum.sa-mp.com or post it in the FakeCP thread. Thank you!
  12.  
  13.  
  14. Main Functions:
  15.  
  16. - CreateFakeCP(Text[], Float:X, Float:Y, Float:Z, Float:R = 1.0, Float:RowSpace = 0.5, Float:DrawDistance = 30.0, Color = 0xFF000099, worldid = -1, interiorid = -1, playerid = -1, Float:streamdistance = 50.0)
  17.  
  18.     Description:
  19.         Creates a checkpoint
  20.         R = Radius of the CP
  21.         RowSpace = Space between each outter row of the CP
  22.        
  23.     Returns:
  24.         ID of the created checkpoint
  25.         -1 if no checkpoint could be created
  26.        
  27. - DestroyFakeCP(fakecpid)
  28.  
  29.     Description:
  30.         Destroys a checkpoint
  31.        
  32.     Returns:
  33.         1 if destroying was successful
  34.         -1 if the given ID was invalid
  35.        
  36. - IsPlayerInFakeCP(playerid, fakecpid)
  37.  
  38.     Description:
  39.         Checks, if a player is in a specific checkpoint
  40.        
  41.     Returns:
  42.         true if he is
  43.         false if not
  44.    
  45. - GetPlayerFakeCP(playerid)
  46.  
  47.     Description:
  48.         Gets a player's checkpoint
  49.        
  50.     Returns:
  51.         Checkpoint ID
  52.         -1 if the player is in no checkpoint
  53.        
  54. - SetFakeCPText(fakecpid, text[])
  55.  
  56.     Description:
  57.         Sets a checkpoints title text
  58.        
  59.     Returns:
  60.         true on success
  61.         false on failure (invalid ID)
  62.  
  63. - SetFakeCPColor(fakecpid, color)
  64.  
  65.     Description:
  66.         Sets a checkpoints color
  67.  
  68.     Returns:
  69.         true on success
  70.         false on failure (invalid ID)
  71.  
  72.  
  73. Callbacks:
  74.  
  75. - OnPlayerEnterFakeCP(playerid, fakecpid)
  76.  
  77.     Description:
  78.         Gets called, if a player enters a checkpoint
  79.  
  80. - OnPlayerLeaveFakeCP(playerid, fakecpid)
  81.  
  82.     Description:
  83.         Gets called, if a player leaves a checkpoint
  84.  
  85.  
  86. NOTE:
  87.  
  88. You can change the limit of checkpoints by defining "MAX_FAKECPS" before including this file like this:
  89.  
  90. #define MAX_FAKECPS 25
  91.  
  92. You can also change the text of the labels surrounding the checkpoint by defining "FCP_CP_TEXT" like this:
  93.  
  94. #define FCP_CP_TEXT "xXx"
  95.  
  96. Also note that you have to include Incognito's Streamer BEFORE you include this include.
  97.  
  98. Have fun!
  99.  
  100.  
  101. native CreateFakeCP(Text[], Float:X, Float:Y, Float:Z, Float:R = 1.0, Float:RowSpace = 0.5, Float:DrawDistance = 30.0, Color = 0xFF000099, worldid = -1, interiorid = -1, playerid = -1, Float:streamdistance = 50.0);
  102. native DestroyFakeCP(fakecpid);
  103. native IsPlayerInFakeCP(playerid, fakecpid);
  104. native GetPlayerFakeCP(playerid);
  105. native SetFakeCPText(fakecpid, text[]);
  106. native SetFakeCPColor(fakecpid, color);
  107. */
  108.  
  109. #if !defined __FAKECPS_INCLUDED__
  110.  
  111. #if !defined MAX_FAKECPS
  112. #define MAX_FAKECPS             20
  113. #endif
  114.  
  115. #if !defined FCP_CP_TEXT
  116. #define FCP_CP_TEXT             ""
  117. #endif
  118.  
  119. // ---------------------------------------------------------------------------- Vars, Arrays, Enums etc.
  120.  
  121. enum fcp_E_FAKECPINFO
  122. {
  123.     bool:fcpUsed,
  124.     Float:fcpX,
  125.     Float:fcpY,
  126.     Float:fcpZ,
  127.     Float:fcpR,
  128.     Float:fcpDrawDistance,
  129.     Float:fcpRowSpace,
  130.     fcpColor,
  131.     fcpText[128],
  132.    
  133.     fcpAreaID,
  134.     Text3D:fcpCPLabels[40],
  135.     Text3D:fcpHeadLabel
  136. };
  137. new fcp_FakeCPs[MAX_FAKECPS][fcp_E_FAKECPINFO];
  138.  
  139. new fcp_LastFakeCP[MAX_PLAYERS];
  140.  
  141. // ---------------------------------------------------------------------------- Forwards
  142.  
  143. forward OnPlayerEnterFakeCP(playerid, fakecpid);
  144. forward OnPlayerLeaveFakeCP(playerid, fakecpid);
  145.  
  146. // ---------------------------------------------------------------------------- Callback Hooks
  147.  
  148. public OnGameModeInit()
  149. {
  150.     for(new i = 0; i < MAX_FAKECPS; i ++) fcp_FakeCPs[i][fcpUsed] = false;
  151.    
  152.     // ----------------
  153.    
  154.     #if defined FCP_OnGameModeInit
  155.             FCP_OnGameModeInit();
  156.     #endif
  157.     return 1;
  158. }
  159.  
  160. #if defined _ALS_OnGameModeInit
  161.         #undef OnGameModeInit
  162. #else
  163.         #define _ALS_OnGameModeInit
  164. #endif
  165. #define OnGameModeInit FCP_OnGameModeInit
  166. #if defined FCP_OnGameModeInit
  167.         forward FCP_OnGameModeInit();
  168. #endif
  169.  
  170. public OnFilterScriptInit()
  171. {
  172.     for(new i = 0; i < MAX_FAKECPS; i ++) fcp_FakeCPs[i][fcpUsed] = false;
  173.  
  174.     // ----------------
  175.  
  176.     #if defined FCP_OnFilterScriptInit
  177.             FCP_OnFilterScriptInit();
  178.     #endif
  179.     return 1;
  180. }
  181.  
  182. #if defined _ALS_OnFilterScriptInit
  183.         #undef OnFilterScriptInit
  184. #else
  185.         #define _ALS_OnFilterScriptInit
  186. #endif
  187. #define OnFilterScriptInit FCP_OnFilterScriptInit
  188. #if defined FCP_OnFilterScriptInit
  189.         forward FCP_OnFilterScriptInit();
  190. #endif
  191.  
  192. public OnPlayerEnterDynamicArea(playerid, areaid)
  193. {
  194.     new Slot = Streamer_GetIntData(STREAMER_TYPE_AREA, areaid, E_STREAMER_EXTRA_ID); // This is the easiest way of matching an areaid with a checkpointid :)
  195.  
  196.     if(Slot < 0 || Slot >= MAX_FAKECPS) return 1;
  197.  
  198.     if(!fcp_FakeCPs[Slot][fcpUsed] || fcp_FakeCPs[Slot][fcpAreaID] != areaid) return 1;
  199.  
  200.     fcp_LastFakeCP[playerid] = Slot;
  201.  
  202.     CallRemoteFunction("OnPlayerEnterFakeCP", "dd", playerid, Slot);
  203.  
  204.     // ----------------
  205.  
  206.     #if defined FCP_OnPlayerEnterDynamicArea
  207.             FCP_OnPlayerEnterDynamicArea(playerid, areaid);
  208.     #endif
  209.     return 1;
  210. }
  211.  
  212. #if defined _ALS_OnPlayerEnterDynamicArea
  213.         #undef OnPlayerEnterDynamicArea
  214. #else
  215.         #define _ALS_OnPlayerEnterDynamicArea
  216. #endif
  217. #define OnPlayerEnterDynamicArea FCP_OnPlayerEnterDynamicArea
  218. #if defined FCP_OnPlayerEnterDynamicArea
  219.         forward FCP_OnPlayerEnterDynamicArea(playerid, areaid);
  220. #endif
  221.  
  222. public OnPlayerLeaveDynamicArea(playerid, areaid)
  223. {
  224.     new Slot = Streamer_GetIntData(STREAMER_TYPE_AREA, areaid, E_STREAMER_EXTRA_ID);
  225.  
  226.     if(Slot < 0 || Slot >= MAX_FAKECPS) return 1;
  227.  
  228.     if(!fcp_FakeCPs[Slot][fcpUsed] || fcp_FakeCPs[Slot][fcpAreaID] != areaid) return 1;
  229.  
  230.     fcp_LastFakeCP[playerid] = -1;
  231.  
  232.     CallRemoteFunction("OnPlayerLeaveFakeCP", "dd", playerid, Slot);
  233.  
  234.     // ----------------
  235.  
  236.     #if defined FCP_OnPlayerLeaveDynamicArea
  237.             FCP_OnPlayerLeaveDynamicArea(playerid, areaid);
  238.     #endif
  239.     return 1;
  240. }
  241.  
  242. #if defined _ALS_OnPlayerLeaveDynamicArea
  243.         #undef OnPlayerLeaveDynamicArea
  244. #else
  245.         #define _ALS_OnPlayerLeaveDynamicArea
  246. #endif
  247. #define OnPlayerLeaveDynamicArea FCP_OnPlayerLeaveDynamicArea
  248. #if defined FCP_OnPlayerLeaveDynamicArea
  249.         forward FCP_OnPlayerLeaveDynamicArea(playerid, areaid);
  250. #endif
  251.  
  252. // ---------------------------------------------------------------------------- Main Functions
  253.  
  254. stock CreateFakeCP(Text[], Float:X, Float:Y, Float:Z, Float:R = 1.0, Float:RowSpace = 0.5, Float:DrawDistance = 30.0, Color = 0xFF000099, worldid = -1, interiorid = -1, playerid = -1, Float:streamdistance = 50.0)
  255. {
  256.     new Slot = -1;
  257.     for(new i = 0; i < MAX_FAKECPS; i ++)
  258.     {
  259.         if(fcp_FakeCPs[i][fcpUsed]) continue;
  260.        
  261.         Slot = i;
  262.         break;
  263.     }
  264.    
  265.     if(Slot == -1) return -1; // RETURN: No free slot
  266.    
  267.     fcp_FakeCPs[Slot][fcpUsed] = true;
  268.    
  269.     if(strlen(Text) > 0) fcp_FakeCPs[Slot][fcpHeadLabel] = CreateDynamic3DTextLabel(Text, Color, X, Y, Z-1.0+(5*RowSpace), DrawDistance, INVALID_PLAYER_ID, INVALID_PLAYER_ID, 1, worldid, interiorid, playerid, streamdistance);
  270.     else fcp_FakeCPs[Slot][fcpHeadLabel] = CreateDynamic3DTextLabel(" ", Color, X, Y, Z-1.0+(5*RowSpace), DrawDistance, INVALID_PLAYER_ID, INVALID_PLAYER_ID, 1, worldid, interiorid, playerid, streamdistance);
  271.    
  272.     fcp_FakeCPs[Slot][fcpAreaID] = CreateDynamicSphere(X, Y, Z, R, worldid, interiorid, playerid);
  273.     Streamer_SetIntData(STREAMER_TYPE_AREA, fcp_FakeCPs[Slot][fcpAreaID], E_STREAMER_EXTRA_ID, Slot); // Set extraid to the checkpointit, so I can find it later again
  274.    
  275.     fcp_FakeCPs[Slot][fcpX] = X;
  276.     fcp_FakeCPs[Slot][fcpY] = Y;
  277.     fcp_FakeCPs[Slot][fcpZ] = Z;
  278.    
  279.     fcp_FakeCPs[Slot][fcpR] = R;
  280.    
  281.     fcp_FakeCPs[Slot][fcpDrawDistance] = DrawDistance;
  282.     fcp_FakeCPs[Slot][fcpRowSpace] = RowSpace;
  283.     fcp_FakeCPs[Slot][fcpColor] = Color;
  284.    
  285.     format(fcp_FakeCPs[Slot][fcpText], 128, Text);
  286.    
  287.     new count = 0;
  288.  
  289.     DrawDistance = R*5.0;
  290.     if(DrawDistance < 5.0) DrawDistance = 5.0;
  291.    
  292.     for(new Float:i = 0.0; i < 360.0; i = i + 45.0)
  293.     {
  294.         new Float:pX, Float:pY;
  295.        
  296.         pX = X + (R * floatsin(-i, degrees));
  297.         pY = Y + (R * floatcos(-i, degrees));
  298.        
  299.         for(new j = 0; j < 5; j++)
  300.         {
  301.             fcp_FakeCPs[Slot][fcpCPLabels][count] = CreateDynamic3DTextLabel(FCP_CP_TEXT, Color-0x00000001, pX, pY, Z-1.0+(j*RowSpace), DrawDistance, INVALID_PLAYER_ID, INVALID_PLAYER_ID, 1, worldid, interiorid, playerid, streamdistance);
  302.            
  303.             count ++;
  304.         }
  305.     }
  306.    
  307.     return Slot;
  308. }
  309.  
  310. stock DestroyFakeCP(fakecpid)
  311. {
  312.     if(fakecpid < 0 || fakecpid >= MAX_FAKECPS) return -1; // RETURN: Invalid ID (limit exceeded)
  313.    
  314.     if(!fcp_FakeCPs[fakecpid][fcpUsed]) return -1; // RETURN: Invalid ID (unused)
  315.    
  316.     fcp_FakeCPs[fakecpid][fcpUsed] = false;
  317.    
  318.     DestroyDynamic3DTextLabel(fcp_FakeCPs[fakecpid][fcpHeadLabel]);
  319.    
  320.     DestroyDynamicArea(fcp_FakeCPs[fakecpid][fcpAreaID]);
  321.    
  322.     for(new i = 0; i < 40; i ++) DestroyDynamic3DTextLabel(fcp_FakeCPs[fakecpid][fcpCPLabels][i]);
  323.    
  324.     return 1; // RETURN: SUCCESS
  325. }
  326.  
  327. stock IsPlayerInFakeCP(playerid, fakecpid)
  328. {
  329.     if(!IsPlayerConnected(playerid) || fakecpid < 0 || fakecpid >= MAX_FAKECPS) return false; // RETURN: Invalid IDs
  330.    
  331.     if(IsPlayerInDynamicArea(playerid, fcp_FakeCPs[fakecpid][fcpAreaID]) && fcp_FakeCPs[fakecpid][fcpUsed]) return true; // RETURN: Player is in CP
  332.    
  333.     return false; // RETURN: Player is in no CP
  334. }
  335.  
  336. stock GetPlayerFakeCP(playerid)
  337. {
  338.     if(!IsPlayerConnected(playerid)) return -1; // RETURN: Player not connected
  339.    
  340.     return fcp_LastFakeCP[playerid]; // RETURN: CheckpointID
  341. }
  342.  
  343. stock SetFakeCPText(fakecpid, text[])
  344. {
  345.     if(fakecpid < 0 || fakecpid >= MAX_FAKECPS) return false; // RETURN: Invalid ID (limit exceeded)
  346.    
  347.     if(!fcp_FakeCPs[fakecpid][fcpUsed]) return false; // RETURN: Invalid ID (unused)
  348.    
  349.     if(strlen(text) == 0) return false; // RETURN: Invalid Text (should not be 0 cells)
  350.    
  351.     UpdateDynamic3DTextLabelText(fcp_FakeCPs[fakecpid][fcpHeadLabel], fcp_FakeCPs[fakecpid][fcpColor], text);
  352.     format(fcp_FakeCPs[fakecpid][fcpText], 128, text);
  353.    
  354.     return true; // RETURN: SUCCESS
  355. }
  356.  
  357. stock SetFakeCPColor(fakecpid, color)
  358. {
  359.     if(fakecpid < 0 || fakecpid >= MAX_FAKECPS) return false; // RETURN: Invalid ID (limit exceeded)
  360.  
  361.     if(!fcp_FakeCPs[fakecpid][fcpUsed]) return false; // RETURN: Invalid ID (unused)
  362.  
  363.     UpdateDynamic3DTextLabelText(fcp_FakeCPs[fakecpid][fcpHeadLabel], color, fcp_FakeCPs[fakecpid][fcpText]);
  364.     for(new i = 0; i < MAX_FAKECPS; i ++) UpdateDynamic3DTextLabelText(fcp_FakeCPs[fakecpid][fcpCPLabels][i], color, FCP_CP_TEXT);
  365.     fcp_FakeCPs[fakecpid][fcpColor] = color;
  366.    
  367.     return true; // RETURN: SUCCESS
  368. }
  369.  
  370. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement