RSX / RCX & REX Files {Scripting}

@Mitch

Really nice job !!

@camsinny

+1 for your idea !

@skybh

Sure you can already split/decompose your variables...they call it "swizzling", so you can extract any values from your matrices.
Here's an example :

Code:
int $arrayA[2] = int[2]{0,1}
int $arrayB[2] = $arrayA[1][0]
// result: $arrayB[0] equals 1 and $arrayB[1] equals 0
// The order has changed compared to $arrayA !
 
You can also use xyzw, rgba or m00m01m02m03m10m11..m33 etc to address array members, if you use a dot ( . ).
A couple of examples:
 
int $arrayA[2] = int[2]{0,1}
int $arrayB[2] = $arrayA.yx
// result: $arrayB[0] equals 1 and $arrayB[1] equals 0
// The order has changed compared to $arrayA !
// Note the dot
 
Or
 
int $arrayA[3] = int[3]{0,1,2}
int $arrayB[2] = ( $arrayA+ int[3]{0,10,20} ).zy
// result: $arrayB[0] equals 22 and $arrayB[1] equals 11
 
Or
 
int $cowSays[3] = int[3]{0,1,2}
int $arrayB[2] = $cowSays.m00
// result: $arrayB[0] equals 0 and $arrayB[1] equals 0
 
Or
 
int $arrayA[4] = int[4]{0,1,2,3}
int $arrayB[3] = $cowSays.yyw
// $arrayB[0] equals 1
// $arrayB[1] equals 1
// $arrayB[2] equals 3

You can now use the system parameters to set your car variables...
Talking about those, was wondering where to find the fuel consumption variable in system.htm file (in dara/dump folder).
 
Does anyone know if we can apply forces to the car via any other means yet?

Ie, just apply say 500N along the car centreline in line with another car.ini variable? Wanting to try create a jet dragster or something, but avoid having to use bodged pacejka to make it work.

So for example just have the engine free with inertia/braking coefficient, and have rpm * constant = thrust basically...


Hmmm

Dave
 
Hmmm, just thinking.

I could use a wing with a negative drag variable that adjusts with speed (so it remains constant force), then tweak the angle with engine rpm to trim it in and out... hmmmm...

Hmmmm

Dave
 
I will take a new fresh look at scripts shortly, since i have been discussing things with Ruud.
Meanwhile, you can give some feature requests concerning scripts, so I can add some new things while im at it.

I just noticed your post. :rolleyes:
It would be really nice to have access to manipulating the car and track cameras.

Experimenting with the particles would be fun too, I mainly need some way of controlling the emitters alpha. I know that it's been possible to position a emitter on a track for other effects (I made a volcano) for a while now, but I would like to make a script that varied the tire-smoke's alpha according to tire heat as well as another for exhaust that would vary the velocity and vector according to ground speed and RPM.
Speaking of particles do they support some sort of primitive collision? I would be nice for sparks to bounce on the ground like they do
in other programs.

Alex Forbin
 
Did you check the related shader ?
Normally, there's an alpha param which you can tweak.

Some pics of your volcano would be great & your particles...I had some similar ideas back in the days with CE2, for sure it isn't the same with Racer.
 
Did you check the related shader ?
Normally, there's an alpha param which you can tweak.

Some pics of your volcano would be great & your particles...I had some similar ideas back in the days with CE2, for sure it isn't the same with Racer.

What I want to do is change the alpha according to other parameters that the shaders alone can't pick-up.
Here is a picture of the volcano, it's a bit more Kilauea than Krakatoa ;) . The lava goes up at varying speeds and heights while the smoke blows with the wind.

Well, the forums image upload seems to be fubar now, we can only upload files with .svm .ntsk .sto and other such
super useful extensions. :rolleyes:

Alex Forbin
 
REFRESH!!!

I've got question. Is it possible to write script for Air Ride? I know, that it's possible to move generic models , but is it possible to use main body model in script?

pradzio1
 
I'm pretty sure suspension variables can be tweaked with scripts, or at least are intended to be, so it should be possible to simulate that kind of thing.
 
Speaking of scripting and shaders. How would you start out with a nice new tire and end after several dozen laps with a melty, gummy looking tire? Progressing from say, chalk marks or price stickers to the chords showing through.
 
It would be nice if we can't tweak clucth by script (i mean having a set clutch function) better for automatic scripts :p
Also about the throttle, it seems that script affect only throttle and not the throttle at vavle :( .
i've tried the one by stereo and when i reach the limit my throttle is 0, but throttle at valve still ok ^^
Now i've done (with help of cosmo°) and average speed script, for curious guys :p . I also wanted to do a cruise control, but with the problem with throttle :(
Also i'm working on a improved version of automatic script (now it's check if you're braking, so if you're braking the downshifts are done before) . And it's work now per gear to get a smoother drive :)
 
