(2020-11-26, 02:27 AM)Kwarde Wrote: When printing a single character (which is just a number), use %c (which stands for character, obviously). %s is for strings (arrays).
Also be more specific. "It doesn't work". What doesn't work? Does it print weird characters? (Which is likely since you used specificer s instead of c). Or does it not work at all? If so, there is another problem going on.
Quote:random('0'-'9')
https://open.mp/docs/scripting/functions/random
random() takes as parameter "max", not a "range". For example, if the input is 15 it will return a random value from 0 up to 14. Negative values (0-9 = -9) will print large values.
When wrapping something in single quotes (eg. 'a', '9') it will return the numeric value of that character. For example, '5' is 5, but 'a' has numeric value 97. So when using:
Code:'A' random('Z' - 'A' 1)
You're actually doing:
Code:65 random(90 - 65 1) //65 random(26): Output will be 65 (0-25), so output will be atleast 65 ('A') and maximal 65(90) ('Z')
Note that these character numbers are ASCII numbers (if I'm not wrong): http://www.asciitable.com/ (I believe SAMP covers 128 of them?)
Quote:Computers can only understand numbers, so an ASCII code is the numerical representation of a character such as 'a' or '@' or an action of some sort
I apologize. I do not speak English and there may have been an error in the translation.
The problem that is happening is that it is printing strange characters in the letters and numbers.
Thank you all very much for your attention. Reach this way with support on the discord.
Credit: Dobby#7939 (Discord)
Code:
#define RandomEx(%0,%1) (random(%1 - %0 1) %0)
format(numberplate, sizeof(numberplate), "%c%c%c%c %c%c%c", RandomEx('A','Z'), RandomEx('A','Z'), RandomEx('1','9'), RandomEx('1','9'), RandomEx('1','9'), RandomEx('A','Z'), RandomEx('A','Z'));