Delay the renaming of CTF entity classnames to after they have fully spawned.
Fix bot spawning a little.
This commit is contained in:
parent
30f372c060
commit
5aa4b76644
3 changed files with 59 additions and 25 deletions
|
@ -14,6 +14,11 @@
|
|||
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
void CSEv_TeamJoin_f(float teamChoice);
|
||||
void CSEv_ClassJoin_f(float classSelection);
|
||||
void CSEv_JoinAuto(void);
|
||||
|
||||
void
|
||||
OP4CTFRules::OP4CTFRules(void)
|
||||
{
|
||||
|
@ -26,8 +31,11 @@ OP4CTFRules::InitPostEnts(void)
|
|||
forceinfokey(world, "teams", "2");
|
||||
forceinfokey(world, "team_1", "Black Mesa");
|
||||
forceinfokey(world, "teamscore_1", "0");
|
||||
forceinfokey(world, "teamcolor_1", "1 1 0");
|
||||
forceinfokey(world, "team_2", "Opposing Force");
|
||||
forceinfokey(world, "teamscore_2", "0");
|
||||
forceinfokey(world, "teamcolor_2", "0 1 0");
|
||||
|
||||
|
||||
forceinfokey(world, "ctfflag_1", "0");
|
||||
forceinfokey(world, "ctfflag_2", "0");
|
||||
|
@ -49,6 +57,10 @@ OP4CTFRules::PlayerConnect(NSClientPlayer pp)
|
|||
forceinfokey(pp, "*score", "0");
|
||||
forceinfokey(pp, "*icon1", "");
|
||||
forceinfokey(pp, "*icon2", "");
|
||||
|
||||
if (clienttype(pp) == CLIENTTYPE_BOT) {
|
||||
pp.ScheduleThink(CSEv_JoinAuto, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -85,22 +97,9 @@ void CSEv_ClassJoin_f(float);
|
|||
bool
|
||||
OP4CTFRules::ConsoleCommand(NSClientPlayer pp, string cmd)
|
||||
{
|
||||
static void OP4CTFRules_BotJoin(void) {
|
||||
float tag = (random() < 0.5) ? 1 : 2;
|
||||
CSEv_TeamJoin_f(tag);
|
||||
CSEv_ClassJoin_f(tag == 1 ? 0 : 13);
|
||||
}
|
||||
|
||||
tokenize(cmd);
|
||||
|
||||
switch (argv(0)) {
|
||||
case "bot_add":
|
||||
entity bot_ent = Bot_AddQuick();
|
||||
if (bot_ent) {
|
||||
bot_ent.think = OP4CTFRules_BotJoin;
|
||||
bot_ent.nextthink = time;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return (false);
|
||||
}
|
||||
|
@ -134,6 +133,12 @@ OP4CTFRules::CharacterSpawn(NSClientPlayer playerEnt, string playerModel)
|
|||
pl.glock_mag = 18;
|
||||
pl.ammo_9mm = 44;
|
||||
|
||||
/* Just-In-Case (tm) */
|
||||
pl.g_items &= ~ITEM_GOALITEM;
|
||||
pl.flags &= ~FL_GOALITEM;
|
||||
pl.flagmodel = 0;
|
||||
pl.SetInfoKey("*icon1", "");
|
||||
|
||||
entity spot = Spawn_SelectRandom(strcat("info_ctfspawn_", ftos(pl.team)));
|
||||
pl.Transport(spot.origin, spot.angles);
|
||||
Weapons_RefreshAmmo(pl);
|
||||
|
@ -172,7 +177,7 @@ OP4CTFRules::CaptureFlag(NSClientPlayer pp)
|
|||
enemyFlag = (NSEntity)find(world, ::classname, flagName);
|
||||
|
||||
if (!enemyFlag) {
|
||||
error("What the hell? There's no flag back there!");
|
||||
NSError("The flag spawnpoint cannot be found.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -209,7 +214,7 @@ OP4CTFRules::DropFlag(NSClientPlayer pp)
|
|||
|
||||
/* item is still pick-upable */
|
||||
if (targetFlag.GetSolid() != SOLID_NOT) {
|
||||
print("the item is not picked up. \n");
|
||||
NSLog("the item is not picked up.");
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -220,7 +225,7 @@ OP4CTFRules::DropFlag(NSClientPlayer pp)
|
|||
}
|
||||
}
|
||||
|
||||
print("^1WARNING: ^7Player marked as having impossible goal-item\n");
|
||||
NSWarning("Player marked as having impossible goal-item.");
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -292,7 +297,7 @@ CSEv_ClassJoin_f(float classSelection)
|
|||
}
|
||||
|
||||
if (playerModel == "") {
|
||||
error("invalid model selection, erroring out");
|
||||
NSError("invalid model selection, erroring out");
|
||||
}
|
||||
|
||||
/* if we're alive, kill them (we need to drop the flag anyhow */
|
||||
|
@ -302,4 +307,12 @@ CSEv_ClassJoin_f(float classSelection)
|
|||
} else {
|
||||
rule.CharacterSpawn((NSClientPlayer)self, playerModel);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CSEv_JoinAuto(void)
|
||||
{
|
||||
float teamChoice = random() < 0.5 ? 1 : 2;
|
||||
CSEv_TeamJoin_f(teamChoice);
|
||||
CSEv_ClassJoin_f(teamChoice == 1 ? 0 : 13);
|
||||
}
|
|
@ -32,6 +32,8 @@ info_ctfspawn:NSEntity
|
|||
|
||||
virtual void Respawn(void);
|
||||
virtual void SpawnKey(string, string);
|
||||
|
||||
nonvirtual void _AfterSpawn(void);
|
||||
};
|
||||
|
||||
void
|
||||
|
@ -52,11 +54,16 @@ info_ctfspawn::SpawnKey(string strKey, string strValue)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
info_ctfspawn::_AfterSpawn(void)
|
||||
{
|
||||
classname = strcat("info_ctfspawn_", ftos(team));
|
||||
}
|
||||
|
||||
void
|
||||
info_ctfspawn::Respawn(void)
|
||||
{
|
||||
SetOrigin(GetSpawnOrigin());
|
||||
SetSolid(SOLID_NOT);
|
||||
|
||||
classname = strcat("info_ctfspawn_", ftos(team));
|
||||
ScheduleThink(_AfterSpawn, 0.0f);
|
||||
}
|
|
@ -44,6 +44,7 @@ class item_ctfflag:OP4CTFItem
|
|||
nonvirtual void FlagTaken(void);
|
||||
nonvirtual void FlagDrop(NSClientPlayer);
|
||||
nonvirtual void FlagReturns(void);
|
||||
nonvirtual void _AfterSpawn(void);
|
||||
};
|
||||
|
||||
void
|
||||
|
@ -52,6 +53,12 @@ item_ctfflag::item_ctfflag(void)
|
|||
m_eActivator = __NULL__;
|
||||
}
|
||||
|
||||
void
|
||||
item_ctfflag::_AfterSpawn(void)
|
||||
{
|
||||
classname = strcat("info_ctfflag_", ftos(m_iTeamID));
|
||||
}
|
||||
|
||||
void
|
||||
item_ctfflag::Respawn(void)
|
||||
{
|
||||
|
@ -64,10 +71,10 @@ item_ctfflag::Respawn(void)
|
|||
|
||||
botinfo = BOTINFO_TEAM_GOALITEM;
|
||||
|
||||
classname = strcat("info_ctfflag_", ftos(m_iTeamID));
|
||||
forceinfokey(world, strcat("ctfflag_", ftos(m_iTeamID)), ftos(CTFFLAG_IDLE));
|
||||
m_eActivator = __NULL__;
|
||||
team = m_iTeamID;
|
||||
ScheduleThink(_AfterSpawn, 0.0f);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -80,12 +87,18 @@ item_ctfflag::Touch(entity eToucher)
|
|||
if (eToucher.team == 0)
|
||||
return;
|
||||
if (eToucher.team == m_iTeamID) {
|
||||
if (m_eActivator == __NULL__) /* only on flags that haven't been dropped */
|
||||
if (pl.g_items & ITEM_GOALITEM) {
|
||||
OP4CTFRules rule = (OP4CTFRules)g_grMode;
|
||||
rule.CaptureFlag((NSClientPlayer)pl);
|
||||
if (m_eActivator == __NULL__) { /* only on flags that haven't been dropped */
|
||||
if (pl.g_items & ITEM_GOALITEM) {
|
||||
OP4CTFRules rule = (OP4CTFRules)g_grMode;
|
||||
rule.CaptureFlag((NSClientPlayer)pl);
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
/* return the flag, give 1 point */
|
||||
FlagReturns();
|
||||
pl.score += 1;
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
m_eActivator = pl;
|
||||
|
@ -137,6 +150,7 @@ item_ctfflag::FlagDrop(NSClientPlayer pp)
|
|||
pl.flagmodel = 0;
|
||||
m_eActivator = pp; /* to mark that who this was dropped by */
|
||||
forceinfokey(world, strcat("ctfflag_", ftos(m_iTeamID)), ftos(CTFFlAG_MISSING));
|
||||
forceinfokey(pl, "*icon1", "");
|
||||
|
||||
/* return after N secs */
|
||||
ScheduleThink(FlagReturns, 30.0f);
|
||||
|
|
Loading…
Reference in a new issue