Sorry for double post
I've tried this :
Code:
func float move(rcarmodel $targetObject, float $state, float $position_x, float $position_y, float $position_z, float $speed, float $max_x, float $max_y, 
 
float $max_z)
{
float $position_x_n = $state*($max_x-$position_x) + $position_x
float $position_y_n = $state*($max_y-$position_y) + $position_y
float $position_z_n = $state*($max_z-$position_z) + $position_z
if $position_x_n < $max_x
{
$position_x_n = $position_x_n + $speed
}
if $position_x_n > $max_x
{
$position_x_n = $position_x_n - $speed
}
if $position_y_n < $max_y
{
$position_y_n = $position_y_n + $speed
}
if $position_y_n > $max_y
{
$position_y_n = $position_y_n + $speed
}
if $position_z_n < $max_z
{
$position_z_n = $position_z_n + $speed
}
if $position_z_n > $max_z
{
$position_z_n = $position_z_n - $speed
}
set $targetObject position float[3]{$position_x_n,$position_y_n,$position_z_n}
}
So, something like stereo's script for rotate objects, but when i use this fonction i've this :
Key not pressed : Object at normal position (given as parameter)
Key pressed : Object at moved position, so i can't see the transition
Maybe someone (stereo? :D ) Have an idea?
Also i've tried to do some ESP, but it seems that set (rcar) brake doesn't realy affect braking..
 
I think the transition speed would depend on what values you pass in for $state and $speed, so the other part of the code.

If $state is just switching from 0 to 1 when the key is pressed, then
Code:
float $position_x_n = $state*($max_x-$position_x) + $position_x
This changes from $position_x to $max_x instantly, and updates the position to max_x.

The rotation script uses $angle, which is returned at the end of the func, to control the object's position. So it's the only variable actually changing per tick - $targetAngle changes when you press/release the key, and instantly switches from closed to open state. But $angle is updated a little at a time, and used for the actual display.
 
I think the transition speed would depend on what values you pass in for $state and $speed, so the other part of the code.

If $state is just switching from 0 to 1 when the key is pressed, then
Code:
float $position_x_n = $state*($max_x-$position_x) + $position_x
This changes from $position_x to $max_x instantly, and updates the position to max_x.

The rotation script uses $angle, which is returned at the end of the func, to control the object's position. So it's the only variable actually changing per tick - $targetAngle changes when you press/release the key, and instantly switches from closed to open state. But $angle is updated a little at a time, and used for the actual display.

Thanks, you are right ^^
So yet the $state is determined by a loop, i've this :
Code:
float $state = 1
while 1
{
  if $car == $localcar
  {
    if is key 88 pressed
    {
$keydown = 1
    }
    if $keydown == 1
    {
    $state = $state - 0.001
if $state < 0
{
$state = 0
}
if $state == 0
{
$keydown = 0
}
    }
    else
    {
    $keydown = 0   
    }
  }
Now i've no idea how to do the invert move when i reach the max position and press key 88 again :S
Currently it's ignoring ABS, so it'll always do a skid stop. I'm not sure if there's a way to have script controlled brakes include the ABS built in.
Code:
rcar $car = get local car
shared int $testactive
while 1
{
  if $testactive == 1
  {
    set $car throttle 0
    set $car brake 1
  }
  interrupt
}
As I said before you'll need to 'reload scripts' on the console to get this one running.
To avoid this you can try to add :
Code:
rcar $car = get local car
shared int $testactive
int $abs = 0
while 1
{
$abs = get $car abs active
  if $testactive == 1 and $abs < 1
  {
    set $car throttle 0
    set $car brake 1
  }
  interrupt
}
It should be ok ;)
 
Now i've no idea how to do the invert move when i reach the max position and press key 88 again :S
Hmm, I took care of that part with 2 variables.
One is to keep track of the state of the key - so that it only runs once per 'switch' (push down).
The other keeps track of the target state - open or closed. This one is a 'toggle' function.
Code:
$toggle = -1
if $keypress {
  if $keystate == 0 {
    set $keystate 1
    set $toggle = - $toggle
  }
}
else {
  set $keystate 0
}
Having '$toggle = - $toggle' means that if $toggle is 1, it becomes -1 - if it's -1, it becomes 1.


Then the other code becomes - if $toggle = 1, then increase state, if $toggle = -1, then decrease state, and if state is less than 0, set to 0, if it's greater than 1 set to 1.

If you're running this on the 'paint' interval (which you should) it's also a good idea to use the keyword 'interval' multiplied by the state change - that way it opens at the same speed independent of framerate, since interval is the number of milliseconds the previous frame took to render.
Code:
$state = $state + $interval*$toggle*0.001
Conveniently, toggle is positive for open, negative for close, so you don't need an if statement - just multiply by toggle to get opening/closing.
 
Hmm, I took care of that part with 2 variables.
One is to keep track of the state of the key - so that it only runs once per 'switch' (push down).
The other keeps track of the target state - open or closed. This one is a 'toggle' function.
Code:
$toggle = -1
if $keypress {
  if $keystate == 0 {
    set $keystate 1
    set $toggle = - $toggle
  }
}
else {
  set $keystate 0
}
Having '$toggle = - $toggle' means that if $toggle is 1, it becomes -1 - if it's -1, it becomes 1.


Then the other code becomes - if $toggle = 1, then increase state, if $toggle = -1, then decrease state, and if state is less than 0, set to 0, if it's greater than 1 set to 1.

If you're running this on the 'paint' interval (which you should) it's also a good idea to use the keyword 'interval' multiplied by the state change - that way it opens at the same speed independent of framerate, since interval is the number of milliseconds the previous frame took to render.
Code:
$state = $state + $interval*$toggle*0.001
Conveniently, toggle is positive for open, negative for close, so you don't need an if statement - just multiply by toggle to get opening/closing.

Thanks , now it works and i know what is "interval"
here is my code
Code:
   if $car == $localcar
   { 
    if is key 88 pressed
    {
if $keydown == 0
{
$toggle = - $toggle
$keydown = 1
}
    }
    if $keydown == 1
    {
$state = $state + 0.002*$toggle // speed of animation
if $state < 0
{
$state = 0
$keydown = 0
$mode = $mode + 1
}
if $state > 1
{
$state = 1
$keydown = 0
$mode = $mode - 1
}
    }
    else
    {
     $keydown = 0    
    }
  }
Btw , a mini poll ! :p
Wich mode do you prefer this : (translation)
Or this (rotation) :

In reality, the roof have two position, the 1st one wich is only the rotation, then the second (wich have 2 positons) is the translation.
I'm trying to do both but it's seems to be hard.. And keep the translation only looks odd because the translation is not very accurate.. what i need is when the mode 2 is selected, it does a small rotation of the window and translate it, it would be proper.. but it's a long way, i'm trying with a variable $mode but i don't know if it's realy possible
 
roofgraph.png


I find it helpful to draw out a diagram of the states you want it to move between. So for example if it goes from closed (1) to rotated open (2) and then to slid back (3), and the reverse doing the same thing, then you'd want either one key cycling through the modes (1 2 3 2 1) or two keys that do more-open and less-open, going 1 state per time.

Then comes the second part of the diagram: You have the state variable, so depending on the current value, you can calculate the correct rotation/translation. Eg. if the current state is 2.5 (increasing by 0.01 each frame) then it would be moving but rotation wouldn't be varying.

Turning a piecewise function like this into code is something like
Code:
if state < 2 {
  rotation = state - 1
  translation = 0
}
else {
  rotation = 1
  translation = state - 2
}
If you plug in the 3 state values (1, 2, 3) you'll find that this returns a (rotation, translation) pair of (0,0), (1,0), and (1,1) which corresponds back to the right angle bend on the original diagram.


This is a fairly simple example, but you can work it out for the parts of moving wings and stuff, and it makes it a lot easier to know what your goal is, and make sure the code matches it.
 
I find it helpful to draw out a diagram of the states you want it to move between. So for example if it goes from closed (1) to rotated open (2) and then to slid back (3), and the reverse doing the same thing, then you'd want either one key cycling through the modes (1 2 3 2 1) or two keys that do more-open and less-open, going 1 state per time.

Then comes the second part of the diagram: You have the state variable, so depending on the current value, you can calculate the correct rotation/translation. Eg. if the current state is 2.5 (increasing by 0.01 each frame) then it would be moving but rotation wouldn't be varying.

Turning a piecewise function like this into code is something like
Code:
if state < 2 {
  rotation = state - 1
  translation = 0
}
else {
  rotation = 1
  translation = state - 2
}
If you plug in the 3 state values (1, 2, 3) you'll find that this returns a (rotation, translation) pair of (0,0), (1,0), and (1,1) which corresponds back to the right angle bend on the original diagram.


This is a fairly simple example, but you can work it out for the parts of moving wings and stuff, and it makes it a lot easier to know what your goal is, and make sure the code matches it.

Thanks for the help friend ! :)
So to get my roof working, i've just changed one thing on the rotate fonction, it don't place the object yet :)
I've worked with a $mode2 variable :)
Here is my code :
Code:
while 1
{
   if $car == $localcar
   { 
    if is key 88 pressed
    {
if $keydown2 == 0
{
$toggle2 = - $toggle2
$keydown2 = 1
}
    }
    if is key 87 pressed and $state == 0 //only when an action is finished
    {
if $mode2 < 3
{
$mode2 + = 1
$state = 1 //reset to start position
wait(250)
}
else
{
$mode2 = 0
$state = 1
wait(250)
}
    }
    if $keydown2 == 1
    {
$state = $state + $speed*$toggle2
if $state < 0
{
$state = 0
$keydown2 = 0
}
if $state > 1
{
$state = 1
$keydown2 = 0
}
    }
    else
    {
     $keydown2 = 0    
    }
    if $mode2 == 0
    {
$toit_rot = move($toit, $state, 0.0, 1.185, 0.12, 0.001, 0.0, 1.185, 0.12)
$toit_rot_2 = move($toit_2, $state, 0.0, -991.185, 0.12, 0.001, 0.0, -991.185, 0.12)
$state = 0
    }
    if $mode2 == 1
{
$state = $state + $speed*$toggle2
if $state < 0
{
$state = 0
$keydown2 = 0
}
if $state > 1
{
$state = 1
$keydown2 = 0
}
$toit_rot = rotate($toit, $state, $toit_rot, 0.0, 1.185, 0.12, 0.0, 1.0, 0.0, 0.00003, 0.00003, 0.00, 0.04)
$toit_rot_2 = 0
$toit_move = 0
$toit_move_2 = 0
}
    if $mode2 == 2
{
$state = $state + $speed*$toggle2
if $state < 0
{
$state = 0
$keydown2 = 0
}
if $state > 1
{
$state = 1
$keydown2 = 0
}
if $state > 0.90
{
$mode2 + = 1
$state = 1
$state = $state + $speed*$toggle2
}
$toit_rot = rotate($toit, $state, $toit_rot, 0.0, 1.185, 0.12, 0.0, 1.0, 0.0, 0.00015, 0.00015, 0.00, 0.04)
$toit_rot_2 = 0
$toit_move = 0
$toit_move_2 = 0
}
    if $mode2 == 3
{
$state = $state + $speed*$toggle2
if $state < 0
{
$state = 0
$keydown2 = 0
}
if $state > 1
{
$state = 1
$keydown2 = 0
}
if $state > 0.98
{
$toit_move_2 = move($toit_2, $state, 0.0, 1.183, -0.68, 0.001, 0.0, 1.18, -0.68)
$toit_rot = 0
$toit_rot_2 = 0
$toit_move = 0
}
else
{
$toit_rot = move($toit, $state, 0.0, -991.185, 0.12, 0.001, 0.0, -991.185, 0.12)
$toit_rot_2 = rotate($toit_2, $state, $toit_rot_2, 0.0, 1.27, -0.68, 0.0, 1.0, 0.0, 0.00011, 0.00011, -0.13, 0.00)
$toit_move = move($toit_2, $state, 0.0, 1.17, -1.45, 0.001, 0.0, 1.19, -0.68)
$toit_move_2 =0
}
}
  }

You can see how it work here :
I just have to make the roof a bit higher during transition. Also it's in physics folder :)
I want to thanks Stereo, cosmo° and jeeP for their help :D
 
So I was just thinking, naturally no idea if this is possible since I haven't dived much into scripts. But anyways, is it possible to script in a trailer on a vehicle? I'm sure it would be quite the script you would need though. Also would it be possible to script in more gears?
 
Theoretically I think maybe I could do a trailer. I'd have to see how some of the scriptfuncs actually work though.

Very interesting problem :p

Do you happen to have any trailer models or am I gonna have to start pulling around Lamborghinis? I'm thinking export the trailer as a car, with no driven wheels on the ground.

EDIT:
First foray into it - finding a bit of a problem. The following
Code:
set (pbody) pos (float[3])
Is fine, works on cars. I can move them around all I want.

This, on the other hand
Code:
add (pbody) bodyforce (float[3]) at (float[3])
Comment:
Adds bodyforce of physics-body at body position
Doesn't seem to have any effects. Unless the units are some small thing, and 10,000 is not enough to visibly affect the vehicle.

My intention was to add forces located at the trailer hitch, pulling the two cars together, but that can't work as is.

I'll try some alternatives tomorrow. A wing with the appropriate downforce/drag would work, but is a pretty huge kludge to attempt.
 

Latest News

Online or Offline racing?

  • 100% online racing

    Votes: 92 7.7%
  • 75% online 25% offline

    Votes: 125 10.5%
  • 50% online 50% offline

    Votes: 171 14.3%
  • 25% online 75% offline

    Votes: 335 28.1%
  • 100% offline racing

    Votes: 465 39.0%
  • Something else, explain in comment

    Votes: 4 0.3%
Back
Top