Guest User

FS:Plate v3 final by Marricio for SAMP forums

a guest
Jul 30th, 2013
1,324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.18 KB | None | 0 0
  1. /*
  2. FS:Plate v3
  3. Made by Marricio / Mecaurio.
  4.  
  5. NOTE:
  6. When you change the plate the Z angle is modified that means it will work as 'flip' command too.
  7. */
  8.  
  9. #include a_samp
  10. #include zcmd
  11.  
  12. #define DIALOG_PLATE 1000
  13.  
  14. new vehiclePlate[MAX_VEHICLES][128];
  15. new szString[128];
  16.  
  17. stock StripText(text[])
  18. {
  19. for(new i=0; i<strlen(text); i++)
  20. {
  21. if(text[i] == '(' && text[i+7] == ')')
  22. {
  23. text[i] = '{';
  24. text[i+7] = '}';
  25. }
  26. }
  27. return 1;
  28. }
  29.  
  30. stock strreplace(_string[], const search[], const replacement[], bool:ignorecase = false, pos = 0, limit = -1, maxlength = sizeof (_string) ) {
  31. // No need to do anything if the limit is 0.
  32. if (limit == 0)
  33. return 0;
  34.  
  35. new
  36. sublen = strlen(search),
  37. replen = strlen(replacement),
  38. bool:packed = ispacked(_string),
  39. maxlen = maxlength,
  40. len = strlen(_string),
  41. count = 0
  42. ;
  43.  
  44.  
  45. // "maxlen" holds the max _string length (not to be confused with "maxlength", which holds the max. array size).
  46. // Since packed _strings hold 4 characters per array slot, we multiply "maxlen" by 4.
  47. if (packed)
  48. maxlen *= 4;
  49.  
  50. // If the length of the sub_string is 0, we have nothing to look for..
  51. if (!sublen)
  52. return 0;
  53.  
  54. // In this line we both assign the return value from "strfind" to "pos" then check if it's -1.
  55. while (-1 != (pos = strfind(_string, search, ignorecase, pos))) {
  56. // Delete the _string we found
  57. strdel(_string, pos, pos + sublen);
  58.  
  59. len -= sublen;
  60.  
  61. // If there's anything to put as replacement, insert it. Make sure there's enough room first.
  62. if (replen && len + replen < maxlen) {
  63. strins(_string, replacement, pos, maxlength);
  64.  
  65. pos += replen;
  66. len += replen;
  67. }
  68.  
  69. // Is there a limit of number of replacements, if so, did we break it?
  70. if (limit != -1 && ++count >= limit)
  71. break;
  72. }
  73.  
  74. return count;
  75. }
  76.  
  77. CMD:plate( playerid, params[] )
  78. {
  79. if( !IsPlayerInAnyVehicle( playerid ) ) return SendClientMessage( playerid, -1, "{c0c0c0}Error:{ffffff} You need to be in a vehicle." );
  80.  
  81. new dialogstring[600];
  82.  
  83. strcat( dialogstring, "{ffffff}Write in the text to be in the vehicle's plate\n\n{248eff}FORMAT TAGS:\n_______________________________________________________________________________\n\n" );
  84. strcat( dialogstring, "{ffffff}(white) white text\n{F21D1D}(red) red text\n{1D5DF2}(blue) blue text\n{F2EB1D}(yellow) yellow text\n{DD1DF2}(purple) purple text\n{68C24F}(green) green text\n" );
  85. strcat( dialogstring, "{ffffff}Or if you want to use hexadecimal numbers use the following format: (FFFFFF).\n\n{ff0000}Don't make the text too long!." );
  86.  
  87. ShowPlayerDialog( playerid, DIALOG_PLATE, DIALOG_STYLE_INPUT, "{ffffff}Write in the text to be displayed in the plate", dialogstring, "Set", "Cancel" );
  88. return 1;
  89. }
  90.  
  91. CMD:resetplate( playerid, params[] )
  92. {
  93. if( isnull( params ) ) return SendClientMessage( playerid, -1, "{c0c0c0}Syntax:{ffffff} /resetplate [vehicleid]" );
  94. if( !IsPlayerAdmin( playerid ) ) return SendClientMessage( playerid, -1, "{c0c0c0}Error:{ffffff} You're not an administrator." );
  95.  
  96. new Float:vehicle_pos[4], vehicleid = strval( params );
  97. format( vehiclePlate[vehicleid], 128, "default" );
  98. SetVehicleNumberPlate( vehicleid, "default" );
  99.  
  100. GetVehiclePos( vehicleid, vehicle_pos[0], vehicle_pos[1], vehicle_pos[2] );
  101. GetVehicleZAngle( vehicleid, vehicle_pos[3] );
  102. SetVehicleToRespawn( vehicleid );
  103. SetVehiclePos( vehicleid, vehicle_pos[0], vehicle_pos[1], vehicle_pos[2] );
  104. SetVehicleZAngle( vehicleid, vehicle_pos[3] );
  105. return 1;
  106. }
  107.  
  108. CMD:getplate( playerid, params[] )
  109. {
  110. if( isnull( params ) ) return SendClientMessage( playerid, -1, "{c0c0c0}Syntax:{ffffff} /getplate [vehicleid]" );
  111.  
  112. format( szString, 128, "[VEHICLE ID: %d | PLATE: %s]", strval( params ), vehiclePlate[strval( params )] );
  113. SendClientMessage( playerid, -1, szString );
  114.  
  115. return 1;
  116. }
  117.  
  118. public OnDialogResponse( playerid, dialogid, response, listitem, inputtext[] )
  119. {
  120. if( dialogid == DIALOG_PLATE )
  121. {
  122. if( !response ) return 1;
  123.  
  124. new newplate[128];
  125. format( newplate, 128, inputtext );
  126.  
  127. if( isnull( newplate ) )
  128. {
  129. new dialogstring[600];
  130. strcat( dialogstring, "{ffffff}Write in the text to be in the vehicle's plate\n\n{248eff}FORMAT TAGS:\n_______________________________________________________________________________\n\n" );
  131. strcat( dialogstring, "{ffffff}(white) white text\n{F21D1D}(red) red text\n{1D5DF2}(blue) blue text\n{F2EB1D}(yellow) yellow text\n{DD1DF2}(purple) purple text\n{68C24F}(green) green text\n" );
  132. strcat( dialogstring, "{ffffff}Or if you want to use hexadecimal numbers use the following format: (FFFFFF).\n\n{ff0000}Don't make the text too long! (excluding color formats)." );
  133.  
  134. ShowPlayerDialog( playerid, DIALOG_PLATE, DIALOG_STYLE_INPUT, "{ffffff}Write in the text to be displayed in the plate", dialogstring, "Set", "Cancel" );
  135. return 1;
  136. }
  137.  
  138. strreplace( newplate, "(white)", "{FFFFFF}", true );
  139. strreplace( newplate, "(red)", "{F21D1D}", true );
  140. strreplace( newplate, "(blue)", "{1D5DF2}", true );
  141. strreplace( newplate, "(yellow)", "{F2EB1D}", true );
  142. strreplace( newplate, "(purple)", "{DD1DF2}", true );
  143. strreplace( newplate, "(green)", "{68C24F}", true );
  144. StripText( newplate ); // This is to detect and fix hexadecimal numbers.
  145.  
  146. new playervehicle, Float:vehicle_pos[4];
  147. playervehicle = GetPlayerVehicleID( playerid );
  148.  
  149. format( vehiclePlate[playervehicle], 128, "%s", newplate );
  150. SetVehicleNumberPlate( playervehicle, newplate );
  151.  
  152. GetPlayerPos( playerid, vehicle_pos[0], vehicle_pos[1], vehicle_pos[2] );
  153. GetVehicleZAngle( playervehicle, vehicle_pos[3] );
  154. SetVehicleToRespawn( playervehicle );
  155. SetVehiclePos( playervehicle, vehicle_pos[0], vehicle_pos[1], vehicle_pos[2] );
  156. SetVehicleZAngle( playervehicle, vehicle_pos[3] );
  157. PutPlayerInVehicle( playerid, playervehicle, 0 );
  158.  
  159. format( szString, 128, "Your vehicle plate has succesfully changed to %s.", newplate );
  160. SendClientMessage( playerid, -1, szString );
  161. }
  162. return 1;
  163. }
Advertisement
Add Comment
Please, Sign In to add comment