Spellcasting system
by Lukas Joergensen · 04/07/2012 (12:17 pm) · 32 comments
Download code files
Hello, and welcome to my first resource! Please, help me in improving this resource if you find any errors, or badly explained parts you want clarified!
First off a quick list of features:
For the system to function properly, it needs the client to have a player. Because it uses the eyevector to calculate on where the spells should hit.
I will use the flamepillar spell as an example!
First create a new ScriptObject with the name of your spell:
Type defines what kind of spell it is (Projectil, summon, AoE, heal etc.)
Raytype defines what rayresult we want when using the CastAtScreenCenter method.
And add the new ScriptObject to the SimGroup 'spells'.
Then define a Cast function like this:
And then add the code for the spell:
Just copy everything from the folder into your own art folder. You don't have to override anything.
Please mind that the assets in the art folder is from the Torque Engine and as such is none of my property and even tho anything in this resource that i made is free those assets are not.
The decal is mine however you are free to use that as you please!
Then in art/datablocks/datablockExec.cs
Add this anywhere in the file:
Now step into the Client folder and copy:
After that just add the changes from default.bind_changes.cs to your own default.bind.cs
Now go into your init.cs file and add:
Now step into the Server folder and copy:
Then add the function in player_changes.cs with your player class.
Edit:
Almost forgot, to have spellanimations you need to add some animations to your model. If you like me use the stock Soldier model as your prototype model, add this in soldier_rigged.cs



