Il 0% ha trovato utile questo documento (0 voti)
2 visualizzazioni3 pagine

Coding Beretta

Coding berretta

Caricato da

BMMZ
Copyright
© All Rights Reserved
Per noi i diritti sui contenuti sono una cosa seria. Se sospetti che questo contenuto sia tuo, rivendicalo qui.
Formati disponibili
Scarica in formato TXT, PDF, TXT o leggi online su Scribd
Il 0% ha trovato utile questo documento (0 voti)
2 visualizzazioni3 pagine

Coding Beretta

Coding berretta

Caricato da

BMMZ
Copyright
© All Rights Reserved
Per noi i diritti sui contenuti sono una cosa seria. Se sospetti che questo contenuto sia tuo, rivendicalo qui.
Formati disponibili
Scarica in formato TXT, PDF, TXT o leggi online su Scribd

#include "cbase.

h"
#include "basehlcombatweapon_shared.h"
#include "explode.h"

// memdbgon must be the last include file in a .cpp file!!!


#include "tier0/memdbgon.h"

class CWeapon_RDB : public CBaseHLCombatWeapon


{
DECLARE_DATADESC();

public:
DECLARE_CLASS(CWeapon_RDB, CBaseHLCombatWeapon);
DECLARE_SERVERCLASS();

void Spawn() override;


void PrimaryAttack() override;
void PlaceRDB();
void TestDetonate(); // Added for testing
void ExplodeRDB();

private:
bool rdbPlaced = false; // To check if RDB is placed
float rdbTimerDuration = 3.0f; // Timer set to 3 seconds

bool IsPlayerInRDBArea(Vector playerPos);


};

IMPLEMENT_SERVERCLASS_ST(CWeapon_RDB, DT_Weapon_RDB)
END_SEND_TABLE()
// Link the class to the entity name
LINK_ENTITY_TO_CLASS(weapon_rdb, CWeapon_RDB);
PRECACHE_WEAPON_REGISTER(weapon_rdb);

// Data description block


BEGIN_DATADESC(CWeapon_RDB)
DEFINE_THINKFUNC(TestDetonate), // Link the test function
END_DATADESC()

void CWeapon_RDB::Spawn()
{
BaseClass::Spawn();
rdbPlaced = false;
}

void CWeapon_RDB::PrimaryAttack()
{
PlaceRDB();
}

bool CWeapon_RDB::IsPlayerInRDBArea(Vector playerPos)


{
Vector allowedAreaMin(0, 0, 0); // Define your restricted area bounds
Vector allowedAreaMax(1000, 1000, 1000);

return (playerPos.x > allowedAreaMin.x && playerPos.x < allowedAreaMax.x &&


playerPos.y > allowedAreaMin.y && playerPos.y < allowedAreaMax.y &&
playerPos.z > allowedAreaMin.z && playerPos.z < allowedAreaMax.z);
}
void CWeapon_RDB::PlaceRDB()
{
CBasePlayer *pPlayer = ToBasePlayer(GetOwner());

//if (pPlayer && IsPlayerInRDBArea(pPlayer->GetAbsOrigin()))


//{
if (rdbPlaced == false)
{
trace_t tr;

// Create Vector for direction


Vector vecDir;

// Take the Player's EyeAngles and turn it into a direction


AngleVectors(pPlayer->EyeAngles(), &vecDir);

// Get the Start/End


Vector vecAbsStart = pPlayer->EyePosition();
Vector vecAbsEnd = vecAbsStart + (vecDir * MAX_TRACE_LENGTH);

UTIL_TraceLine(vecAbsStart, vecAbsEnd, MASK_SOLID, pPlayer,


COLLISION_GROUP_NONE, &tr);

//debug
UTIL_AddDebugLine(vecAbsStart, vecAbsEnd, true, true);

if ([Link] < 1.0)


{
Vector hitPos = [Link];
QAngle hitAngles;
VectorAngles([Link], hitAngles);

CBaseEntity *pRDB = CreateEntityByName("remote_detonating_bomb");


if (pRDB)
{
pRDB->SetAbsOrigin(hitPos);
pRDB->SetAbsAngles(hitAngles);
pRDB->SetMoveType(MOVETYPE_NONE); // Stick to the surface
pRDB->Spawn();

rdbPlaced = true;
ClientPrint(pPlayer, HUD_PRINTCENTER, "RDB placed and will
detonate in 3 seconds.");

// Directly call the detonation function after 3 seconds


for testing
SetNextThink(gpGlobals->curtime + rdbTimerDuration); //
Set to 3 seconds
SetThink(&CWeapon_RDB::TestDetonate);
}
}
else
{
ClientPrint(pPlayer, HUD_PRINTCENTER, "No valid surface to place
the RDB.");
}
}
//}
//else
//{
//ClientPrint(pPlayer, HUD_PRINTCENTER, "You cannot place the RDB
here.");
//}
}

void CWeapon_RDB::TestDetonate()
{
if (rdbPlaced) // Ensure the bomb was placed before detonation
{
ExplodeRDB();
rdbPlaced = false; // Reset placed status
ClientPrint(ToBasePlayer(GetOwner()), HUD_PRINTCENTER, "RDB detonated
by test override.");
}
}

void CWeapon_RDB::ExplodeRDB()
{
Vector vecRDBOrigin = GetAbsOrigin();
ExplosionCreate(vecRDBOrigin, GetAbsAngles(), GetOwnerEntity(), 100, 200,
SF_ENVEXPLOSION_NODAMAGE, true);

// Clean up the RDB entity after explosion if needed


UTIL_Remove(this); // This assumes the RDB is the weapon itself; adjust if
needed
}

Potrebbero piacerti anche