Random vehicle selling price
#1

I just setup a custom vehicle selling system, but since i listed all the vehicles, i wanna randomize the selling price too, so i did in this way:

(I'll not post all the vehicles list, just a small part so you can understand what im asking):

pawn Код:
new RandomVehiclePrice = random(35000-7500+1200+500+6000-1300+25000-12000);
new ListVehicles[212][VehiclesInfo] =
{
{"Landstalker",RandomVehiclePrice},
    {"Bravura",RandomVehiclePrice},
    {"Buffalo",RandomVehiclePrice},
    {"Linerunner",RandomVehiclePrice},
    {"Perrenial",RandomVehiclePrice},
    {"Sentinel",RandomVehiclePrice},
    {"Dumper",RandomVehiclePrice},
    {"Firetruck",RandomVehiclePrice},
    {"Trashmaster",RandomVehiclePrice},
    {"Stretch",RandomVehiclePrice},
    {"Manana",RandomVehiclePrice},
    {"Infernus",RandomVehiclePrice}
};
But when i compile it, pawno crashes. What's wrong?
Reply
#2

Wouldn't be easier to just use:
pawn Код:
new ListVehicles[212][VehiclesInfo] =
{
    {"Landstalker", RandomEx(500, 35000)},
    {"Bravura", RandomEx(600, 30000)},
    // rest..
};
pawn Код:
stock RandomEx(min, max)
{
    return random(max - min) + min;
}
Reply
#3

I have 212 vehicles listed, it will be a pain in the ass editing them all with a different random number. I was thinking to make all vehicles with "RandomEx(600, 30000)". It will print a different random number for every vehicle, right?

EDIT: Tried that code, crashes too.
Reply
#4

You can only initialize arrays with constants. Neither a variable, nor the return value of a function would be a valid initialer.
Reply
#5

So i suppose i can't add a random number in that array.
Reply
#6

You can, but u have to do it manually. Or you can just get a random number whenever you need the car price.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)