From a3a1d93b3b715dc1ded75cf819464dc9d3444152 Mon Sep 17 00:00:00 2001 From: Dan Date: Mon, 24 Feb 2020 21:10:09 +0000 Subject: [PATCH] Fixed BOLO plates less than 8 characters --- nui/radar.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/nui/radar.js b/nui/radar.js index 073021f..1ee09ca 100644 --- a/nui/radar.js +++ b/nui/radar.js @@ -649,8 +649,29 @@ elements.setBoloBtn.click( function() { // Grab the value of the text input box let plate = elements.boloText.val().toUpperCase(); - // Send the plate to the Lua side - sendData( "setBoloPlate", plate ); + // 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 + sendData( "setBoloPlate", text ); + } else { + sendData( "setBoloPlate", plate ); + } } ) // Checks what the user is typing into the plate box