Senior Member
Join Date: Jun 2010
Location: Ukraine
|
04-15-2015
, 03:56
Re: [Help]Reset func_train
|
#6
|
I already try this method, I save pev_target to global array and set this value to pev_target. I try to emit engine DLLFunc_Think and HAM_CS_Restart after set the values.
Brush entity default origin is {0, 0, 0}. I need to find all and replace all values to default, but I don't know what values I need. Found values:
- pev_nextthink - 0 by default
- pev_velocity - g_vecZero by default
- pev_target - key target value by default
- pev_message - 0 by default
- pev_enemy - 0 by default
- pev_spawnflags - "pev_spawnflags | SF_TRAIN_WAIT_RETRIGGER" by default
- m_pevCurrentTarget - 0 by default
- m_activated - 0 by default
- m_pfnThink - 0 by default
- m_pfnCallWhenMoveDone - 0 by defa
- m_vecFinalDest - g_vecZero by defa
- m_vecFinalAngle - g_vecZero by default
PHP Code:
new const g_vecZero[3] = {0, 0, 0};
const m_pevCurrentTarget = 79; const m_activated = 81; const m_pfnThink = 4; const m_pfnCallWhenMoveDone = 64;
new const m_vecFinalDest[3] = {65, ...}; new const m_vecFinalAngle[3] = {68, ...};
//I dont know how to use: const m_hEnemy_serialnumber = 85; const m_hTargetEnt = 86; const m_hEnemy = 84;
From plats.cpp:
Quote:
PHP Code:
void CFuncTrain :: Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ) { if ( pev->spawnflags & SF_TRAIN_WAIT_RETRIGGER ) { // Move toward my target pev->spawnflags &= ~SF_TRAIN_WAIT_RETRIGGER; Next(); } else { pev->spawnflags |= SF_TRAIN_WAIT_RETRIGGER; // Pop back to last target if it's available if ( pev->enemy ) pev->target = pev->enemy->v.targetname; pev->nextthink = 0; pev->velocity = g_vecZero; if ( pev->noiseStopMoving ) EMIT_SOUND (ENT(pev), CHAN_VOICE, (char*)STRING(pev->noiseStopMoving), m_volume, ATTN_NORM); } }
void CFuncTrain :: Wait( void ) { // Fire the pass target if there is one if ( m_pevCurrentTarget->message ) { FireTargets( STRING(m_pevCurrentTarget->message), this, this, USE_TOGGLE, 0 ); if ( FBitSet( m_pevCurrentTarget->spawnflags, SF_CORNER_FIREONCE ) ) m_pevCurrentTarget->message = 0; } // need pointer to LAST target. if ( FBitSet (m_pevCurrentTarget->spawnflags , SF_TRAIN_WAIT_RETRIGGER ) || ( pev->spawnflags & SF_TRAIN_WAIT_RETRIGGER ) ) { pev->spawnflags |= SF_TRAIN_WAIT_RETRIGGER; // clear the sound channel. if ( pev->noiseMovement ) STOP_SOUND( edict(), CHAN_STATIC, (char*)STRING(pev->noiseMovement) ); if ( pev->noiseStopMoving ) EMIT_SOUND (ENT(pev), CHAN_VOICE, (char*)STRING(pev->noiseStopMoving), m_volume, ATTN_NORM); pev->nextthink = 0; return; } // ALERT ( at_console, "%f\n", m_flWait );
if (m_flWait != 0) {// -1 wait will wait forever! pev->nextthink = pev->ltime + m_flWait; if ( pev->noiseMovement ) STOP_SOUND( edict(), CHAN_STATIC, (char*)STRING(pev->noiseMovement) ); if ( pev->noiseStopMoving ) EMIT_SOUND (ENT(pev), CHAN_VOICE, (char*)STRING(pev->noiseStopMoving), m_volume, ATTN_NORM); SetThink( &CFuncTrain::Next ); } else { Next();// do it RIGHT now! } }
// // Train next - path corner needs to change to next target // void CFuncTrain :: Next( void ) { CBaseEntity *pTarg;
// now find our next target pTarg = GetNextTarget();
if ( !pTarg ) { if ( pev->noiseMovement ) STOP_SOUND( edict(), CHAN_STATIC, (char*)STRING(pev->noiseMovement) ); // Play stop sound if ( pev->noiseStopMoving ) EMIT_SOUND (ENT(pev), CHAN_VOICE, (char*)STRING(pev->noiseStopMoving), m_volume, ATTN_NORM); return; }
// Save last target in case we need to find it again pev->message = pev->target;
pev->target = pTarg->pev->target; m_flWait = pTarg->GetDelay();
if ( m_pevCurrentTarget && m_pevCurrentTarget->speed != 0 ) {// don't copy speed from target if it is 0 (uninitialized) pev->speed = m_pevCurrentTarget->speed; ALERT( at_aiconsole, "Train %s speed to %4.2f\n", STRING(pev->targetname), pev->speed ); } m_pevCurrentTarget = pTarg->pev;// keep track of this since path corners change our target for us.
pev->enemy = pTarg->edict();//hack
if(FBitSet(m_pevCurrentTarget->spawnflags, SF_CORNER_TELEPORT)) { // Path corner has indicated a teleport to the next corner. SetBits(pev->effects, EF_NOINTERP); UTIL_SetOrigin(pev, pTarg->pev->origin - (pev->mins + pev->maxs)* 0.5); Wait(); // Get on with doing the next path corner. } else { // Normal linear move. // CHANGED this from CHAN_VOICE to CHAN_STATIC around OEM beta time because trains should // use CHAN_STATIC for their movement sounds to prevent sound field problems. // this is not a hack or temporary fix, this is how things should be. (sjb). if ( pev->noiseMovement ) STOP_SOUND( edict(), CHAN_STATIC, (char*)STRING(pev->noiseMovement) ); if ( pev->noiseMovement ) EMIT_SOUND (ENT(pev), CHAN_STATIC, (char*)STRING(pev->noiseMovement), m_volume, ATTN_NORM); ClearBits(pev->effects, EF_NOINTERP); SetMoveDone( &CFuncTrain::Wait ); LinearMove (pTarg->pev->origin - (pev->mins + pev->maxs)* 0.5, pev->speed); } }
void CFuncTrain :: Activate( void ) { // Not yet active, so teleport to first target if ( !m_activated ) { m_activated = TRUE; entvars_t *pevTarg = VARS( FIND_ENTITY_BY_TARGETNAME (NULL, STRING(pev->target) ) ); pev->target = pevTarg->target; m_pevCurrentTarget = pevTarg;// keep track of this since path corners change our target for us. UTIL_SetOrigin (pev, pevTarg->origin - (pev->mins + pev->maxs) * 0.5 ); if ( FStringNull(pev->targetname) ) { // not triggered, so start immediately pev->nextthink = pev->ltime + 0.1; SetThink( &CFuncTrain::Next ); } else pev->spawnflags |= SF_TRAIN_WAIT_RETRIGGER; } }
/*QUAKED func_train (0 .5 .8) ? Trains are moving platforms that players can ride. The targets origin specifies the min point of the train at each corner. The train spawns at the first target it is pointing at. If the train is the target of a button or trigger, it will not begin moving until activated. speed default 100 dmg default 2 sounds 1) ratchet metal */
void CFuncTrain :: Spawn( void ) { Precache(); if (pev->speed == 0) pev->speed = 100; if ( FStringNull(pev->target) ) ALERT(at_console, "FuncTrain with no target"); if (pev->dmg == 0) pev->dmg = 2; pev->movetype = MOVETYPE_PUSH; if ( FBitSet (pev->spawnflags, SF_TRACKTRAIN_PASSABLE) ) pev->solid = SOLID_NOT; else pev->solid = SOLID_BSP;
SET_MODEL( ENT(pev), STRING(pev->model) ); UTIL_SetSize (pev, pev->mins, pev->maxs); UTIL_SetOrigin(pev, pev->origin);
m_activated = FALSE;
if ( m_volume == 0 ) m_volume = 0.85; }
void CFuncTrain::Precache( void ) { CBasePlatTrain::Precache();
#if 0 // obsolete // otherwise use preset sound switch (m_sounds) { case 0: pev->noise = 0; pev->noise1 = 0; break;
case 1: PRECACHE_SOUND ("plats/train2.wav"); PRECACHE_SOUND ("plats/train1.wav"); pev->noise = MAKE_STRING("plats/train2.wav"); pev->noise1 = MAKE_STRING("plats/train1.wav"); break;
case 2: PRECACHE_SOUND ("plats/platmove1.wav"); PRECACHE_SOUND ("plats/platstop1.wav"); pev->noise = MAKE_STRING("plats/platstop1.wav"); pev->noise1 = MAKE_STRING("plats/platmove1.wav"); break; } #endif }
void CFuncTrain::OverrideReset( void ) { CBaseEntity *pTarg;
// Are we moving? if ( pev->velocity != g_vecZero && pev->nextthink != 0 ) { pev->target = pev->message; // now find our next target pTarg = GetNextTarget(); if ( !pTarg ) { pev->nextthink = 0; pev->velocity = g_vecZero; } else // Keep moving for 0.1 secs, then find path_corner again and restart { SetThink( &CFuncTrain::Next ); pev->nextthink = pev->ltime + 0.1; } } }
|
__________________
Last edited by Hedgehog Fog; 04-15-2015 at 08:31.
|
|