Wayback Machine
JAN MAY Jun
Previous capture 5 Next capture
2004 2006 2007
16 captures
12 Aug 02 - 5 May 06
sparklines
Close Help

# menu
 
http://www.planethalflife.com/hlprogramming > tutorials > database 

news
 
current
 
submit

tutorials
 
database
  -
mp
  -
client
 
submit
 
search

forum
 
main

contact
 
email

Shields
Created by sh4D0w c0nSum3s



HalfLife's Code is BLUE
sh4D0w c0nSum3s's Code is RED
sh4D0w c0nSum3s's Commentary is GREEN


FIRST OFF:
You !_WILL_! give me credit if you use this source. in fact why don''t you just email me the link to your mod to let me know you''re using it. if you don''t plan on accrediting the original author then buzz off. and yes this is _ORIGINAL_ hand written source.

This is from my former now dead mod so i figured i would contribute it to the community so i can regain my status among you people.


just drop this in bmodels.cpp about line 83. it should be below the func_wall function.

also be sure to include player.h in the header definitions of bmodels.cpp





//========================================
//Shields - shadow
//========================================

#define KICK_BACK_SPEED 1000;
//this is used to define how hard the shield kicks the player back

class CFuncShield : public CFuncWall
{
public:
void Spawn( void );
void Touch( CBaseEntity *pEntity );

float pushSpeed; //amount of force to apply against player
};

LINK_ENTITY_TO_CLASS( func_shield, CFuncShield );

void CFuncShield::Spawn( void )
{
//make me solid
pev->angles = g_vecZero;
pev->movetype = MOVETYPE_NONE;
pev->solid = SOLID_BBOX;

//but don''t draw me just yet
pev->effects |= EF_NODRAW;

SET_MODEL( ENT( pev ), STRING( pev->model ) );

//set up flags
pev->flags |= FL_WORLDBRUSH;

PRECACHE_SOUND( "doors/aliendoor1.wav" );

//and set up my touch function
SetTouch( Touch );
}

void CFuncShield::Touch( CBaseEntity *pEntity )
{
//get the push speed variable
pushSpeed = CVAR_GET_FLOAT("shieldstrength");

the shieldstrength variable is in the .fgd file
which you will need to add to your own for it to work. it allows the mapper to set the shield force.


if( pEntity->IsPlayer() )
{
//THE THING THAT HIT ME IS A PLAYER
if( pushSpeed < 2000 )
{
//THE SPEED IS UNDER 2000 SO PUSH THEM BACK BY pushSpeed amount
pEntity->pev->velocity = -pEntity->pev->velocity * pushSpeed;
}
else
{
//OTHERWISE THE SPEED IS TOO HIGH SO DO IT BY 500
pEntity->pev->velocity = -pEntity->pev->velocity * KICK_BACK_SPEED;
}

}
//PLAY WEIRD SOUND
EMIT_SOUND(ENT(pev), CHAN_STATIC, "doors/aliendoor1.wav", 1.0, ATTN_NORM);

//make it visible
pev->effects &= ~EF_NODRAW;

//but still see through
pev->rendermode = kRenderTransTexture;
pev->renderamt = 40;
pev->renderfx = kRenderFxGlowShell;

}

//=============== END SHIELDS ====================
//==================================================


GAME.CPP

drop this into game.cpp about line 48

//Shield strength CVAR
cvar_t shieldstrength={"mp_shieldstrength","0", FCVAR_SERVER };


then go to line about 492 in the same file and add


//Shield strength CVAR
CVAR_REGISTER (&shieldstrength);


now just be sure to add this line into your .FGD file for the mapper.


@SolidClass base(func_wall) = func_shield : "Func Shield"
[
shieldstrength(integer) : "Shield Strength" : 600
]


basically what it does it the mapper makes a brush with the appropriate texture (one that looks like shields). when the player hits the shields it plays that sound and makes the brush visible. there is a server variable called sv_shieldstrength so the server can modify how hard the shield pushes.