MMORPG Tutorial Article 5 Simply Magic...
by Dreamer · 04/12/2005 (9:24 pm) · 30 comments
First off if you haven't done so already, please start here...
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=7514
Create a file server/scripts/DDSpell.cs
Add this to it...
Now in commands.cs add
In client/scripts/default.bind.cs add
Thats it now target something and hit the C button, it will cast a nasty little spell on them doing immediate direct damage.
Next we will add a database and begin work on the Massively Mulitplayer aspects of our MMORPG. Enjoy!
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=7514
Create a file server/scripts/DDSpell.cs
Add this to it...
datablock ProjectileData(SpellProjectile)
{
projectileShapeName = "~/data/shapes/crossbow/projectile.dts";
directDamage = 20;
radiusDamage = 20;
damageRadius = 1.5;
EnergyCost = 10;
explosion = CrossbowExplosion;
waterExplosion = CrossbowWaterExplosion;
particleEmitter = CrossbowBoltEmitter;
particleWaterEmitter= CrossbowBoltBubbleEmitter;
splash = CrossbowSplash;
muzzleVelocity = 10;
velInheritFactor = 0.3;
armingDelay = 0;
lifetime = 5000;
fadeDelay = 5000;
bounceElasticity = 0;
bounceFriction = 0;
isBallistic = true;
gravityMod = 0.80;
hasLight = true;
lightRadius = 4;
lightColor = "0.5 0.5 0.25";
hasWaterLight = true;
waterLightColor = "0 0.5 0.5";
};
function SpellProjectile::onCollision(%this,%obj,%col,%fade,%pos,%normal)
{
// Apply damage to the object all shape base objects
if (%col.getType() & $TypeMasks::ShapeBaseObjectType)
%col.damage(%obj,%pos,%this.directDamage,"CrossbowBolt");
// Radius damage is a support scripts defined in radiusDamage.cs
// Push the contact point away from the contact surface slightly
// along the contact normal to derive the explosion center. -dbs
radiusDamage(%obj, VectorAdd(%pos, VectorScale(%normal, 0.01)),%this.damageRadius,%this.radiusDamage,"Radius",40);
}Now in commands.cs add
function ServerCmdCastSpell(%client,%spell){
%Player = %client.Player;
echo("Casting Spell!");
if(%spell $="Bolt"){
echo("Spell was Bolt!");
%EnergyCost = 10;
if(%client.Player.getEnergyLevel() > %EnergyCost){
%targetObject = %client.getSelectedObject();
%bolt = new (Projectile)() {
dataBlock = SpellProjectile;
initialVelocity = 10;
initialPosition = %targetObject.getTransform();
sourceObject = %Player;
client = %client;
};
%client.Player.setEnergyLevel(%client.Player.getEnergyLevel() - %EnergyCost);
echo("Client energy is "@%client.Player.getEnergyLevel());
MissionCleanup.add(%bolt);
}else{
MessageClient(%client,'No Energy','You are too weak to cast this spell');
}
//%targetObject.applyRepair(100);
}
if(%spell $="Heal"){
echo("Spell was Heal!");
%EnergyCost = 10;
if(%client.Player.getEnergyLevel() > %EnergyCost){
%targetObject = %client.getSelectedObject();
%client.Player.setEnergyLevel(%client.Player.getEnergyLevel() - %EnergyCost);
echo("Client energy is "@%client.Player.getEnergyLevel());
%targetObject.applyRepair(10);
}else{
MessageClient(%client,'No Energy','You are too weak to cast this spell');
}
}
echo("Casting Complete!");
}In client/scripts/default.bind.cs add
moveMap.bind(keyboard,"c","CastSpell");
function CastSpell(){
CommandToServer('CastSpell',"Bolt");
}Thats it now target something and hit the C button, it will cast a nasty little spell on them doing immediate direct damage.
Next we will add a database and begin work on the Massively Mulitplayer aspects of our MMORPG. Enjoy!
#2
Regarding my comment in another of your resources, getting all of the most recent 'code snippet' entries is kind of a notoriety thing. I did mean it as a compliment, but I shouldn't have just posted that without a comment on the resource itself. :|
Again, I'm looking foward to strapping this code in and trying it out. One note. If you've got a web-site (even if you say your art is sub-par), I'm sure folks would love to see some screens to go with your posts. If you don't have a site and want to post some screens I'm sure someone (myself included) would be willing to help (I can provide a space and you can link them in-line in a post here or in a thread).
Hall Of Worlds, LLC
EdM|EGTGE
04/14/2005 (11:49 am)
@Dreamer - This series looks great so far and I'm looking forward to seeing a continuation of your work (the remaining resources). I haven't had the time to actually try this out yet (I'm sure I'm not alone), but when I do I'll come back and rate. Regardless, thanks for this. Its always cool to see community members sharing good stuff like this. This really gets me thinking of a currently on the shelf game idea again....Regarding my comment in another of your resources, getting all of the most recent 'code snippet' entries is kind of a notoriety thing. I did mean it as a compliment, but I shouldn't have just posted that without a comment on the resource itself. :|
Again, I'm looking foward to strapping this code in and trying it out. One note. If you've got a web-site (even if you say your art is sub-par), I'm sure folks would love to see some screens to go with your posts. If you don't have a site and want to post some screens I'm sure someone (myself included) would be willing to help (I can provide a space and you can link them in-line in a post here or in a thread).
Hall Of Worlds, LLCEdM|EGTGE
#3
Same here. Big thank you from me (and propably most of the cummunity) to share this.
04/14/2005 (11:59 am)
Quote:@Dreamer - This series looks great so far and I'm looking forward to seeing a continuation of your work (the remaining resources). I haven't had the time to actually try this out yet (I'm sure I'm not alone), but when I do I'll come back and rate.
Same here. Big thank you from me (and propably most of the cummunity) to share this.
#4
@Edward, At the moment I haven't any screenshots of these resources in action, because MOST of this code comes from my personal changelog, and I am really pretty far ahead of where these beginning tutorials are at, ergo my screenshots wouldn't reflect what the current code in fact does (wish I would've taken pictures back then, but oh well).
@Dirk, you are most welcome, I'm glad to help!
@Everyone...
Next Tutorial!
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=7605
04/14/2005 (1:17 pm)
My thanks to you all for your kind words.@Edward, At the moment I haven't any screenshots of these resources in action, because MOST of this code comes from my personal changelog, and I am really pretty far ahead of where these beginning tutorials are at, ergo my screenshots wouldn't reflect what the current code in fact does (wish I would've taken pictures back then, but oh well).
@Dirk, you are most welcome, I'm glad to help!
@Everyone...
Next Tutorial!
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=7605
#5
@All - Link below is to fish and fishpole model Dreamer mentioned in earlier installment of this multi-part resource.

Hall Of Worlds, LLC
EdM|EGTGE
04/14/2005 (9:09 pm)
@Dreamer - Here is a link to the resources you sent. @All - Link below is to fish and fishpole model Dreamer mentioned in earlier installment of this multi-part resource.

Hall Of Worlds, LLCEdM|EGTGE
#6
04/14/2005 (11:11 pm)
Thanx for hosting it Edward! Nice Pic BTW
#7
i am getting a error once i kill say a fish wish a spell
Client energy is 14.592
Casting Complete!
starter.fps/server/scripts/player.cs (814): Unable to find object: '' attempting to call function 'onDeath'
Casting Spell!
melee redux worked fine that i can see hard to hit just a fish
but onto this one spell worked fine took em awhile forgot to clear out config.cs and config.cs.dso before i could cast /bonk my fault. now just this on death i target with cursor use C it casts the spell and fish dies but get that little error
line 813-815 is as followed
if (%obj.getState() $= "Dead")
%client.onDeath(%sourceObject, %sourceClient, %damageType, %location);
}
05/04/2005 (4:28 pm)
welp got thru this one..... almost LOLi am getting a error once i kill say a fish wish a spell
Client energy is 14.592
Casting Complete!
starter.fps/server/scripts/player.cs (814): Unable to find object: '' attempting to call function 'onDeath'
Casting Spell!
melee redux worked fine that i can see hard to hit just a fish
but onto this one spell worked fine took em awhile forgot to clear out config.cs and config.cs.dso before i could cast /bonk my fault. now just this on death i target with cursor use C it casts the spell and fish dies but get that little error
line 813-815 is as followed
if (%obj.getState() $= "Dead")
%client.onDeath(%sourceObject, %sourceClient, %damageType, %location);
}
#8
05/04/2005 (8:12 pm)
I wouldn't worry too much, what's happening is that the fish is being removed from the game prior to that function being called, you can fix it with an isObject command like this...if(isObject(%obj)){
if(%obj.getState() $= "Dead")
%client.onDeath(%sourceObject,%sourceClient,%damageType,%location);
}
#9
(At least, for me I had to change it to that to cause the spell to only be cast once)
Robert
05/08/2005 (7:15 pm)
For you CastSpell keybind, you may want it to be function CastSpell(%val)
{
if(%val)
CommandToServer('CastSpell',"Bolt");
} so the spell is not cast when the key is pressed and when the key is released, unless of course, that was your intention, :).(At least, for me I had to change it to that to cause the spell to only be cast once)
Robert
#10
Casting Spell!
Spell was Bolt!
starter.fps/server/scripts/commands.cs (308): Unable to find object: '0' attempting to call function 'getTransform'
Client energy is 21.504
Casting Complete!
Hopefully something small I'm overlooking here, any help is appretiated,
-steve
p.s. i'm not sure if i was supposed to but i added the exec for the DDspell.cs to Game.cs
05/31/2005 (8:44 pm)
Hi everyone, I've just spent some time trying to add this to my project and I think I've just about got it in, I've created the DDspell.cs, modified commands.cs and made my keybind, I have completed the Inventory tutorial and the mmorpg targeting tutorial but skipped the two fish and melee combat for now as it doesnt really fit my game style. Anyways i'm getting the follow error in my log when i attempt to cast, first i tried just casting at nothing, then using the mmorpg style targeting, targeted my guard1..Casting Spell!
Spell was Bolt!
starter.fps/server/scripts/commands.cs (308): Unable to find object: '0' attempting to call function 'getTransform'
Client energy is 21.504
Casting Complete!
Hopefully something small I'm overlooking here, any help is appretiated,
-steve
p.s. i'm not sure if i was supposed to but i added the exec for the DDspell.cs to Game.cs
#11
05/31/2005 (8:56 pm)
Look up higher in your log, something didn't compile properly. Most likely a broken linebreak somewhere.
#12
thank you for your help,
-steve
05/31/2005 (9:26 pm)
hmm well i'm not exactlly sure what did the trick, i did some poking around and i can cast now but i'm still getting a slight error if i dont have something targeted using the mmorpg targeting system, is there a better way for me to handle this error and display it to the user? thank you for your help,
-steve
#13
06/01/2005 (6:29 am)
Actually you should code this to reject the spell cast if there is no target, then you won't get an error, maybe in the rejection code put something like a MessageClient, and put something in the message that says they need to have a target first.
#14
thank you thank you thank you ( can't say it enough :P)
-steve
06/01/2005 (6:43 am)
thanks dreamer, that deffinatelly points me in the right direction, it may take me some time (i'm just learning C++ now but am fairly comfortable with some scripting from games i've worked on in the past) but as soon as i get this little extra figured out I will post it up here.thank you thank you thank you ( can't say it enough :P)
-steve
#15
06/08/2005 (5:55 pm)
Um in the commands.cs section, isn't the code repeated? (ie double-paste)
#16
06/08/2005 (7:12 pm)
LOL, I can't believe I did that, it's just a typo... I'll get it fixed soon. Thanx for the heads up.
#17
06/09/2005 (3:54 pm)
Ok fixed it!
#18
Are you using the lighting pack by Synapse by any chance because I have been having frequent tiny struggles with the previous tutorials but ended up working them out. In this tuotorial on the other hand when I press "c" to cast the spell i get a fatal error telling me "Out of bounds Value!" Im not sure what this means but it seems pretty big. It casts or doesnt do anything if I dont have a target selected and only does this when I have my fish or kork selected. I also had some trouble with making contact with the previous tut. I must be doing something wrong in the previous tut. Its late and I'm tired I will give it a rest and see what I can do tomorrow.
This is the error that I get from the console log
Then it just cuts out from there...I guess I will get up to this point on TGE without the lighting pack to see if this is the case. If anyone has got this far with the lighting pack please let me know so that I can finsd a way to fix it.
06/21/2005 (11:26 pm)
I have a question...Are you using the lighting pack by Synapse by any chance because I have been having frequent tiny struggles with the previous tutorials but ended up working them out. In this tuotorial on the other hand when I press "c" to cast the spell i get a fatal error telling me "Out of bounds Value!" Im not sure what this means but it seems pretty big. It casts or doesnt do anything if I dont have a target selected and only does this when I have my fish or kork selected. I also had some trouble with making contact with the previous tut. I must be doing something wrong in the previous tut. Its late and I'm tired I will give it a rest and see what I can do tomorrow.
This is the error that I get from the console log
Quote:Client has selected 1521 212.219 338.032 243.177 0.648569 -0.615099 -0.448344
Mapping string: UpdateTargetDialog to index: 15
Mapping string: NewTarget to index: 16
Recieved command to open TargetGUI command was NewTarget and TargetName is Fish
Mapping string: use to index: 5
Mapping string: CastSpell to index: 6
Casting Spell!
Spell was Bolt!
Client energy is 50
Casting Complete!
Fatal: (c:\documents and settings\owner\desktop\gamelight\engine\core\bitstream.h @ 170) Out of bounds value!
Then it just cuts out from there...I guess I will get up to this point on TGE without the lighting pack to see if this is the case. If anyone has got this far with the lighting pack please let me know so that I can finsd a way to fix it.
#19
An out of bounds value, means you are cramming too much down the pipe at one time, there is an article somewhere that shows how to deal with them (it's a change to a couple of lines of code), and I did implement it quite awhile ago, so maybe thats the difference.
Do a site search for "Out of Bounds"
Hope that helps.
06/22/2005 (6:13 pm)
Nope, it's based on a clean build... Strangely enough, I can't get this error to reproduce :(An out of bounds value, means you are cramming too much down the pipe at one time, there is an article somewhere that shows how to deal with them (it's a change to a couple of lines of code), and I did implement it quite awhile ago, so maybe thats the difference.
Do a site search for "Out of Bounds"
Hope that helps.
#20
06/22/2005 (8:16 pm)
Hmm i did a search but nothing came up that was relevent... There was one about particle emitters but when i used that fix it still happened. This is the forum entry www.garagegames.com/mg/forums/result.thread.php?qt=20447 I wonder if anyone else is having this problem cause I hate it when I'm the only one. Im going to test this on my other comp to see if its a problem with my setup. Thank you for your help.
Torque Owner Dreamer
Default Studio Name
http://www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=7514