Need help Implementing 'Spells' into my Mod

Grab your favourite IDE and tinker with the innards of game engines

Need help Implementing 'Spells' into my Mod

Postby NZNobody on Mon Nov 21, 2011 3:30 am

Hey,
So basically I'm working on a mod for HL2 based of the WC3 map: Warlocks. I have managed to get clamped above you camera and free the mouse so that you always face where it is but now is the important part: clicking to cast spells.
First off: I'm a noob source coder and stumbled accross most I achieved so please take that into account!
Secondly: I have implemented a "Spell_Manager" as a entity and every player gets one, it manages (this allready works!) which spell is currently selected, cool downs, and the stats of spells (eg dammage, speed .... and so on). This spell manager is what actually 'casts' the spell by calling the function of the spell entities which I created:

Code: Select all
//This function actually fires the spells!
void CSpell_Manager::CastSpell(int iSpell, Vector vecOrigin, QAngle angAiming, CBasePlayer *pOwner )
{
   //BAM!
   switch(iSpell)
   {
   case FIREBALL :
      {
         CSpell_Fireball *pSpell = CSpell_Fireball::CreateSpell(&m_spFireball, vecOrigin, angAiming, pOwner);
         m_fCoolDown1=BASE_COOLDOWN_FIREBALL;

      }
      break;
   case TRACKER :
      {
         CSpell_Tracker *pSpell = CSpell_Tracker::CreateSpell(&m_spTracker, vecOrigin, angAiming, pOwner);
         m_fCoolDown2=BASE_COOLDOWN_TRACKER;
      }
      break;
   case LIGHTNING :
      {
         CSpell_Lightning *pSpell = CSpell_Lightning::CreateSpell(&m_spLightning, vecOrigin, angAiming, pOwner);
         m_fCoolDown2=BASE_COOLDOWN_TRACKER;
      }
      break;
   }
}


The CreateSpell function looks like this:
Code: Select all
//-----------------------------------------------------------------------------
// Purpose: Called to actually create a Spell
//-----------------------------------------------------------------------------
CSpell_Fireball *CSpell_Fireball::CreateSpell( CSpell_Fireball *spFireball, const Vector &vecOrigin, const QAngle &angAngles, CBasePlayer *pentOwner)
{
   //Calculations!
   Vector vecSpawn = vecOrigin;
   vecSpawn.z=64;               // Force it to spawn at a height of 64
   Vector vecAbsVel = Vector(0,0,0); // Declare a vector to be used
   AngleVectors(angAngles, &vecAbsVel); // Hopefully create a vector out of the angle
   vecAbsVel *=spFireball->m_flSpeed;; // Hopefully make this vecVel actually the velocity
   // Initialise values and spawn spell + effects
   CSpell_Fireball *pSpell = (CSpell_Fireball *)CreateEntityByName( "cspell_fireball" ); //Create the entity
   UTIL_SetOrigin( pSpell, vecSpawn ); // place the entity at origin
   pSpell->SetAbsAngles( angAngles ); // make it face the way it should
   pSpell->SetAbsVelocity(vecAbsVel); // make it move toward where it should
   pSpell->Spawn(); // actually give it a model and so on so forth
   pSpell->m_flSpeed=spFireball->m_flSpeed;
   pSpell->m_flDuration=spFireball->m_flDuration;      // Copy given values
   pSpell->m_flDamage=spFireball->m_flDamage;
   pSpell->m_plOwner=pentOwner;
   pSpell->SetOwnerEntity( pentOwner ); // Who created this magical fireball?
   DispatchParticleEffect( ENTITY_EFFECT,PATTACH_ABSORIGIN_FOLLOW,pSpell,-1,false);
   return pSpell;
}


Now that you have seen how my spells currently work I have to ask my important question:
Is this the correct way of doing it? Do I need to base my spells off 'CBaseAnimating' entities to be able to detect when they collide and so forth? The reason I ask is because I do not know how to then effeciently attach the spells particle effects to this entity? With my current system the effects are connected, but not fully; for example they don't despawn when the spell entity does.
Basically: Can I do this better by not having my spells which will always be pure particle effects based of animated models?

