Skip to content

Commit

Permalink
[FIXME!!!] FIREFIGHT: respawn monsters named "FIREFIGHT" when killed
Browse files Browse the repository at this point in the history
  • Loading branch information
sabianroberts committed Oct 29, 2024
1 parent f0fd42d commit 8aae74e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
38 changes: 36 additions & 2 deletions binary/dlls/agfirefight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
#include "cbase.h"
#include "player.h"
#include "weapons.h"
#include "gamerules.h"

#include "aggamerules.h"
#include "agglobal.h"
//#include "agarena.h"
#include "agfirefight.h"

#include "algo.h"
Expand All @@ -35,7 +33,43 @@ AgFirefight::~AgFirefight()

}

void AgFirefight::InitMonsters()
{
edict_t* pEdict = FIND_ENTITY_BY_STRING(nullptr, "targetname", "FIREFIGHT");
while (!FNullEnt(pEdict))
{
RespawnInfo respawnInfo;
respawnInfo.edict = pEdict;
respawnInfo.spawnPosition = pEdict->v.origin; // Store original position
respawnInfo.respawnTime = 0.0f; // Initialize respawn time to 0

m_respawnQueue.push_back(respawnInfo);
pEdict = FIND_ENTITY_BY_STRING(pEdict, "targetname", "FIREFIGHT");
}
}

void AgFirefight::Think()
{
float currentTime = gpGlobals->time;

for (auto& respawnInfo : m_respawnQueue) {
if (respawnInfo.respawnTime > 0.0f && respawnInfo.respawnTime <= currentTime) {
// Respawn the monster
CBaseEntity* pNewMonster = CBaseEntity::Instance(g_engfuncs.pfnCreateNamedEntity(MAKE_STRING("monster_name")));
if (pNewMonster) {
pNewMonster->pev->origin = respawnInfo.spawnPosition; // Set the spawn position
pNewMonster->Spawn(); // Spawn the new monster

// Reset the respawn timer
respawnInfo.respawnTime = 0.0f;
}
}

// Check if the monster is dead
if (respawnInfo.edict->free) {
respawnInfo.respawnTime = currentTime + 5.0f; // Set respawn time after 5 seconds
}
}

CGameRules::Think();
}
16 changes: 15 additions & 1 deletion binary/dlls/agfirefight.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,34 @@
*
****/

#include "aggamerules.h"
#include <vector>

#ifndef FIREFIGHT_H
#define FIREFIGHT_H

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER

class AgFirefight
class AgFirefight : public CGameRules
{
public:
AgFirefight();
virtual ~AgFirefight();

void Think();
void InitMonsters();

private:
struct RespawnInfo
{
edict_t* edict;
vec3_t spawnPosition;
float respawnTime;
};

std::vector<RespawnInfo> m_respawnQueue;
};

#endif // FIREFIGHT_H

0 comments on commit 8aae74e

Please sign in to comment.