Advertisement
iPLEOMAX

returnf.inc

Mar 6th, 2012
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.04 KB | None | 0 0
  1. /*
  2.  This Source Code Form is subject to the terms of the Mozilla Public
  3.  License, v. 2.0. If a copy of the MPL was not distributed with this file,
  4.  You can obtain one at http://mozilla.org/MPL/2.0/
  5.  
  6.  Script Author: iPLEOMAX, 2012
  7.  Release: 2, Minor Fixes
  8. */
  9.  
  10. #if defined _ret_included
  11.     #endinput
  12. #endif
  13.  
  14. #define _ret_included
  15.  
  16. #include <a_samp>
  17.  
  18. #if !defined MAX_RESULT_SIZE
  19.     #define MAX_RESULT_SIZE   (128)
  20. #endif
  21.  
  22. #if !defined MAX_TEMPSTR_SIZE
  23.     #define MAX_TEMPSTR_SIZE  (1024)
  24. #endif
  25.  
  26. #define ClearString(%0) \
  27.     for(new index = 0; index < sizeof %0; index++) %0[index] = '\0'
  28.  
  29. #define RET:%0(%1) forward retf_%0(%1); public retf_%0(%1)
  30. #define RETF(%0,%1) return format(Parse_Result, sizeof(Parse_Result), %0, %1)
  31.  
  32. /*
  33. native returnf(string[], playerid = INVALID_PLAYER_ID);
  34. native RETF(const format[], {Float,_}:...);
  35. */
  36.  
  37. new
  38.     Parse_Result [MAX_RESULT_SIZE],
  39.     Return_Temp  [MAX_TEMPSTR_SIZE]
  40. ;
  41.  
  42. stock returnf( iString[], playerid = INVALID_PLAYER_ID )
  43. {
  44.     if(strfind(iString, "#", false) == -1) return false;
  45.  
  46.     ClearString(Return_Temp);
  47.    
  48.     new iStart, bool:iCap;
  49.  
  50.     for ( new iPos = 0, iLen = strlen(iString); iPos < iLen; iPos++ )
  51.     {
  52.         if ( !iCap && iString[iPos] == '#' )
  53.         {
  54.             iStart = iPos;
  55.             iCap = true;
  56.         }
  57.         else if ( iCap && iString[iPos] == '#' )
  58.         {
  59.             iCap = false;
  60.  
  61.             new Function[64];
  62.             strmid(Function, iString, iStart + 1, iPos);
  63.             strins(Function, "retf_", 0);
  64.            
  65.             if(playerid != INVALID_PLAYER_ID) CallLocalFunction(Function, "d", playerid);
  66.             else CallLocalFunction(Function, "");
  67.            
  68.             strcat(Return_Temp, Parse_Result);
  69.             ClearString(Parse_Result);
  70.         }
  71.         else if (iCap) {}
  72.         else InsertToTempString( iString[iPos] );
  73.     }
  74.    
  75.     format(iString, strlen(Return_Temp) + 1, "%s", Return_Temp);
  76.     return true;
  77. }
  78.  
  79. stock InsertToTempString( character )
  80. {
  81.     for(new iPos; iPos < sizeof Return_Temp; iPos++)
  82.     {
  83.         if(Return_Temp[iPos] == '\0')
  84.         {
  85.             Return_Temp[iPos] = character;
  86.             break;
  87.         }
  88.     }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement