Author Topic: Modifying vehicleData fields on a key press in-game  (Read 3950 times)

I would like to add flaps to an airplane.  Flaps are surfaces on the trailing edge of airplane wings that hinge down to increase drag and decrease the stall speed.  I saw that there are the fields "drag", "lift", and "stallSpeed" in the WheeledVehicleData of Strato's A10 (and other vehicles.  I used the A10 for research because it has a similar flaps system).  To do this, I would like to modify the "drag", "stallspeed", and possibly "lift" values by pressing and holding the light key (or triggering it via interactive vehicles).

The A10 has pseudo-flaps that are used to slow the vehicle down, for landings or more accurate shooting.  The system used in the A10 script scales the vehicle speed, slowing the vehicle down (as far as I can tell).  This is a similar effect that I would like to have occur, but not quite what I want.  The function that contains the flaps is referenced below.

Code: [Select]
function A10Vehicle::onTrigger(%this,%obj,%trigNum,%val)
{

//echo(%trigNum SPC %val);

if(%val)
{
%obj.setVelocity(vectorScale(%obj.getVelocity(),0.99));
%obj.playthread(1,flapopen);
%obj.brake=true;
}
else
{
%obj.unmountimage(0);
%obj.playthread(1,flapclose);
%obj.brake=false;
}

}

In the past and in my recent research, I have read threads discussing the issue I am having, but I could never get a concise answer.  From what I have read, it would require work-arounds or buggy scripting, thus rendering it impossible.

Is this true, or is there some way?  Is the system that the A10 uses the most logical system?  One reference (second listed below) I found discussed toggling two datablocks to change the type of vehicle it is, which could be implemented to suit my needs, if logical.  Any suggestions for other ways to do this would be much appreciated.



References:
http://forum.blockland.us/index.php?topic=239593.0 (topic discussing a similar issue)
http://forum.blockland.us/index.php?topic=149521.0 (possible work-around)
http://www-rohan.sdsu.edu/~stewart/GPGT/Appendix%20A%20-%20Quick%20References.pdf (torquescript reference)

Yes, either creating a new datablock on a per-plane basis, or toggling between two would work. Neither will be free of issues, though, although the latter is a better solution.

Basically, swap out your current code with %obj.getObjectMount().setDatablock("datablock"); to swap datablocks (pulling that from my head, but I think that's right).

Yes, either creating a new datablock on a per-plane basis, or toggling between two would work. Neither will be free of issues, though, although the latter is a better solution.

Basically, swap out your current code with %obj.getObjectMount().setDatablock("datablock"); to swap datablocks (pulling that from my head, but I think that's right).

ok, thanks, I'll work off of that.

It would be much, much better to just reduce the velocity of the vehicle using setVelocity. Changing datablocks while people are riding frequently is bound to have some side effects which would make it annoying if not unusable (resetting rotation, deleting/unmounting players), but I don't know, it might work fine. Give it a try, but I recommend avoiding it.

The biggest problem with add-ons that work by changing datablocks arise when multiple add-ons that change the same objects datablock collide

%obj.getObjectMount().setDatablock("datablock");
Because his current code is a vehicle method, he already has the vehicle object
So just %obj.setDatablock("thing");
If he wants it to activate on pressing the light key, he would need to do %client.player.getObjectMount().setDatablock("thing"); (provided your get of getObjectMount is correct)

Alright, thanks for the input.  I'll try the method of changing datablocks first, then airspeed scaling, then a tweak of the second method I thought of that could replicate increased lift that relies on scaling vertical speed (if at all possible).  Is there a comparable value/variable (clarify for me, I don't know the terminology) to obj.getVelocity() for vertical speed?  I kinda though a couple of strato's helicopters have vertical speed indicators on the HUD.

Is there a comparable value/variable (clarify for me, I don't know the terminology) to obj.getVelocity() for vertical speed?  I kinda though a couple of strato's helicopters have vertical speed indicators on the HUD.

As getVelocity returns a vector, you can just get the z component of it. getWord(%obj.getVelocity(), 2)

As getVelocity returns a vector, you can just get the z component of it. getWord(%obj.getVelocity(), 2)

Sweet, then I guess I don't need to mess with datablocks.