Page 1 of 1

A car with random or sequential color

Posted: 12 Jan 2011, 17:44
by petr0
Hi, I added a respawning trailer to Tiny Town and I want it to have different color every respawn. How can i acomplish that?

I tried this way:

Code: Select all

...
COUNTER col = 6
...
LEVELSTART
...
SET col = ( col + 1 )
tr = CREATE_CAR ( 61.45 , 196.5  ) col 180 TRUKCONT END  //here is an error, if there is a number instead of "col" it compiles well
...
...but compiler throws an error.
How can I give a car random or sequential color?

Re: A car with random or sequential color

Posted: 12 Jan 2011, 18:04
by Sektor
You can't do it that way since the limited compiler requires a constant integer and won't allow a variable/counter.

You'd have to have one create_car command for every color you want to select from.

Re: A car with random or sequential color

Posted: 12 Jan 2011, 18:14
by petr0
Too bad... I'll make the location of respawn sequential also then!
Thanks.

Re: A car with random or sequential color

Posted: 12 Jan 2011, 18:19
by Sektor
Coordinates and many other values also need to be constants.

Re: A car with random or sequential color

Posted: 12 Jan 2011, 18:27
by petr0
Yes, but it's not a problem since I must write multiple create_car lines anyway.

Re: A car with random or sequential color

Posted: 12 Jan 2011, 18:44
by petr0
BTW, can I set a counter to random value somehow?

Re: A car with random or sequential color

Posted: 12 Jan 2011, 18:59
by elypter
There is no Random function in GTA2 but you can do a workarround (a modulo operation)

Code: Select all

	SET temp = ( rand / 33 )
	SET temp = ( temp * 33 )
	SET surp_sel= ( rand - temp )
33 is the maximum random value

rand is a counter that is increased every WHILE_EXEC cycle and reset on pseudo random events.
It is important that it is a value that is different in every game and that the seed(rand) happens more often than event(surp_sel) otherwise you could get a repeating pattern.
If you use the same seed for multiple events ensure that the max values do not have a common divisor otherwise you will have correlations.

You can look how it works on BC Awkward Cargo