djcev.com

//

Git Repos / fte_dogmode / qc / triggers / textstory.qc

Last update to this file was on 2025-08-13 at 05:20.

Show textstory.qc

//==============================================================================
// trigger_textstory
//==============================================================================

//======================================================================
// constants
//======================================================================

#ifdef SSQC
//----------------------------------------------------------------------
// base_textstory spawnflags -- CEV
//----------------------------------------------------------------------
typedef enumflags
{
SPAWNFLAG_BASE_TEXTSTORY_SILENT = 1,
SPAWNFLAG_BASE_TEXTSTORY_NOFADE = 2
// SPAWNFLAG_NOT_ON_EASY = 256, // see base_entities.qc -- CEV
// SPAWNFLAG_NOT_ON_NORMAL = 512,
// SPAWNFLAG_NOT_ON_HARD_OR_NIGHTMARE = 1024,
// SPAWNFLAG_NOT_IN_DEATHMATCH = 2048,
// SPAWNFLAG_NOT_IN_COOP = 4096,
// SPAWNFLAG_NOT_IN_SP = 8192,
// SPAWNFLAG_NOT_ON_SKILL2 = 32768, // see base_entities.qc -- CEV
// SPAWNFLAG_NOT_ON_SKILL3 = 65536, // see base_entities.qc -- CEV
// SPAWNFLAG_CENTERPRINTALL = 131072 // see base_entities.qc -- CEV
} base_textstory_spawnflags;
#endif

#ifdef SSQC
const float BASE_TEXTSTORY_DEFAULT_FADE = 160;
#endif

//======================================================================
// forward declarations
//======================================================================

#ifdef SSQC
// base_textstory
void(entity controller) base_textstory_hide;
void(entity controller) base_textstory_show;
void(string key, string value) base_textstory_init_field;
#endif

#ifdef SSQC
// trigger_textstory
void() trigger_textstory_hide;
void() trigger_textstory_show;
void() trigger_textstory_touch;
void(entity e) trigger_textstory_init;
void() trigger_textstory;
#endif

#ifdef SSQC
// target_textstory_helper
void() target_textstory_helper_hide;
void() target_textstory_helper_show;
entity(entity src, entity tgt, float nthink, float atkfinished)
spawn_target_textstory_helper;
void(entity e) target_textstory_helper_init;
strip void() target_textstory_helper;
#endif

#ifdef SSQC
// target_textstory
// void(entity tgt) target_textstory_spawn_helper;
void() target_textstory_use;
void(entity e) target_textstory_init;
void() target_textstory;
#endif

//------------------------------------------------------------------------------

#ifdef SSQC
//----------------------------------------------------------------------
// base textstory class
//----------------------------------------------------------------------
// class base_textstory: base_trigger
// {
//--------------------------------------------------------------
// hide a textstory
//--------------------------------------------------------------
void(entity controller) base_textstory_hide =
{
if (!self.enemy || !(self.enemy.flags & FL_CLIENT))
return;

self.enemy.stateflags &= ~STATE_SUPPRESSCENTERPRINT;
centerprint (self.enemy, "");

if (controller.noise2 != __NULL__ && controller.noise2 != "")
sound (self.enemy, CHAN_BODY, controller.noise2,
VOL_HIGH, ATTN_NORM);

if (!(controller.spawnflags & SPAWNFLAG_BASE_TEXTSTORY_NOFADE))
csf_fade (self.enemy, 0, '0 0 0', 0.5);
};

//--------------------------------------------------------------
// show a textstory
//--------------------------------------------------------------
void(entity controller) base_textstory_show =
{
if (!self.enemy || !(self.enemy.flags & FL_CLIENT))
return;

self.enemy.stateflags |= STATE_SUPPRESSCENTERPRINT;

centerprint_builtin (self.enemy, controller.message);

if (!(self.stateflags & STATE_INVISIBLE))
{
if (controller.noise1 != __NULL__ &&
controller.noise1 != "")
{
sound (self.enemy, CHAN_BODY, controller.noise1,
VOL_HIGH, ATTN_NORM);
}

if (!(controller.spawnflags &
SPAWNFLAG_BASE_TEXTSTORY_NOFADE))
{
csf_fade (self.enemy, self.cnt, '0 0 0', 1);
}
}

self.stateflags |= STATE_INVISIBLE;
};

//--------------------------------------------------------------
void(string key, string value) base_textstory_init_field =
{
switch (key)
{
case "fade_amt":
self.cnt = stof (value);
break;
case "is_waiting":
// rewrite is_waiting to a stateflag -- CEV
if (stof(value))
self.stateflags |= STATE_WAITING;
break;
}
};
// };
#endif

#ifdef SSQC
//----------------------------------------------------------------------
// trigger_textstory -- centerprint text when inside this trigger
//----------------------------------------------------------------------
// class trigger_textstory: base_textstory
// {
//--------------------------------------------------------------
// hide text
//--------------------------------------------------------------
void() trigger_textstory_hide =
{
base_textstory_hide (self);

self.enemy = world;
self.stateflags &= ~STATE_INVISIBLE;
};

//--------------------------------------------------------------
// show text
//--------------------------------------------------------------
void() trigger_textstory_show =
{
base_textstory_show (self);

self.think = trigger_textstory_hide;
self.nextthink = time + 0.2;
};

