I created this rolling system by using a more specific branch of Lua known as GLua which pertains to the game this is run in, known as Garry's Mod. It is a plugin that can be added on to an existing playable gamemode known as Nutscript. As such, my rolling system makes use of a pre-existing framework of commands provided by GLua and Nutscript. I required knowledge of basic math operations and operators such as modulus, fundamental code concepts such as if/else statements as well as knowledge of Lua's code language in specific.
By using a series of local variables that get the attribute stats from a pre-existing character creation menu included with Nutscript, a modifier can be determined such as +1 or -1 that will be added onto whatever initial number is rolled by the player. This is done using several "if", "elseif" and "else" statements that get the attributes and determine its numerical value. With Dungeons and Dragons, a modifier of any kind is assigned to two numbers with one being odd and the other being even, such as a +1 modifier for 12 and 13. The modifier is found by subtracting ten from the original attribute score, dividing the total by 2 and then rounding down.
In order for the odd numbers to round down and still register the same modifier as the even number, we need to truncate the odd number so it removes the decimal after we divide. If the modifier is a negative value, we subtract 1 from the quotient when the attribute score is under 10 and is an odd number. This is done to make sure that our score of 9 AKA
(9 - 10) / 2 = 0.5, which truncates to 0, is then subtracted by 1 at the very end to retain the same score as that of the even number which would be 8 in this case.