This is my first resource so i might be missing something or have explained something poorly, again just comment on this resource if you want something fixed or shined a bit up! I will remain active on this resource!
Hello, and welcome to my first resource! Please, help me in improving this resource if you find any errors, or badly explained parts you want clarified!
First off a quick list of features:
- AoE spell indicator
- 2 sample spells Fireball and Pillar of Flame
- Simple pipeline for adding new spells
- Support for spellanimations
For the system to function properly, it needs the client to have a player. Because it uses the eyevector to calculate on where the spells should hit.
How to add a new spell:
First create a new file give it any name and place it in the Scripts/Server/Spells folder.I will use the flamepillar spell as an example!
First create a new ScriptObject with the name of your spell:
new ScriptObject( Flamepillar ){
superClass = Spell;
type = "AOE";
raytype = "point";
};
spells.add(Flamepillar);Always set superClass to Spell.Type defines what kind of spell it is (Projectil, summon, AoE, heal etc.)
Raytype defines what rayresult we want when using the CastAtScreenCenter method.
And add the new ScriptObject to the SimGroup 'spells'.
Then define a Cast function like this:
function Flamepillar::Cast(%this, %pos, %trans, %path, %team, %client)
{
// First if we miss any of the needed variables, message the error to the console
// and return with an error.
if(%pos $= ""){
error("No pos on Rogue::Cast");
return false;
}
if(%trans $= ""){
error("No trans on Rogue::Cast");
return false;
}
}And then add the code for the spell:
function Flamepillar::Cast(%this, %pos, %trans, %path, %team, %client)
{
// First if we miss any of the needed variables, message the error to the console
// and return with an error.
if(%pos $= ""){
error("No pos on Rogue::Cast");
return false;
}
if(%trans $= ""){
error("No trans on Rogue::Cast");
return false;
}
// Instantiate the ParticleEmitterNode which shows the almighty Pillar of Flame
%flame = new ParticleEmitterNode(){
position = %pos;
rotation = "1 0 0 0";
scale = "1 1 1 1";
dataBlock = broadNode;
emitter = broadEmitter;
velocity = 1;
};
// Dish out some damage when the Pillar of Flame is spawned
radiusDamage(%col, %pos, 2.5, 20, "Projectile", 0);
// Tell the client to lock for 2000 ms and cast spellanimation 1
commandToClient(%client, 'BeginCast', 2000, 1);
// Return with the instantiated object
return %flame;
}Then to fire the spell we will just use this:commandToServer('CastSpell', "Flamepillar");Or if we want it to have a spellIndicator:spellIndicator("Flamepillar");Installation
First download the code files (link at top).Just copy everything from the folder into your own art folder. You don't have to override anything.
Please mind that the assets in the art folder is from the Torque Engine and as such is none of my property and even tho anything in this resource that i made is free those assets are not.
The decal is mine however you are free to use that as you please!
Then in art/datablocks/datablockExec.cs
Add this anywhere in the file:
exec("./../effects/effects.cs");
exec("./../decals/indicatorDecal.cs");Now step into the Client folder and copy:
- movement.cs
- raycasts.cs
- scriptExec.cs
- spellindicator.cs
- (If you don't already have one) commands.cs
After that just add the changes from default.bind_changes.cs to your own default.bind.cs
Now go into your init.cs file and add:
exec("./scriptExec.cs");under Client scripts.Now step into the Server folder and copy:
- spell.cs
- spells
- utility
Then add the function in player_changes.cs with your player class.
Edit:
Almost forgot, to have spellanimations you need to add some animations to your model. If you like me use the stock Soldier model as your prototype model, add this in soldier_rigged.cs
%this.addSequence( "./Anims/PlayerAnim_Lurker_Celebrate_01.dae Celebrate_01", "spell_1", 0, -1); %this.addSequence( "./Anims/PlayerAnim_Lurker_Head.dae Head", "spell_2", 0, -1);In the onLoad function right after all the other addSequence calls.
Screenshots:
Pillar of Flame and spell animations:

Fireball

Spell indicator

This is my first resource so i might be missing something or have explained something poorly, again just comment on this resource if you want something fixed or shined a bit up! I will remain active on this resource!
About the author
IPS Bundle available at: https://www.winterleafentertainment.com/Products/IPS.aspx
#22
Change mouseFire to:
07/19/2013 (1:07 pm)
Okay do this:Change mouseFire to:
function mouseFire(%val)
{
if($canShoot)
$mvTriggerCount0++;
}And add this function:function enableShooting()
{
$canShoot = true;
}Then do something like this in cast:function Flamepillar::Cast(%this, %pos, %trans, %path, %team, %client)
{
// First if we miss any of the needed variables, message the error to the console
// and return with an error.
if(%pos $= ""){
error("No pos on Rogue::Cast");
return false;
}
if(%trans $= ""){
error("No trans on Rogue::Cast");
return false;
}
%player = %client.getControlObject();
if(%player.getEnergyLevel() >= %this.cost)
%player.setEnergyLevel(%player.getEnergyLevel() - %this.cost);
else{
error("Not enough energy!");
return false;
}
$canShoot = false;
//Cast spell stuff here
%animationTime = 2000; // Or how long you want to disable shooting.
schedule(%animationTime, 0, enableShooting);
}
#23
07/19/2013 (1:26 pm)
You can't shoot now at anytime. It's something with the "function mouseFire(%val)".
#24
07/19/2013 (1:53 pm)
Remember to initialize the $canShoot variable to true.
#25
07/19/2013 (1:59 pm)
It is set to true and I have added that function below mouseFire.
#26
07/19/2013 (2:14 pm)
Try testing if enableShooting is called. Mayhaps there is something wrong with the schedule.
#27
07/19/2013 (2:16 pm)
Doesn't work.
#28
schedule(2000, 0, enableShooting);
Worked fine for me.
Are you sure it doesn't get called? What does your console log say?
07/19/2013 (3:14 pm)
Weird, doing this:schedule(2000, 0, enableShooting);
Worked fine for me.
Are you sure it doesn't get called? What does your console log say?
#29
07/19/2013 (3:22 pm)
It seems to work but when you first enter the mission you can't shoot until you cast flame pillar then you can shoot.
#30
07/19/2013 (3:25 pm)
Try writing $canShoot = true; in the top of default.bind.cs
#31
07/19/2013 (3:32 pm)
That worked like a charm! Thank you very much for all your help!
#32
07/19/2013 (4:07 pm)
No problem! Good luck with your game! 
Torque Owner Stephen
GearedMind Studio