Very simple "spell casting"
by Stefan Beffy Moises · 07/13/2002 (8:41 am) · 19 comments
Download Code File
First of all, thanks to Sabrecyd and LabRat and "the IRC guys" for helping me to solve some problems with this!
Ok, lets start with the actual "doSpell()" function, which is placed in "fps/server/scripts/game.cs" (shouldn't really matter where
you put it on the server side...).
It takes the radius the damage should be done in, the client casting the spell, and the type of spell (currently "1" for
Explosions, "2" for ParticleEmitters only... here it is:
It takes the players' transform (position), adjusts the z value to get it off the ground,
then takes the current eye vector of the player, scales it (adjust this value to change the distance of the spell)
and adds it to the transform vector - otherwise
the spell would just stay in the same position all the time, even if the player was turning...
If it only uses the ParticleEmitter, it also plays a sound using:
Then I've got a call to this function in "fps/server/scripts/commands.cs":
The actual call to the function is in "fps/client/scripts/defaultBind.cs":
You also need to add this mapping in "fps/client/config.cs":
If you also want this to be in the options dialog so that you can remap it, put this into the
remapping section in "fps/client/scripts/optionsDlg.cs":
Okay, then I've made a new Explosion file by simply copying the important stuff from "crossbow.cs" (RealmWars),
this file introduces some AudioProfiles, ParticleEmitter, Explosions, and a, like "virtual projectile",
the "SpellBolt" ;-), which I simply need to apply damage by using the spell...
here is just the AudioProfile for the spell itself, which I also use for the "ParticleEmitter" spell type...
for further details, please look into the file which is contained in the zip file provided...
Ok, here is the ParticleEmitter which I use as type "2" spell...
It's just an alternative if you don't want a complete explosion to appear ...
I've put it into my own "customParticles" file (which is executed in "game.cs", of course...)
This could be improved in various directions, of course...
- First of all, I don't really like the switch block choosing between
the 2 (or more) spell types... maybe you can come up with some better and more dynamic solution here...
- Then, the distance is always the same, so the spell isn't "spreading"...
- Also, there is no collision detection involved... so the spell can appear inside of trees, buildings,
in the terrain, etc. ... should be added, too... ;-)
Anyhow, I hope it's something you can use to play around with and maybe improve it and give it back to
the community... :-)
You can download the cs and wav files needed here alternatively!
Have fun! :-)
First of all, thanks to Sabrecyd and LabRat and "the IRC guys" for helping me to solve some problems with this!
Ok, lets start with the actual "doSpell()" function, which is placed in "fps/server/scripts/game.cs" (shouldn't really matter where
you put it on the server side...).
It takes the radius the damage should be done in, the client casting the spell, and the type of spell (currently "1" for
Explosions, "2" for ParticleEmitters only... here it is:
// fps/server/scripts/game.cs
// NOTE: if you encounter problems in Multiplayer, try to put this on the client side as
// clientCmdDoSpell - didn't test it yet in MP...
function doSpell(%radius,%client,%type)
{
%radiusDamage = 8.0;
%pos = %client.player.getTransform();
%x = getWord(%pos, 0);
%y = getWord(%pos, 1);
%z = getWord(%pos, 2);
// adjust z value a bit...
%z += 2.0;
%finalPos = %x SPC %y SPC %z;
%eye = %client.player.getEyeVector();
%vec = vectorScale(%eye, 20);
%finalPos = vectorAdd(%finalPos, %vec);
switch$(%type)
{
case "1":
// EXPLOSION
%p = new explosion() {
dataBlock = "SpellExplosion";
position = %finalPos;
};
MissionCleanup.add(%p);
// Radius damage is a support script defined in radiusDamage.cs
radiusDamage(%p,%finalPos,%radius,%radiusDamage,"SpellBolt",0);
case "2":
// PARTICLES WITH SOUND
%p = new ParticleEmitterNode() {
position = %finalPos;
rotation = "1 0 0 0";
scale = "1 1 1";
dataBlock = "defaultParticleEmitterNode";
emitter = "BlueSpellEmitter";
velocity = "1";
};
serverPlay3D(SpellSound,%client.player);
radiusDamage(%p,%finalPos,%radius,%radiusDamage,"SpellBolt",0);
%p.schedule(2000,"delete");
default:
// EXPLOSION
%p = new explosion() {
dataBlock = "SpellExplosion";
position = %finalPos;
};
MissionCleanup.add(%p);
radiusDamage(%p,%finalPos,%radius,%radiusDamage,"SpellBolt",0);
}
}It takes the players' transform (position), adjusts the z value to get it off the ground,
then takes the current eye vector of the player, scales it (adjust this value to change the distance of the spell)
and adds it to the transform vector - otherwise
the spell would just stay in the same position all the time, even if the player was turning...
If it only uses the ParticleEmitter, it also plays a sound using:
serverPlay3D(SpellSound,%client.player);
Then I've got a call to this function in "fps/server/scripts/commands.cs":
// fps/server/scripts/commands.cs
function serverCmdDoSpell(%client)
{
doSpell("50",%client,1);
}The actual call to the function is in "fps/client/scripts/defaultBind.cs":
function castSpell(%val)
{
if(%val)
{
commandToServer('DoSpell');
}
}
// bind a key to it
moveMap.bind(keyboard, "ctrl s", castSpell);You also need to add this mapping in "fps/client/config.cs":
moveMap.bind(keyboard, "ctrl s", castSpell);
If you also want this to be in the options dialog so that you can remap it, put this into the
remapping section in "fps/client/scripts/optionsDlg.cs":
// fps/client/scripts/optionsDlg.cs $RemapName[$RemapCount] = "Cast Spell"; $RemapCmd[$RemapCount] = "castSpell"; $RemapCount++;
Okay, then I've made a new Explosion file by simply copying the important stuff from "crossbow.cs" (RealmWars),
this file introduces some AudioProfiles, ParticleEmitter, Explosions, and a, like "virtual projectile",
the "SpellBolt" ;-), which I simply need to apply damage by using the spell...
here is just the AudioProfile for the spell itself, which I also use for the "ParticleEmitter" spell type...
for further details, please look into the file which is contained in the zip file provided...
// fps/server/scripts/spellExplosion.cs
datablock AudioProfile(SpellSound)
{
fileName = "~/data/sound/fx/spark1.wav";
description = AudioClose3d;
preload = true;
};
...
// all the other exlosion/emitter stuff...Ok, here is the ParticleEmitter which I use as type "2" spell...
It's just an alternative if you don't want a complete explosion to appear ...
I've put it into my own "customParticles" file (which is executed in "game.cs", of course...)
// fps/server/scripts/customParticles.cs
datablock ParticleData(BlueSpellParticle)
{
dragCoefficient = 1.11437;
gravityCoefficient = -0.735043;
windCoefficient = 0;
inheritedVelFactor = 0.483366;
constantAcceleration = 0;
lifetimeMS = 1056;
lifetimeVarianceMS = 256;
useInvAlpha = 0;
spinRandomMin = -159;
spinRandomMax = 172;
textureName = "fps/data/shapes/rifle/smokeParticle";
times[0] = 0;
times[1] = 1;
colors[0] = "0.002362 0.010866 0.700000 0.370079";
colors[1] = "0.000000 0.102362 0.800000 0.740157";
sizes[0] = 6.08863;
sizes[1] = 0;
};
datablock ParticleEmitterData(BlueSpellEmitter)
{
ejectionPeriodMS = 10;
periodVarianceMS = 2;
ejectionVelocity = 2.75;
velocityVariance = 1.62;
ejectionOffset = 0;
thetaMin = 47;
thetaMax = 90;
phiReferenceVel = 144;
phiVariance = 360;
overrideAdvances = 0;
orientParticles= 0;
orientOnVelocity = 1;
particles = "BlueSpellParticle";
};This could be improved in various directions, of course...
- First of all, I don't really like the switch block choosing between
the 2 (or more) spell types... maybe you can come up with some better and more dynamic solution here...
- Then, the distance is always the same, so the spell isn't "spreading"...
- Also, there is no collision detection involved... so the spell can appear inside of trees, buildings,
in the terrain, etc. ... should be added, too... ;-)
Anyhow, I hope it's something you can use to play around with and maybe improve it and give it back to
the community... :-)
You can download the cs and wav files needed here alternatively!
Have fun! :-)
#2
You know what would be cool is to tap into how the crosshair triggers the little healthbar of a player or bot and make the spell explode at that location. I'm not sure where that code is or if that's possible for sure. I did look a little bit last night but it was getting late and I spent too much time playing around with the teleporting, this spell(s), shooting bots, and working on a mission file :)
07/16/2002 (5:19 am)
More great stuff Stefan. You might want to define %radius too (maybe 15 or at least something slightly less then the vectorScale #). I noticed the explosion will damage the caster too - ow ;) I haven't tried it client side or networked, but I noticed this won't give the frag credit to the caster. I have that problem in a couple areas right now. Mostly to do with spawned explosions.You know what would be cool is to tap into how the crosshair triggers the little healthbar of a player or bot and make the spell explode at that location. I'm not sure where that code is or if that's possible for sure. I did look a little bit last night but it was getting late and I spent too much time playing around with the teleporting, this spell(s), shooting bots, and working on a mission file :)
#3
Anyhow, I'll give it a try, too...
What I'd really like to achieve though is a "moving" spell, one that moves fast from the caster towards the enemy and then explodes or whatever... don't know if that's possible, though... how do you move an explosion...? Maybe we can move a ParticleEffect and once it has reached the enemy, create a new explosion at this location...
And there should really be a more dynamic "spell switching"... the above switch statement is very cheesy IMO ... I think if I ever find the time I will write a generic "Spell" C++ class (e.g. "spell.cc"), which you can derive from (bigExplosionSpell.cc, redFireEmitterHealingSpell.cc, ...) , and add and call new spells dynamically...
and not to forget the collision detection...
like I said, there are a million possible improvements... as always... :-P
07/16/2002 (7:03 am)
Thanks Savrecyd! Actually I like your idea with the spell "exploding" at the opponents' health bar location... only problem is that these health bars are currently broken in our dev version and don't show up at all... :-/ Got no idea how that could have happened...Anyhow, I'll give it a try, too...
What I'd really like to achieve though is a "moving" spell, one that moves fast from the caster towards the enemy and then explodes or whatever... don't know if that's possible, though... how do you move an explosion...? Maybe we can move a ParticleEffect and once it has reached the enemy, create a new explosion at this location...
And there should really be a more dynamic "spell switching"... the above switch statement is very cheesy IMO ... I think if I ever find the time I will write a generic "Spell" C++ class (e.g. "spell.cc"), which you can derive from (bigExplosionSpell.cc, redFireEmitterHealingSpell.cc, ...) , and add and call new spells dynamically...
and not to forget the collision detection...
like I said, there are a million possible improvements... as always... :-P
#4
Yeah, moving spells with collisions and an entire spell class would be very cool and probably the best way to go. That would basically be a projectile object then instead of just an explosion or emitter. A better switching method would also be good. Maybe I'll look at this some more too. That time issue is always a problem :(
edit: Was just thinking about your moving explosion comment. That wouldn't be a projectile would it...not if you want that big explosion or emitter moving towards the enemy. Yeah, that would look cool :)
07/16/2002 (7:25 am)
That's funny you say that about the healthbar. Somehow I managed to "break" the names above the players and the healthbar on other players at one point too. I kinda forgot they were even there until I redid everything on a HEAD version in May (mostly to get vehicles working). Then they came back. I'm not sure what I did to make them disappear.Yeah, moving spells with collisions and an entire spell class would be very cool and probably the best way to go. That would basically be a projectile object then instead of just an explosion or emitter. A better switching method would also be good. Maybe I'll look at this some more too. That time issue is always a problem :(
edit: Was just thinking about your moving explosion comment. That wouldn't be a projectile would it...not if you want that big explosion or emitter moving towards the enemy. Yeah, that would look cool :)
#5
But maybe we could use a projectile with an attached fxLight object for this, too...
I've used Melv's fxLight for tuning the crossbow projectiles, looks pretty impressive, too... :-)
Let me know if you work on this, so that we don't end up doing the same stuff twice...
07/16/2002 (9:24 am)
Yep, that's what I'd like to do... move a big, fat emitter towards the enemy and then create an even bigger explosion on arrival... ^-^ hehehe... ;-)But maybe we could use a projectile with an attached fxLight object for this, too...
I've used Melv's fxLight for tuning the crossbow projectiles, looks pretty impressive, too... :-)
Let me know if you work on this, so that we don't end up doing the same stuff twice...
#6
07/16/2002 (9:32 am)
Will do. I have the fxlight stuff in too, but haven't really done anything with them yet. That is a good thing to point out to check. Your description made me envision a blue-firey "tornado" type funnel cloud moving towards the enemy then exploding on contact - sweet :)
#7
I would instead focus on creating the various classes of spells, and then on their effects.
For instance, you might have one spell that is a projectile (with or without gravity arc) and triggers a certain effect upon impact. Another spell would be of the type described above (a more skill-dependant Direct Damage type of spell, using the name/healthbar to trigger it is a brilliant improvisation and one that makes a lot more sense than some sort of auto-target, or alternatively, needing pixel-perfect accuracy). Still another might be purely pixel-perfect, and create an effect at the location targetted.
But the effects are defined separately, allowing you to mix and match casting types and effects to create almost any spell you want. For instance, create a projectile spell that creates an Area of Effect damage type (splash damage) on impact. Or create a direct damage type spell (healthbar targetted) whose effect is a 'damage over time' spell (like poison, etc). Or an aimed spell (pixel-perfect aiming) whose effect is to create a pulsing area of effect damage type, while applying a particle effect to the affected area (like, say, a firestorm spell that appears to set everything in a radius on fire and will damage you the longer you're in it).
Then you can just mix and match the basic casting types -- which determines the location of the spell -- with the effect you want to occur at that location.
This is all basically the same stuff that you had in Tribes 1 btw. You had aimed projectile spells with single-target damage on impact, projectile spells with splash damage on impact, aimed direct damage spells (laser rifle), and a kind of auto-targetted spell in the Rocket Turret, altho Tribes 2 obviously did a better job of refining the targetting process.
07/16/2002 (12:48 pm)
Well, the idea of a 'spell' is pretty wide-ranging.I would instead focus on creating the various classes of spells, and then on their effects.
For instance, you might have one spell that is a projectile (with or without gravity arc) and triggers a certain effect upon impact. Another spell would be of the type described above (a more skill-dependant Direct Damage type of spell, using the name/healthbar to trigger it is a brilliant improvisation and one that makes a lot more sense than some sort of auto-target, or alternatively, needing pixel-perfect accuracy). Still another might be purely pixel-perfect, and create an effect at the location targetted.
But the effects are defined separately, allowing you to mix and match casting types and effects to create almost any spell you want. For instance, create a projectile spell that creates an Area of Effect damage type (splash damage) on impact. Or create a direct damage type spell (healthbar targetted) whose effect is a 'damage over time' spell (like poison, etc). Or an aimed spell (pixel-perfect aiming) whose effect is to create a pulsing area of effect damage type, while applying a particle effect to the affected area (like, say, a firestorm spell that appears to set everything in a radius on fire and will damage you the longer you're in it).
Then you can just mix and match the basic casting types -- which determines the location of the spell -- with the effect you want to occur at that location.
This is all basically the same stuff that you had in Tribes 1 btw. You had aimed projectile spells with single-target damage on impact, projectile spells with splash damage on impact, aimed direct damage spells (laser rifle), and a kind of auto-targetted spell in the Rocket Turret, altho Tribes 2 obviously did a better job of refining the targetting process.
#8
I've been side tracked with some bot AI lately. Nothing very good yet. I've been holding off doing much because I'd like to check out that FEAR bot stuff. I have managed to make them capable of killing me now and then.
07/22/2002 (5:20 am)
You're right of course, there probably should be a seperate spell class. The mixing of effects would be a great thing to have. I might have to take a look at this again. I've been side tracked with some bot AI lately. Nothing very good yet. I've been holding off doing much because I'd like to check out that FEAR bot stuff. I have managed to make them capable of killing me now and then.
#9
Blood
I was just thinking that maybe spawning a projectile and manipulating that might work better then the spawned explosion. Spawning a projectile doesn't seem to have those client side "problems". It might give you some more ideas for spell use anyway.
-Sabrecyd
08/15/2002 (8:43 am)
Stefan, you should check out the "blood" code that Michael Cozzolino has worked on.Blood
I was just thinking that maybe spawning a projectile and manipulating that might work better then the spawned explosion. Spawning a projectile doesn't seem to have those client side "problems". It might give you some more ideas for spell use anyway.
-Sabrecyd
#10
08/24/2002 (7:52 pm)
I cant get it to work, all it does it damage my player
#11
Screw around with the spells final location until the spell is distant enough not to harm the player.
eg. In the game.cs:doSpell() function increase
the second param in the vectorScale() call.
(I changed it from 20 to 60.)
%eye = %client.player.getEyeVector();
%vec = vectorScale(%eye, 20);
%finalPos = vectorAdd(%finalPos, %vec);
08/26/2002 (8:48 pm)
Jecht, I encountered this. It appears the spells final position is too close and the player is caught in the spells damage radius.Screw around with the spells final location until the spell is distant enough not to harm the player.
eg. In the game.cs:doSpell() function increase
the second param in the vectorScale() call.
(I changed it from 20 to 60.)
%eye = %client.player.getEyeVector();
%vec = vectorScale(%eye, 20);
%finalPos = vectorAdd(%finalPos, %vec);
#13
Something like a SpellBase class that all spell types inherit from, then down to something like ParticleSpellBase, ExplosionSpellBase, etc. then a class for each individual spell the end user would implement. Anyways, just a thought so I might extend this resource and post a new one with inherited spell classes or something. Thanks!
Edit: Duh. Luc had already mentioned this before. Oh I need more tic-tacs.
07/06/2004 (6:32 pm)
@Stefan: Just looking at this resource again after awhile. You mentioned about not liking the switch statement in handling of the spells (I don't blame you). As there's been a lot of discussions recently of some people wanting to write in a more OO manner with TorqueScript, I thought a nice way would be to create spell classes/datablocks and use Torque inheritance model for this.Something like a SpellBase class that all spell types inherit from, then down to something like ParticleSpellBase, ExplosionSpellBase, etc. then a class for each individual spell the end user would implement. Anyways, just a thought so I might extend this resource and post a new one with inherited spell classes or something. Thanks!
Edit: Duh. Luc had already mentioned this before. Oh I need more tic-tacs.
#14
First of all, I posted this big long post and clicked NOTIFY WHEN NEW COMMENTS ARE POSTED..
and then my big long post was deleted when the page refreshed.. DOH!!! That hurts.
SO here's a more condensed version. Any help would be appreciated.
Is this resource still valid? I tried to implement it on the latest HEAD and this is my problem:
i echo stuff to the console log and see that I entered the following functions just fine:
--------------------------------------
entered castSpell
Mapping string: DoSpell to index: 3
entered serverCmdDoSpell
Entered doSpell in game.cs
Object 'SpellExplosion' is not a member of the 'GameBaseData' data block class
nicodemus/server/scripts/game.cs (411): Register object failed for object (null) of class Explosion.
Set::add: Object "0" doesn't exist
entered castSpell
entered serverCmdDoSpell
Entered doSpell in game.cs
Object 'SpellExplosion' is not a member of the 'GameBaseData' data block class
nicodemus/server/scripts/game.cs (411): Register object failed for object (null) of class Explosion.
Set::add: Object "0" doesn't exist
--------------------------------------
It seems like Im not defining something somewhere or missed something in this recourse, but I don't know what..
If anyone can help me out, I would appreciate it.
EDIT: Formatting and typo corrections.
10/04/2004 (3:16 pm)
Hello All.First of all, I posted this big long post and clicked NOTIFY WHEN NEW COMMENTS ARE POSTED..
and then my big long post was deleted when the page refreshed.. DOH!!! That hurts.
SO here's a more condensed version. Any help would be appreciated.
Is this resource still valid? I tried to implement it on the latest HEAD and this is my problem:
i echo stuff to the console log and see that I entered the following functions just fine:
--------------------------------------
entered castSpell
Mapping string: DoSpell to index: 3
entered serverCmdDoSpell
Entered doSpell in game.cs
Object 'SpellExplosion' is not a member of the 'GameBaseData' data block class
nicodemus/server/scripts/game.cs (411): Register object failed for object (null) of class Explosion.
Set::add: Object "0" doesn't exist
entered castSpell
entered serverCmdDoSpell
Entered doSpell in game.cs
Object 'SpellExplosion' is not a member of the 'GameBaseData' data block class
nicodemus/server/scripts/game.cs (411): Register object failed for object (null) of class Explosion.
Set::add: Object "0" doesn't exist
--------------------------------------
It seems like Im not defining something somewhere or missed something in this recourse, but I don't know what..
If anyone can help me out, I would appreciate it.
EDIT: Formatting and typo corrections.
#15
Create them simliar to the weapons system.... look in weapons.cs maybe even copy it to spells.cs (im not sure yet as i havent started the spell code) also look in inv.cs and probaly change it to something like spellinv.cs
Then do it just like you would make a weapon assign a "cast" key like a fire key and then spells can be added to the spellinv like weapons can then it would take very little to write a gui to look over your your various spells (check out the guis for the normal inv they should port or i dont see a reason they wouldnt) and set which one is the current casting spell or hotkeys to them or numberkeys or you get the point.
Now this is probaly a really stupid idea as I dont know as much about torque as you guys but i see a spell as nothing more then a type of weapon with a diffrent key to use it.
The reasons I feel my idea might fail is mostly copying and renaming the files..... I would assume alot of variables would have to be changed add somehting like sp to them all for spells or whatever. Im not really sure how the engine would handle this as I havent dabbled much with the source to it im already dreading that as it is for my more indepth networking.
01/26/2005 (11:33 am)
Hmm I am currently doing an mmorpg and this is the way I looked at spells, others may see flaws to this and if so please let me know.Create them simliar to the weapons system.... look in weapons.cs maybe even copy it to spells.cs (im not sure yet as i havent started the spell code) also look in inv.cs and probaly change it to something like spellinv.cs
Then do it just like you would make a weapon assign a "cast" key like a fire key and then spells can be added to the spellinv like weapons can then it would take very little to write a gui to look over your your various spells (check out the guis for the normal inv they should port or i dont see a reason they wouldnt) and set which one is the current casting spell or hotkeys to them or numberkeys or you get the point.
Now this is probaly a really stupid idea as I dont know as much about torque as you guys but i see a spell as nothing more then a type of weapon with a diffrent key to use it.
The reasons I feel my idea might fail is mostly copying and renaming the files..... I would assume alot of variables would have to be changed add somehting like sp to them all for spells or whatever. Im not really sure how the engine would handle this as I havent dabbled much with the source to it im already dreading that as it is for my more indepth networking.
#16
09/24/2007 (12:35 am)
Edit: sry all, replied on the wrong place
#17
11/25/2007 (1:59 am)
You could probly shoot a ray from the player to the position he is looking at tell it hits somthing then have the explosion happen at that position.. ill post code later when i get time to work on it (mite be a week or so)
#18
//:) spell command
//Just it doesn't waste magic so this could be spam :x
function doSpell(%radius,%client,%type)
{
%player = %client.player;
%radiusDamage = 8.0;
%pos = %client.player.getTransform();
%x = getWord(%pos, 0);
%y = getWord(%pos, 1);
%z = getWord(%pos, 2);
// adjust z value a bit...
%z += 2.0;
%finalPos = %x SPC %y SPC %z;
%eye = %client.player.getEyeVector();
%vec = vectorScale(%eye, 60);
%finalPos = vectorAdd(%finalPos, %vec);
//added by skylord.
%RayCast=containerraycast(vectoradd(%client.player.getposition(),"0 0 2.5"),%finalPos,$TypeMasks::WaterObjectType |
$TypeMasks::WaterObjectType |
$TypeMasks::PlayerObjectType |
$TypeMasks::VehicleBlockerObjectType |
$TypeMasks::TerrainObjectType |
$TypeMasks::ShapeBaseObjectType |
$TypeMasks::InteriorObjectType |
$TypeMasks::StaticObjectType |
$TypeMasks::StaticShapeObjectType,%player);
if(%RayCast)//Must have hit somthing Between lets figure out where it happened
{
%x = getword(%RayCast,1);%y = getword(%RayCast,2);%z = getword(%RayCast,3);
%finalpos = %x SPC %y SPC %z;
}
echo(firstword(%raycast));
//if it doesn't find somthing it will just make a explosion.
switch$(%type)
{
case "1":
// EXPLOSION
%p = new explosion() {
dataBlock = "SpellExplosion";
position = %finalPos;
};
MissionCleanup.add(%p);
// Radius damage is a support script defined in radiusDamage.cs
radiusDamage(%p,%finalPos,%radius,%radiusDamage,"SpellBolt",0);
case "2":
// PARTICLES WITH SOUND
%p = new ParticleEmitterNode() {
position = %finalPos;
rotation = "1 0 0 0";
scale = "1 1 1";
dataBlock = "defaultParticleEmitterNode";
emitter = "BlueSpellEmitter";
velocity = "1";
};
serverPlay3D(SpellSound,%client.player);
radiusDamage(%p,%finalPos,%radius,%radiusDamage,"SpellBolt",0);
%p.schedule(2000,"delete");
default:
// EXPLOSION
%p = new explosion() {
dataBlock = "SpellExplosion";
position = %finalPos;
};
MissionCleanup.add(%p);
radiusDamage(%p,%finalPos,%radius,%radiusDamage,"SpellBolt",0);
}
}
12/11/2007 (1:36 pm)
Here is my spell command so the explosion doesn't go threw objects //:) spell command
//Just it doesn't waste magic so this could be spam :x
function doSpell(%radius,%client,%type)
{
%player = %client.player;
%radiusDamage = 8.0;
%pos = %client.player.getTransform();
%x = getWord(%pos, 0);
%y = getWord(%pos, 1);
%z = getWord(%pos, 2);
// adjust z value a bit...
%z += 2.0;
%finalPos = %x SPC %y SPC %z;
%eye = %client.player.getEyeVector();
%vec = vectorScale(%eye, 60);
%finalPos = vectorAdd(%finalPos, %vec);
//added by skylord.
%RayCast=containerraycast(vectoradd(%client.player.getposition(),"0 0 2.5"),%finalPos,$TypeMasks::WaterObjectType |
$TypeMasks::WaterObjectType |
$TypeMasks::PlayerObjectType |
$TypeMasks::VehicleBlockerObjectType |
$TypeMasks::TerrainObjectType |
$TypeMasks::ShapeBaseObjectType |
$TypeMasks::InteriorObjectType |
$TypeMasks::StaticObjectType |
$TypeMasks::StaticShapeObjectType,%player);
if(%RayCast)//Must have hit somthing Between lets figure out where it happened
{
%x = getword(%RayCast,1);%y = getword(%RayCast,2);%z = getword(%RayCast,3);
%finalpos = %x SPC %y SPC %z;
}
echo(firstword(%raycast));
//if it doesn't find somthing it will just make a explosion.
switch$(%type)
{
case "1":
// EXPLOSION
%p = new explosion() {
dataBlock = "SpellExplosion";
position = %finalPos;
};
MissionCleanup.add(%p);
// Radius damage is a support script defined in radiusDamage.cs
radiusDamage(%p,%finalPos,%radius,%radiusDamage,"SpellBolt",0);
case "2":
// PARTICLES WITH SOUND
%p = new ParticleEmitterNode() {
position = %finalPos;
rotation = "1 0 0 0";
scale = "1 1 1";
dataBlock = "defaultParticleEmitterNode";
emitter = "BlueSpellEmitter";
velocity = "1";
};
serverPlay3D(SpellSound,%client.player);
radiusDamage(%p,%finalPos,%radius,%radiusDamage,"SpellBolt",0);
%p.schedule(2000,"delete");
default:
// EXPLOSION
%p = new explosion() {
dataBlock = "SpellExplosion";
position = %finalPos;
};
MissionCleanup.add(%p);
radiusDamage(%p,%finalPos,%radius,%radiusDamage,"SpellBolt",0);
}
}
#19
03/07/2009 (11:31 am)
Ahh thanks. Very useful. Now I just got to work this out and make different types of spells.
Associate Ben Garney
And even if you don't use it for the spell effect, this is a good example of how to add some functionality to the game. The only thing that would make it better would be if the method of making it work multiplayer was better explained.