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