A car with random or sequential color

Anything to do with GTA1/GTA2 modding (tools, scripts and more).
Post Reply
petr0
Mugger
Mugger
Posts: 11
Joined: 12 Jan 2011, 14:28
GH nick: petr0

A car with random or sequential color

Post 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?
User avatar
Sektor
Boss
Boss
Posts: 1424
Joined: 04 Mar 2008, 06:51
GH nick: Sektor
Location: GTAMP.com
Contact:

Re: A car with random or sequential color

Post 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.
petr0
Mugger
Mugger
Posts: 11
Joined: 12 Jan 2011, 14:28
GH nick: petr0

Re: A car with random or sequential color

Post by petr0 »

Too bad... I'll make the location of respawn sequential also then!
Thanks.
User avatar
Sektor
Boss
Boss
Posts: 1424
Joined: 04 Mar 2008, 06:51
GH nick: Sektor
Location: GTAMP.com
Contact:

Re: A car with random or sequential color

Post by Sektor »

Coordinates and many other values also need to be constants.
petr0
Mugger
Mugger
Posts: 11
Joined: 12 Jan 2011, 14:28
GH nick: petr0

Re: A car with random or sequential color

Post by petr0 »

Yes, but it's not a problem since I must write multiple create_car lines anyway.
petr0
Mugger
Mugger
Posts: 11
Joined: 12 Jan 2011, 14:28
GH nick: petr0

Re: A car with random or sequential color

Post by petr0 »

BTW, can I set a counter to random value somehow?
User avatar
elypter
Immortal
Posts: 1120
Joined: 26 Dec 2009, 23:53
GH nick: elypter

Re: A car with random or sequential color

Post 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
yur sa'nok ngeyä
Post Reply