//--------------------------------------------------------------
void() trigger_textstory_touch =
{
if (self.stateflags & STATE_INACTIVE)
return;

if (!(other.flags & FL_CLIENT))
return;

// don't show message if another player is already triggering it
if (other != self.enemy && self.stateflags & STATE_INVISIBLE)
return;

if (self.mangle && !is_in_angle (other.v_angle, self.mangle,
self.view_ofs))
{
return;
}

if (self.attack_finished < time)
{
self.attack_finished = time + 0.1;
self.enemy = other;

trigger_textstory_show ();
}
};

//--------------------------------------------------------------
void(entity e) trigger_textstory_init =
{
e.classname = "trigger_textstory";
e.classtype = CT_TRIGGER_TEXTSTORY;
e.touch = trigger_textstory_touch;
base_trigger_init (e);

// custom fade amount -- dumptruck_ds
if (!e.cnt)
e.cnt = BASE_TEXTSTORY_DEFAULT_FADE;

if (e.view_ofs == '0 0 0')
e.view_ofs = '90 90 0';

if (e.mangle)
e.mangle = normalize_angles180 (e.mangle);

if (e.noise1 == "")
e.noise1 = snd_misc_talk.wav;

if (e.noise2 == "")
e.noise2 = snd_null.wav;

if (e.spawnflags & SPAWNFLAG_BASE_TEXTSTORY_SILENT)
{
e.noise1 = "";
e.noise2 = "";
}


if (e.noise1 != "")
precache_sound (e.noise1);
if (e.noise2 != "")
precache_sound (e.noise2);

sub_checkwaiting (e);
};

//--------------------------------------------------------------
void() trigger_textstory =
{
BASE_TRIGGER_PREINIT (base_textstory_init_field)
trigger_textstory_init (self);
};
// };
#endif

#ifdef SSQC
//------------------------------------------------------------------------------
// helper class spawned by target_textstory below
//------------------------------------------------------------------------------
// class target_textstory_helper: base_textstory
// {
//--------------------------------------------------------------
// hide text
//--------------------------------------------------------------
void() target_textstory_helper_hide =
{
base_textstory_hide (self.owner);
remove (self);
};

//--------------------------------------------------------------
// show text
//--------------------------------------------------------------
void() target_textstory_helper_show =
{
if (!self.enemy || !(self.enemy.flags & FL_CLIENT))
{
remove (self);
return;
}

base_textstory_show (self.owner);

if (self.attack_finished < time)
self.think = target_textstory_helper_hide;

self.nextthink = time + 0.1;
};

//--------------------------------------------------------------
entity(entity src, entity tgt, float nthink, float atkfinished)
spawn_target_textstory_helper =
{
local entity e = spawn ();
e.owner = src;
e.enemy = tgt;
e.nextthink = nthink;
e.attack_finished = atkfinished;
e.cnt = src.cnt;
target_textstory_helper_init (e);
return e;
};

//--------------------------------------------------------------
void(entity e) target_textstory_helper_init =
{
e.classname = "target_textstory_helper";
e.classtype = CT_TARGET_TEXTSTORY_HELPER;
e.think = target_textstory_helper_show;

base_tempentity_init (e);
};

//--------------------------------------------------------------
strip void() target_textstory_helper =
{
target_textstory_helper_init (self);
};
// };
#endif

#ifdef SSQC
//----------------------------------------------------------------------
// target_textstory: centerprint a message for an amount of time when used
//----------------------------------------------------------------------
// class target_textstory: base_textstory
// {
//--------------------------------------------------------------
void() target_textstory_use =
{
if (self.stateflags & STATE_INACTIVE)
return;

if (!(activator.flags & FL_CLIENT))
return;

local entity t;

if (self.spawnflags & SPAWNFLAG_CENTERPRINTALL)
{
t = findfloat (world, classtype, CT_PLAYER);
while (t)
{
spawn_target_textstory_helper (self, t,
time + 0.1, time + self.wait);
t = findfloat (t, classtype, CT_PLAYER);
}
}
else
{
spawn_target_textstory_helper (self, activator,
time + 0.1, time + self.wait);
}
};

//--------------------------------------------------------------
void(entity e) target_textstory_init =
{
e.classname = "target_textstory";
e.classtype = CT_TARGET_TEXTSTORY;
base_mapentity_init (e);

// custom fade amount -- dumptruck_ds
if (!e.cnt)
e.cnt = BASE_TEXTSTORY_DEFAULT_FADE;

if (e.noise1 == "")
e.noise1 = snd_misc_talk.wav;

if (e.noise2 == "")
e.noise2 = snd_null.wav;

if (e.spawnflags & SPAWNFLAG_BASE_TEXTSTORY_SILENT) {
e.noise1 = "";
e.noise2 = "";
}

if (e.noise1 != "")
precache_sound (e.noise1);
if (e.noise2 != "")
precache_sound (e.noise2);

if (!e.wait)
e.wait = 5;

e.use = target_textstory_use;
};

//--------------------------------------------------------------
void() target_textstory =
{
BASE_TRIGGER_PREINIT (base_textstory_init_field)
target_textstory_init (self);
};
// };
#endif

Return to the top of this page or return to the overview of this repo.

Log textstory.qc

Return to the top of this page or return to the overview of this repo.