Thanks,
NZNobody
NZNobody
Member
Member
 
Joined: Wed Jul 06, 2011 11:25 am

Re: Need help Implementing 'Spells' into my Mod

Postby NZNobody on Mon Nov 21, 2011 8:35 am

In addition to the above: I need help with the TakeDamage() function to make my spells deal damage. Its not really working correctly due to (I'm assuming this) me not setting up the CDamageTypeInfo class up correctly.
NZNobody
Member
Member
 
Joined: Wed Jul 06, 2011 11:25 am

Re: Need help Implementing 'Spells' into my Mod

Postby zombie@computer on Mon Nov 21, 2011 9:33 am

look at how rockets and grenades work.
Your system looks okay at first glance but personally i think it would have been easier to simply use the same setup rockets and grenades have (i.e. weapon spawns a rocket or grenade entity, gives it a certain velocity and angle and the game does the rest).
When you are up to your neck in shit, keep your head up high
zombie@computer
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Fri Dec 31, 2004 5:58 pm
Location: Lent, Netherlands

Re: Need help Implementing 'Spells' into my Mod

Postby NZNobody on Mon Nov 21, 2011 9:52 am

Thanks for your feedback Zombie. The reason I wanted to create my own class and system was for expansion purposes. For example I implemented a spell that 'tracks' enemies and follows them. Also there will be spells that suck all entities around itself inwards. Also spells down't obey the laws of physics always.
On another note: I managed to get damage working (was an issue that the damage was being disregarded because the function checked to make sure the inflicter was on a different team, and logically I didn't give my spells 'teams').
NZNobody
Member
Member
 
Joined: Wed Jul 06, 2011 11:25 am

Re: Need help Implementing 'Spells' into my Mod

Postby ChromeAngel on Wed Nov 23, 2011 8:18 am

I agree with Z@C, you would have been better off starting with the weapon system that's already built and making your spells as CBaseCombatWeapon's (this class handles damage, Rate of fire (cooldown time), mana(ammo) consumption and lets you script them for easier tuning) and the projectiles they create based on CBaseGrenade.
User avatar
ChromeAngel
Member
Member
 
Joined: Fri Oct 21, 2011 7:28 am
Location: England

Re: Need help Implementing 'Spells' into my Mod

Postby NZNobody on Wed Nov 23, 2011 10:37 am

Thanks again for your feedback. After a discussion with a main dev from HL2 Wars I have decided to attempt to port my mod to Alien Swarm code for a number of reasons including the already set up camera work. Taking this into account I probably will follow the advice both of you posted here so thanks!
BUT once again with projectiles: how to tie effects to them efficiently? Can i just shoot particle systems? Or must they be attached to a CBaseAnimating (tried to not give it a model, but then the particles don't appear). It would be good to just shoot the effects TBH
NZNobody
Member
Member
 
Joined: Wed Jul 06, 2011 11:25 am

Re: Need help Implementing 'Spells' into my Mod

Postby zombie@computer on Wed Nov 23, 2011 12:04 pm

no you can simply spawn the particles and make them follow the grenade or rocket's origin: https://developer.valvesoftware.com/wik ... es_In_Code

You dont want to just shoot the particle effects because you will lose all those nifty functions entities have for collision detection, prediction, networking etc. Sure, you can reimplement, but what is the gain (apart from being able to up the limit of spells you can spawn in your map)?

If you look at the grenade's or rockets code you should be able to easily figure out how to do

1) follow the entity (rockets follow the laser guide, so its similar)
2) enable physics (eg throwing a magic ball). Grenades AND rockets follow physics, and its basically as simple as giving a direction, mass, friction and momentum. Or you can disable physics by giving em mass=0.
3) direct shots are similar to rockets without laser guide...
When you are up to your neck in shit, keep your head up high
zombie@computer
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Fri Dec 31, 2004 5:58 pm
Location: Lent, Netherlands

Return to Programming

Who is online

Users browsing this forum: No registered users

cron