Author Topic: I need to decipher this  (Read 1233 times)

I'm working on a vehicle that uses two jets similiar to the minijet's. Below is the minijet code that I don't understand. I've successfully "duplicated" emitters for mountPoints 3 and 4, but I think I need to do something here, but I can understand enough of it to know what it's doing.

Btw, minJetEngineSpeed is 20.

Code: [Select]
function JetEngineCheck(%obj)
{
// return;
if(!isObject(%obj))
return;

%speed = vectorLen(%obj.getVelocity());
if(%speed < %obj.dataBlock.minJetEngineSpeed)
{
if(%obj.getMountedImage(0) !$= "")
{
%obj.unMountImage(0);
}
}
else
{
if(%obj.getMountedImage(0) $= 0)
{
%obj.mountImage(JetEngineImage2,0);
}
}

if(%obj.getMountedObject(0))
{
if(%obj.getMountedImage(1) $= 0)
{
%obj.mountImage(JetEngineImage1,1);
}
}
else
{
if(%obj.getMountedImage(1) !$= "")
{
%obj.unMountImage(1);
}
}

if(%obj.getMountedObject(0))
{
if(%obj.getMountedImage(1) $= 0)
{
%obj.mountImage(JetEngineImage1,1);
}
}
else
{
if(%obj.getMountedImage(1) !$= "")
{
%obj.unMountImage(1);
}
}

schedule(2000,0,"JetEngineCheck",%obj);
}

One jet works just fine, so I know I'm on the right track. I just need a little guidance for this last part.

I think it is checking the speed.
Code: [Select]
if(%speed < %obj.dataBlock.minJetEngineSpeed)In the vehicle code, it should have something saying
Code: [Select]
minJetengineSpeed = ?;That is the speed it needs before it can mount the trails. The rest I don't know. If you are looking for two jets, the stunt plane has 2 trails. I don't know about the minijet though.

I think it is checking the speed.

That is the speed it needs before it can mount the trails. The rest I don't know. If you are looking for two jets, the stunt plane has 2 trails. I don't know about the minijet though.

I know it's checking the speed, that's obvious, I just don't know if it does something at that speed I need to code so that the other jet will appear.

Here is the one from the stunt plane.
Code: [Select]
function contrailCheck(%obj)
{
// return;
if(!isObject(%obj))
return;

%speed = vectorLen(%obj.getVelocity());
if(%speed < %obj.dataBlock.minContrailSpeed)
{
if(%obj.getMountedImage(3) !$= "")
{
%obj.unMountImage(2);
%obj.unMountImage(3);
}
}
else
{
if(%obj.getMountedImage(3) $= 0)
{
%obj.mountImage(contrailImage1,2);
%obj.mountImage(contrailImage2,3);
}
}

if(%speed < 5)
{
if(%obj.prop !$= "slow")
{
%obj.playThread(0,propslow);
%obj.prop = "slow";
}
}
else
{
if(%obj.prop !$= "fast")
{
%obj.playThread(0,propfast);
%obj.prop = "fast";
}
}

schedule(2000,0,"contrailCheck",%obj);
}

Here is the one from the stunt plane.

- Code -


That did nothing but confuse me more. I need it deciphered. Not slammed with more code.

I believe the answer to your question lies in the JetEngineImage.

But describe what you want to know some better please.

As far as i can conclude is that you want to know how you can let it emit two trails at once.
Am i right about that?

