Plastic Gem #27: Zapper Tesla Coil
by Paul Dana · 07/17/2008 (4:47 am) · 3 comments
Download Code File

Plastic Gem # 27: Zapper Tesla Coil
Difficulty: Easy
NOTE: The .zip file was too large for GG resource so get it here.
Before following this gem, you must follow the instructions in Gem #20, Gem #25 and #26, which require Gem #2, Gem #25, and optionally Gem #3 if you want ease, which you do.
[b]The Zapper has a Tesla Coil effect between those knobby things there
Hi Paul Dana from Plastic Games again. Building on the previous gem, this gem will add a Tesla Coil effect to the PlasticZapper defined in the previous gem. A Tesla Coil effect, in this case, means an electrical zappy effect between a couple of posts.
1) Unzipping the files
Remember you must first follow the instructions in Gem #20, Gem #25, Gem #26, Gem #2, Gem #25 (and optionally Gem #3). This will give you the thread upgrade and the zapper shape itself and a first shot at zapper.cs. Next unzip the pg27_zapperTeslaCoil.zip file that comes with this gem. In there you will find a script file called zapper.cs that defines the PlasticZapper class with this gem's updaes, as well as a folder called shocker. Copy the shocker folder to your ~/data/shapes folder.
2) Updating the script
Copy the zapper.cs file from this gem's zip file over the zapper.cs you created in the previous gem. This version has all the stuff from last time, plust new stuff to create the Tesla Coil effect.
3) Testing it out
Just run the mission you made in the previous gem. The Tesla Coil effect should just show up.
4) Looking at the code
In the fan example from Gem #18, I just gave you a dump of ALL the code to make the fan work without describing how it all actaully worked. For the PlasticZapper object I am building up the functionality a bit at a time and try to explain a bit more what is going on as well. Let's take a look at what has changed in the code in zapper.cs.
First we defined a new datablock for the electricy effect called PlasticElectrode.
This is used in the new code you can see added to the ::onAdd() method:
Notice we are using the StaticShapeData.createStaticShape() dynamic creation method from Gem #20.
Notice that the ::onAdd() method simply creates the effect...mounts it on the Zapper object and then just runs the electrifying effect anim on that object.
The Next Gem
That's all for this gem. Tomorrow's gem will show how to make a managed trigger for this object that will control the mechanical arm, causing it to swing down when a player enters the trigger and swings back when the player leaves the area.

Plastic Gem # 27: Zapper Tesla Coil
Difficulty: Easy
NOTE: The .zip file was too large for GG resource so get it here.
Before following this gem, you must follow the instructions in Gem #20, Gem #25 and #26, which require Gem #2, Gem #25, and optionally Gem #3 if you want ease, which you do.
[b]The Zapper has a Tesla Coil effect between those knobby things thereHi Paul Dana from Plastic Games again. Building on the previous gem, this gem will add a Tesla Coil effect to the PlasticZapper defined in the previous gem. A Tesla Coil effect, in this case, means an electrical zappy effect between a couple of posts.
1) Unzipping the files
Remember you must first follow the instructions in Gem #20, Gem #25, Gem #26, Gem #2, Gem #25 (and optionally Gem #3). This will give you the thread upgrade and the zapper shape itself and a first shot at zapper.cs. Next unzip the pg27_zapperTeslaCoil.zip file that comes with this gem. In there you will find a script file called zapper.cs that defines the PlasticZapper class with this gem's updaes, as well as a folder called shocker. Copy the shocker folder to your ~/data/shapes folder.
2) Updating the script
Copy the zapper.cs file from this gem's zip file over the zapper.cs you created in the previous gem. This version has all the stuff from last time, plust new stuff to create the Tesla Coil effect.
3) Testing it out
Just run the mission you made in the previous gem. The Tesla Coil effect should just show up.
4) Looking at the code
In the fan example from Gem #18, I just gave you a dump of ALL the code to make the fan work without describing how it all actaully worked. For the PlasticZapper object I am building up the functionality a bit at a time and try to explain a bit more what is going on as well. Let's take a look at what has changed in the code in zapper.cs.
First we defined a new datablock for the electricy effect called PlasticElectrode.
// ok this object is electric effect for the tesla coil
datablock StaticShapeData(PlasticZapperElectrode)
{
shapeFile = "~/data/shapes/shocker/shocker.dts";
};This is used in the new code you can see added to the ::onAdd() method:
// this shows dynamic creation from Gem #20...otherwise you would have to do this: %electrode = new StaticShape() { dataBlock = PlasticZapperElectrode; }; MissionCleanup.add(%electrode);
%electrode = PlasticZapperElectrode.createStaticShape();
// mount electrode effect
%obj.mountObject(%electrode,1);
%obj.electrode = %electrode;
%electrode.playThread(0,"electrode");
%electrode.setThreadSpeed(0, 0.5);
}Notice we are using the StaticShapeData.createStaticShape() dynamic creation method from Gem #20.
Notice that the ::onAdd() method simply creates the effect...mounts it on the Zapper object and then just runs the electrifying effect anim on that object.
The Next Gem
That's all for this gem. Tomorrow's gem will show how to make a managed trigger for this object that will control the mechanical arm, causing it to swing down when a player enters the trigger and swings back when the player leaves the area.
About the author
Torque Owner Mike Rowley
These Gems are awesome tho. Looking forward to working with this one too. :-)