Thanks so much! Don't worry. We have our fair share of ugly code as well. The Source SDK is so undocumented there's like 1000 ways to do something but only one or two that are the 'correct' way. It took us like 3 or 4 rewrites to the grapple phone alone to get it to function the same way as the original Nightfire. All the tutorials on the net, and examples we found either didn't work, or didn't function how we wanted it.
Lol, here's a crap snippet of code from the RC helicopter code. Had major issues trying to get entities to render out of the current PVS, so i ended up writing this convoluted crap to attach the player to the heli and make him invisible and invulnerable when firing.
if ( cmd->buttons & IN_ATTACK && time - lasttime_leftclicked > RandomFloat(0.1, 0.125) ){
m_bRecoil = true;
Vector savedplayerorigin = pPlayer->GetAbsOrigin();
pPlayer->AddEffects(EF_NODRAW);
MoveType_t savedmovetype = pPlayer->GetMoveType();
pPlayer->SetMoveType(MOVETYPE_NOCLIP);
int savedtakedamage = pPlayer->m_takedamage;
pPlayer->m_takedamage = DAMAGE_NO;
SolidType_t savedsolidtype = pPlayer->GetSolid();
pPlayer->SetSolid(SOLID_NONE);
lasttime_leftclicked = time;
Vector origin = GetLocalOrigin();
origin.z -= 2;
//Take the Player's EyeAngles and turn it into a direction
Vector vecDir;
AngleVectors( GetLocalAngles(), &vecDir );
//todo: fix spread, it's not shown on client correctly
//float spreadx = RandomFloat(-0.05, 0.05);
//float spready = RandomFloat(-0.05, 0.05);
pPlayer->FireBullets(1, origin, vecDir, Vector(0, 0, 0), 4096, GetAmmoDef()->Index( "minigun" ), 4, -1, -1, 20, pPlayer->GetBaseEntity(), false, true);
CBroadcastRecipientFilter broadcast;
EmitSound(broadcast, entindex(), PHELICOPTER_GUNSOUND, &origin, 0, 0);
Vector vecAbsEnd = origin + (vecDir * MAX_TRACE_LENGTH);
trace_t tr;
//Do the TraceLine, and write our results to our trace_t class, tr.
pPlayer->FollowEntity(this);
UTIL_TraceLine( origin, vecAbsEnd, MASK_SOLID, pPlayer, COLLISION_GROUP_NONE, &tr );
UTIL_Tracer( (Vector&)origin, (Vector&)tr.endpos, entindex(), 1, 6000, true, "GaussTracer" );
pPlayer->StopFollowingEntity();
pPlayer->SetAbsOrigin(savedplayerorigin);
pPlayer->RemoveEffects(EF_NODRAW);
pPlayer->SetMoveType(savedmovetype);
pPlayer->SetSolid(savedsolidtype);
pPlayer->m_takedamage = savedtakedamage;
}
if ( cmd->buttons & IN_ATTACK2 && time - lasttime_rightclicked > 3 ){
m_bShake = true;
Vector savedplayerorigin = pPlayer->GetAbsOrigin();
pPlayer->AddEffects(EF_NODRAW);
MoveType_t savedmovetype = pPlayer->GetMoveType();
pPlayer->SetMoveType(MOVETYPE_NOCLIP);
int savedtakedamage = pPlayer->m_takedamage;
pPlayer->m_takedamage = DAMAGE_NO;
SolidType_t savedsolidtype = pPlayer->GetSolid();
pPlayer->SetSolid(SOLID_NONE);
lasttime_rightclicked = time;
Vector origin = GetLocalOrigin();
origin.z -= 2;
//Take the Player's EyeAngles and turn it into a direction
Vector vecDir;
AngleVectors( GetLocalAngles(), &vecDir );
CBroadcastRecipientFilter broadcast;
EmitSound(broadcast, entindex(), PHELICOPTER_ROCKETSOUND, &origin, 0, 0);
CMissile *pMissile = CMissile::Create( origin, GetLocalAngles(), this->edict() ); //CRASH
if(!pMissile)
return;
pMissile->SetGravity(0.1);
pMissile->SetMoveType(MOVETYPE_FLYGRAVITY);
pMissile->SetImpactEnergyScale(0.5f);
pMissile->SetOwnerEntity(pPlayer);
pMissile->SetAbsVelocity(vecDir * 600);
pMissile->SetDamage( 80 );
pPlayer->StopFollowingEntity();
pPlayer->SetAbsOrigin(savedplayerorigin);
pPlayer->RemoveEffects(EF_NODRAW);
pPlayer->SetMoveType(savedmovetype);
pPlayer->SetSolid(savedsolidtype);
pPlayer->m_takedamage = savedtakedamage;
}