Code: [Select]
function JetEngineCheck(%obj)
{
// return;
if(!isObject(%obj))
return;

%speed = vectorLen(%obj.getVelocity());
if(%speed < %obj.dataBlock.minJetEngineSpeed) // If the speed is less than 20
{
if(%obj.getMountedImage(0) !$= "") // and an image is mounted to slot 0
{
%obj.unMountImage(0); // unmount it
}
}
else //otherwise
{
if(%obj.getMountedImage(0) $= 0) // if an image isnt mounted to slot 0
{
%obj.mountImage(JetEngineImage2,0); //mount this one
}
}
//Jet Engine Image 2 goes into slot 0 above

//notably, Jet Engine Image 1 does not check for speed
if(%obj.getMountedObject(0))// I believe, "If Jet Engine Image 2 is mounted", try changing it
// to %obj.getMountedImage(0) !$= ""
{
if(%obj.getMountedImage(1) $= 0)// and Jet Engine Image 1 is not mounted to slot 1
{
%obj.mountImage(JetEngineImage1,1); //mount Jet Engine Image 1 to slot 1
}
}
else // if Jet Engine Image 2 isn't mounted
{
if(%obj.getMountedImage(1) !$= "") // and Jet Engine Image 1 is
{
%obj.unMountImage(1); // unmount Jet Engine Image 1
}
}

if(%obj.getMountedObject(0))//Repeat of the above, no changes. This part may be removable.
{
if(%obj.getMountedImage(1) $= 0)
{
%obj.mountImage(JetEngineImage1,1);
}
}
else
{
if(%obj.getMountedImage(1) !$= "")
{
%obj.unMountImage(1);
}
}

schedule(2000,0,"JetEngineCheck",%obj);
}

If Jet Engine Image 2 is mounted, the code assumes the speed matches the requirement and proceeds to mount Jet Engine Image 1
based on whether or not Jet Engine Image 2 is mounted currently.
It then proceeds to check and mount it a second time.

If you need additional explanation you'll have to be more clear in what you don't understand.

"I just don't know if it does something at that speed I need to code so that the other jet will appear.":
The other jet relies on Jet Engine Image 2's existance (or anything in the 0 image slot, for that matter) to be spawned instead of the
speed check used to spawn Jet Engine Image 1.

I would assume additional jet code would be

Code: [Select]
if(%obj.getMountedObject(0))//Repeat of the above, no changes. This part may be removable.
{
if(%obj.getMountedImage(2) $= 0)
{
%obj.mountImage(JetEngineImage3,2);
}
}
else
{
if(%obj.getMountedImage(2) !$= "")
{
%obj.unMountImage(2);
}
}

Okay, let me explain this as best as I can, there are two emitters by default, JetEngineImage1, and JetEngineImage2. Image 1 is a fire trail, and Image 2 is a smoke trail. These two together make one Jet Engine. I need a second Jet Engine.

Here's the coding for JetEngineImage1 and 2:

Code: [Select]
datablock ShapeBaseImageData(JetEngineImage1)
{
   shapeFile = "./empty.dts";
emap = false;

mountPoint = 1;
   rotation = "1 0 0 180";

stateName[0] = "Ready";
stateTransitionOnTimeout[0] = "FireA";
stateTimeoutValue[0] = 0.01;

stateName[1] = "FireA";
stateTransitionOnTimeout[1] = "Done";
stateWaitForTimeout[1] = True;
stateTimeoutValue[1] = 10000;
stateEmitter[1] = EngineEmitter;
stateEmitterTime[1] = 10000;

stateName[2] = "Done";
stateScript[2] = "onDone";
};
function JetEngineImage1::onDone(%this,%obj,%slot)
{
%obj.unMountImage(%slot);
}

datablock ShapeBaseImageData(JetEngineImage2)
{
   shapeFile = "./empty.dts";
emap = false;

mountPoint = 2;
   rotation = "1 0 0 180";

stateName[0] = "Ready";
stateTransitionOnTimeout[0] = "FireA";
stateTimeoutValue[0] = 0.01;

stateName[1] = "FireA";
stateTransitionOnTimeout[1] = "Done";
stateWaitForTimeout[1] = True;
stateTimeoutValue[1] = 10000;
stateEmitter[1] = EngineSmokeEmitter;
stateEmitterTime[1] = 10000;

stateName[2] = "Done";
stateScript[2] = "onDone";
};

To make the new jet engine, I simply replicated the values like this:

