Fixed BOLO plates less than 8 characters

This commit is contained in:
Dan
2020-02-24 21:10:09 +00:00
parent b0dfb93a2a
commit a3a1d93b3b

View File

@@ -649,8 +649,29 @@ elements.setBoloBtn.click( function() {
// Grab the value of the text input box // Grab the value of the text input box
let plate = elements.boloText.val().toUpperCase(); let plate = elements.boloText.val().toUpperCase();
// Gets the amount of whitespace there should be
let spaceAmount = 8 - plate.length;
if ( spaceAmount > 0 )
{
// Splits the amount in half
let split = spaceAmount / 2;
// Calculates how many whitespace characters there should be at the start and end of the string. As GTA
// formats a licence plate string by padding it, with the end of the string being biased compared to
// the start of the string.
let startSpace = Math.floor( split );
let endSpace = Math.ceil( split );
// Add the padding to the string
let text = plate.padStart( plate.length + startSpace );
text = text.padEnd( text.length + endSpace );
// Send the plate to the Lua side // Send the plate to the Lua side
sendData( "setBoloPlate", text );
} else {
sendData( "setBoloPlate", plate ); sendData( "setBoloPlate", plate );
}
} ) } )
// Checks what the user is typing into the plate box // Checks what the user is typing into the plate box