Random Plate bugs help
#1

pawn Код:
stock getRandomLetter() {
    return 65 + random(52); // ASCII Code of capital A is 65 + 2 * 26 for all other chars in alphabet.
}

stock GetFreeVehiclePlate()
{
    for(new v = 0; v < MAX_VEHICLES; v ++)
    {
        new VPlate[255];
        new randnumb = 1 + random(9);
        format(VPlate, 255, "%c%c%c - %d%d%d", getRandomLetter(), getRandomLetter(), getRandomLetter(), randnumb,randnumb,randnumb);
        if(strcmp(Vehicles[v][Plate], VPlate, true)) return v;
    }
    return -1;
}
Its supposed to do for example AAA - 111 or BAS - 234 just random the first 3 a-z and last 3 0-9.

but it made this: яFCliams

which isnt correct...
Can someone help me out
Reply
#2

Lower case letters don't follow the upper case letters directly in the ASCII code.
pawn Код:
const charset[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

new VPlate[8]; // don't waste resources
format(VPlate, sizeof(VPlate), "%c%c%c-%03d", charset[random(sizeof(charset))], charset[random(sizeof(charset))], charset[random(sizeof(charset))], (100 + random(900)));
Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
Lower case letters don't follow the upper case letters directly in the ASCII code.
pawn Код:
const charset[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";

new VPlate[8]; // don't waste resources
format(VPlate, sizeof(VPlate), "%c%c%c-%03d", charset[random(sizeof(charset))], charset[random(sizeof(charset))], charset[random(sizeof(charset))], (100 + random(900)));
C:\Users\Stefan Dorst\Desktop\Scratch RolePlay\gamemodes\RP.pwn(8662) : error 001: expected token: "=", but found "["
C:\Users\Stefan Dorst\Desktop\Scratch RolePlay\gamemodes\RP.pwn(8662) : error 029: invalid expression, assumed zero
C:\Users\Stefan Dorst\Desktop\Scratch RolePlay\gamemodes\RP.pwn(8662) : warning 215: expression has no effect
C:\Users\Stefan Dorst\Desktop\Scratch RolePlay\gamemodes\RP.pwn(8664) : error 028: invalid subscript (not an array or too many subscripts): "charset"
C:\Users\Stefan Dorst\Desktop\Scratch RolePlay\gamemodes\RP.pwn(8664) : error 039: constant symbol has no size
C:\Users\Stefan Dorst\Desktop\Scratch RolePlay\gamemodes\RP.pwn(8664) : error 029: invalid expression, assumed zero
C:\Users\Stefan Dorst\Desktop\Scratch RolePlay\gamemodes\RP.pwn(8664) : fatal error 107: too many error messages on one line

Compilation aborted.Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


6 Errors.
Reply
#4

Sorry, use new const instead of just const. I have that charset variable as a stock in one of my includes, that's why I didn't notice at first.
Reply
#5

pawn Код:
stock GetFreeVehiclePlate()
{
    for(new v = 0; v < MAX_VEHICLES; v ++)
    {
        new const charset[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        new VPlate[8]; // don't waste resources
        format(VPlate, sizeof(VPlate), "%c%c%c - %03d", charset[random(sizeof(charset))], charset[random(sizeof(charset))], charset[random(sizeof(charset))], (100 + random(900)));
        if(strcmp(Vehicles[v][Plate], VPlate, true)) return v;
    }
    return -1;
}
shows a stupid thing like яFCliams aganin..
Reply
#6

Ty this...
pawn Код:
stock GetFreeVehiclePlate()
{
    new VPlate[10];
    for(new v = 0; v < MAX_VEHICLES; v ++)
    {
        format(VPlate, sizeof(VPlate), "%c%c%c - %d", random(25)+65, random(25)+65, random(25)+65, (100 + random(900)));
        if(strcmp(Vehicles[v][Plate], VPlate, true)) return v;
    }
    return -1;
}
Reply
#7

Let me check
Reply
#8

Nope still doesn't work...
Reply
#9

Quote:
Originally Posted by Stefand
Посмотреть сообщение
Nope still doesn't work...
pawn Код:
format(VPlate, sizeof(VPlate), "%c%c%c - %d", random(25)+65, random(25)+65, random(25)+65, (100 + random(900)));
this code gives you a string of the type AAA -123

pawn Код:
if(strcmp(Vehicles[v][Plate], VPlate, true)) return v;
this code probably is the problematic code.

how are you calling the function?
Reply
#10

it is to check if the plate that is been created isn't already in use.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)