Code: [Select]
datablock ShapeBaseImageData(JetEngineImage3)
{
   shapeFile = "./empty.dts";
emap = false;

mountPoint = 3;
   rotation = "1 0 0 180";

stateName[0] = "Ready";
stateTransitionOnTimeout[0] = "FireA";
stateTimeoutValue[0] = 0.01;

stateName[1] = "FireA";
stateTransitionOnTimeout[1] = "Done";
stateWaitForTimeout[1] = True;
stateTimeoutValue[1] = 10000;
stateEmitter[1] = EngineEmitter;
stateEmitterTime[1] = 10000;

stateName[2] = "Done";
stateScript[2] = "onDone";
};
function JetEngineImage3::onDone(%this,%obj,%slot)
{
%obj.unMountImage(%slot);
}

datablock ShapeBaseImageData(JetEngineImage4)
{
   shapeFile = "./empty.dts";
emap = false;

mountPoint = 4;
   rotation = "1 0 0 180";

stateName[0] = "Ready";
stateTransitionOnTimeout[0] = "FireA";
stateTimeoutValue[0] = 0.01;

stateName[1] = "FireA";
stateTransitionOnTimeout[1] = "Done";
stateWaitForTimeout[1] = True;
stateTimeoutValue[1] = 10000;
stateEmitter[1] = EngineSmokeEmitter;
stateEmitterTime[1] = 10000;

stateName[2] = "Done";
stateScript[2] = "onDone";
};

There are four mountPoints involved, mount1 and mount 2 are used for the first engine, and mount3 and mount4 are used for the second engine.

I was able to replicate the JetEngine Images, but not the code that is posted in the OP. Because I don't know what it does, I couldn't mess with it.

Is everyone on the same page now?

Try this?
Code: [Select]
%speed = vectorLen(%obj.getVelocity());
if(%speed < %obj.dataBlock.minJetEngineSpeed)
{
if(%obj.getMountedImage(2) !$= "")
{
%obj.unMountImage(2);
}
}
else
{
if(%obj.getMountedImage(2) $= 0)
{
%obj.mountImage(JetEngineImage4,2);
}
}

if(%obj.getMountedObject(2))
{
if(%obj.getMountedImage(3) $= 0)
{
%obj.mountImage(JetEngineImage3,3);
}
}
else
{
if(%obj.getMountedImage(3) !$= "")
{
%obj.unMountImage(3);
}
}

if(%obj.getMountedObject(2))
{
if(%obj.getMountedImage(3) $= 0)
{
%obj.mountImage(JetEngineImage3,3);
}
}
else
{
if(%obj.getMountedImage(3) !$= "")
{
%obj.unMountImage(3);
}
}
Number changes are the future, man.

Try this?

-Code Snip-

Number changes are the future, man.

Tried it, didn't work. :/

Why don't you just make the smoke part of the jet emitter and stick with two emitters in total?

The code in the OP tells the vehicle to mount the images when n a certain speed.

Then to your two trail problem.
In the ShapeBaseImageData you can also state from which node it has to emit the emitter.
With this simple line:
stateEmitterNode[number of sequence] = "nodename"

So instead of 'mountpoints' you could use nodes to give the trail to both sides.
Or if Mountpoints are nodes, then you're lucky, but i don't know about that, i am not a moddeller. ;D

Why don't you just make the smoke part of the jet emitter and stick with two emitters in total?

Actually, I thought of that, and the weirdest thing happened. I completely removed the smoke datablock, and stuck with only the jet model, change the four mounts to two mounts, and the tested it, and the left jet was fire, and the right jet was for some very, very, odd reason... still smoke.

Go figure.

Actually, I thought of that, and the weirdest thing happened. I completely removed the smoke datablock, and stuck with only the jet model, change the four mounts to two mounts, and the tested it, and the left jet was fire, and the right jet was for some very, very, odd reason... still smoke.

Go figure.
Lolwut.

Send me a PM with the full code.
Or post it here. :P

At least, i suppose i have an idea what you are working on. ;D

Aight. I won't be able to get to it till tonight though. I'm not going to be at home till late tonight. I'll post it then.