halflife icon indicating copy to clipboard operation
halflife copied to clipboard

[CS] trigger_once does not work

Open tyftler opened this issue 13 years ago • 1 comments

It only works once per map, so you cannot trigger it again until map change. It should be reset on round start.

tyftler avatar Feb 05 '13 18:02 tyftler

Changing this behavior now could break maps that use it for one off triggers.

I suggest adding a keyvalue (not spawnflag since it can easily conflict) to allow resetting on round start.

Since trigger_once uses base class methods and removes itself on fire the base class will need to be changed to handle this case: https://github.com/ValveSoftware/halflife/blob/c7240b965743a53a29491dd49320c88eecf6257b/dlls/triggers.cpp#L1183-L1190

Change this to:

else
{
	// we can't just remove (self) here, because this is a touch function
	// called while C code is looping through area links...
	SetTouch( NULL );

	if( !m_bRestartOnNewRound )
	{
		pev->nextthink = gpGlobals->time + 0.1;
		SetThink(  &CBaseTrigger::SUB_Remove );
	}
}

Adding a Restart method to the entity and adding it to CHalfLifeMultiplay::CleanUpMap should work:

void CTriggerMultiple::Restart()
{
    if( m_bRestartOnNewRound )
    {
        //Reenable touch method
        SetTouch( &CTriggerMultiple::MultiTouch );
    }
}

Note: both trigger_once and trigger_multiple need to be restarted since trigger_multiple is the base class for trigger_once and implements the trigger logic, and trigger_multiple can be made to act as a trigger_once by setting wait time to -1 (which is what trigger_once does).

SamVanheer avatar Jul 18 '19 11:07 SamVanheer