@@ -1329,6 +1329,31 @@ void CBaseEntity::FireNamedOutput( const char *pszOutput, variant_t variant, CBa
13291329 }
13301330}
13311331
1332+ #ifdef MAPBASE_VSCRIPT
1333+ void CBaseEntity::ScriptFireOutput ( const char *pszOutput, HSCRIPT hActivator, HSCRIPT hCaller, const char *szValue, float flDelay )
1334+ {
1335+ variant_t value;
1336+ value.SetString ( MAKE_STRING (szValue) );
1337+
1338+ FireNamedOutput ( pszOutput, value, ToEnt (hActivator), ToEnt (hCaller), flDelay );
1339+ }
1340+
1341+ float CBaseEntity::GetMaxOutputDelay ( const char *pszOutput )
1342+ {
1343+ CBaseEntityOutput *pOutput = FindNamedOutput ( pszOutput );
1344+ if ( pOutput )
1345+ {
1346+ return pOutput->GetMaxDelay ();
1347+ }
1348+ return 0 ;
1349+ }
1350+
1351+ void CBaseEntity::CancelEventsByInput ( const char *szInput )
1352+ {
1353+ g_EventQueue.CancelEventsByInput ( this , szInput );
1354+ }
1355+ #endif // MAPBASE_VSCRIPT
1356+
13321357CBaseEntityOutput *CBaseEntity::FindNamedOutput ( const char *pszOutput )
13331358{
13341359 if ( pszOutput == NULL )
@@ -2271,6 +2296,11 @@ BEGIN_ENT_SCRIPTDESC_ROOT( CBaseEntity, "Root class of all server-side entities"
22712296
22722297 DEFINE_SCRIPTFUNC_NAMED( ScriptClassify, " Classify" , " Get Class_T class ID" )
22732298
2299+ DEFINE_SCRIPTFUNC_NAMED( ScriptAcceptInput, " AcceptInput" , " " )
2300+ DEFINE_SCRIPTFUNC_NAMED( ScriptFireOutput, " FireOutput" , " Fire an entity output" )
2301+ DEFINE_SCRIPTFUNC( GetMaxOutputDelay, " Get the longest delay for all events attached to an output" )
2302+ DEFINE_SCRIPTFUNC( CancelEventsByInput, " Cancel all I/O events for this entity, match input" )
2303+
22742304 DEFINE_SCRIPTFUNC_NAMED( ScriptAddOutput, " AddOutput" , " Add an output" )
22752305 DEFINE_SCRIPTFUNC_NAMED( ScriptGetKeyValue, " GetKeyValue" , " Get a keyvalue" )
22762306
@@ -2321,6 +2351,9 @@ BEGIN_ENT_SCRIPTDESC_ROOT( CBaseEntity, "Root class of all server-side entities"
23212351 DEFINE_SCRIPTFUNC( AddEFlags, " Add Eflags" )
23222352 DEFINE_SCRIPTFUNC( RemoveEFlags, " Remove Eflags" )
23232353
2354+ DEFINE_SCRIPTFUNC( GetTransmitState, " " )
2355+ DEFINE_SCRIPTFUNC( SetTransmitState, " " )
2356+
23242357 DEFINE_SCRIPTFUNC_NAMED( ScriptGetMoveType, " GetMoveType" , " Get the move type" )
23252358 DEFINE_SCRIPTFUNC_NAMED( ScriptSetMoveType, " SetMoveType" , " Set the move type" )
23262359
@@ -2474,9 +2507,18 @@ void CBaseEntity::UpdateOnRemove( void )
24742507 {
24752508 CallScriptFunctionHandle ( hFunc, NULL );
24762509 }
2477- #endif
2510+ #endif // MAPBASE_VSCRIPT
2511+
24782512 g_pScriptVM->RemoveInstance ( m_hScriptInstance );
24792513 m_hScriptInstance = NULL ;
2514+
2515+ #ifdef MAPBASE_VSCRIPT
2516+ if ( m_hfnThink )
2517+ {
2518+ g_pScriptVM->ReleaseScript ( m_hfnThink );
2519+ m_hfnThink = NULL ;
2520+ }
2521+ #endif // MAPBASE_VSCRIPT
24802522 }
24812523}
24822524
@@ -4411,7 +4453,11 @@ bool CBaseEntity::AcceptInput( const char *szInputName, CBaseEntity *pActivator,
44114453 // found a match
44124454
44134455 // mapper debug message
4456+ #ifdef MAPBASE
4457+ ConColorMsg ( 2 , Color (CON_COLOR_DEV_VERBOSE ), " (%0.2f) input %s: %s.%s(%s)\n " , gpGlobals->curtime , pCaller ? STRING (pCaller->m_iName .Get ()) : " <NULL>" , GetDebugName (), szInputName, Value.String () );
4458+ #else
44144459 DevMsg ( 2 , " (%0.2f) input %s: %s.%s(%s)\n " , gpGlobals->curtime , pCaller ? STRING (pCaller->m_iName .Get ()) : " <NULL>" , GetDebugName (), szInputName, Value.String () );
4460+ #endif
44154461 ADD_DEBUG_HISTORY ( HISTORY_ENTITY_IO , szBuffer );
44164462
44174463 if (m_debugOverlays & OVERLAY_MESSAGE_BIT )
@@ -4544,10 +4590,25 @@ bool CBaseEntity::AcceptInput( const char *szInputName, CBaseEntity *pActivator,
45444590 }
45454591 }
45464592
4593+ #ifdef MAPBASE
4594+ ConColorMsg ( 2 , Color (CON_COLOR_DEV_VERBOSE ), " unhandled input: (%s) -> (%s,%s)\n " , szInputName, STRING (m_iClassname), GetDebugName () );
4595+ #else
45474596 DevMsg ( 2 , " unhandled input: (%s) -> (%s,%s)\n " , szInputName, STRING (m_iClassname), GetDebugName ()/* ,", from (%s,%s)" STRING(pCaller->m_iClassname), STRING(pCaller->m_iName.Get())*/ );
4597+ #endif
45484598 return false ;
45494599}
45504600
4601+ #ifdef MAPBASE_VSCRIPT
4602+ bool CBaseEntity::ScriptAcceptInput ( const char *szInputName, const char *szValue, HSCRIPT hActivator, HSCRIPT hCaller )
4603+ {
4604+ variant_t value;
4605+ value.SetString ( MAKE_STRING (szValue) );
4606+
4607+ return AcceptInput ( szInputName, ToEnt (hActivator), ToEnt (hCaller), value, 0 );
4608+ }
4609+ #endif
4610+
4611+
45514612// -----------------------------------------------------------------------------
45524613// Purpose: Input handler for the entity alpha.
45534614// Input : nAlpha - Alpha value (0 - 255).
@@ -4587,6 +4648,17 @@ void CBaseEntity::InputColor( inputdata_t &inputdata )
45874648void CBaseEntity::InputUse ( inputdata_t &inputdata )
45884649{
45894650 Use ( inputdata.pActivator , inputdata.pCaller , (USE_TYPE )inputdata.nOutputID , 0 );
4651+
4652+ #ifdef MAPBASE
4653+ IGameEvent *event = gameeventmanager->CreateEvent ( " player_use" );
4654+ if ( event )
4655+ {
4656+ event->SetInt ( " userid" , inputdata.pActivator && inputdata.pActivator ->IsPlayer () ?
4657+ ((CBasePlayer*)inputdata.pActivator )->GetUserID () : 0 );
4658+ event->SetInt ( " entity" , entindex () );
4659+ gameeventmanager->FireEvent ( event );
4660+ }
4661+ #endif // MAPBASE
45904662}
45914663
45924664
@@ -4702,7 +4774,19 @@ void CBaseEntity::InputKill( inputdata_t &inputdata )
47024774 m_OnKilled.FireOutput ( inputdata.pActivator , this );
47034775#endif
47044776
4777+ #ifdef MAPBASE
4778+ // Kick players
4779+ if ( IsPlayer () )
4780+ {
4781+ engine->ServerCommand ( UTIL_VarArgs ( " kickid %d CBaseEntity::InputKill()\n " , engine->GetPlayerUserId (edict ()) ) );
4782+ }
4783+ else
4784+ {
4785+ UTIL_Remove ( this );
4786+ }
4787+ #else
47054788 UTIL_Remove ( this );
4789+ #endif
47064790}
47074791
47084792void CBaseEntity::InputKillHierarchy ( inputdata_t &inputdata )
@@ -4724,6 +4808,9 @@ void CBaseEntity::InputKillHierarchy( inputdata_t &inputdata )
47244808
47254809#ifdef MAPBASE
47264810 m_OnKilled.FireOutput ( inputdata.pActivator , this );
4811+
4812+ // Kicking players in InputKillHierarchy does not exist in future Valve games
4813+ // if ( IsPlayer() )
47274814#endif
47284815
47294816 UTIL_Remove ( this );
@@ -8410,7 +8497,7 @@ void CBaseEntity::ScriptThink(void)
84108497#ifdef MAPBASE_VSCRIPT
84118498// -----------------------------------------------------------------------------
84128499// -----------------------------------------------------------------------------
8413- void CBaseEntity::ScriptSetThinkFunction (const char *szFunc, float time )
8500+ void CBaseEntity::ScriptSetThinkFunction ( const char *szFunc, float flTime )
84148501{
84158502 // Empty string stops thinking
84168503 if (!szFunc || szFunc[0 ] == ' \0 ' )
@@ -8420,7 +8507,8 @@ void CBaseEntity::ScriptSetThinkFunction(const char *szFunc, float time)
84208507 else
84218508 {
84228509 m_iszScriptThinkFunction = AllocPooledString (szFunc);
8423- SetContextThink ( &CBaseEntity::ScriptThink, gpGlobals->curtime + time, " ScriptThink" );
8510+ flTime = max ( 0 , flTime );
8511+ SetContextThink ( &CBaseEntity::ScriptThink, gpGlobals->curtime + flTime, " ScriptThink" );
84248512 }
84258513}
84268514
@@ -8434,37 +8522,30 @@ void CBaseEntity::ScriptStopThinkFunction()
84348522// -----------------------------------------------------------------------------
84358523void CBaseEntity::ScriptThinkH ()
84368524{
8437- if (m_hfnThink)
8525+ ScriptVariant_t varThinkRetVal;
8526+ if ( g_pScriptVM->ExecuteFunction (m_hfnThink, NULL , 0 , &varThinkRetVal, NULL , true ) == SCRIPT_ERROR )
84388527 {
8439- ScriptVariant_t varThinkRetVal;
8440- if (g_pScriptVM->ExecuteFunction (m_hfnThink, NULL , 0 , &varThinkRetVal, NULL , true ) == SCRIPT_ERROR )
8441- {
8442- DevWarning (" %s FAILED to call script think function (invalid closure)!\n " , GetDebugName ());
8443- ScriptStopThink ();
8444- return ;
8445- }
8446-
8447- float flThinkFrequency = 0 .f ;
8448- if (!varThinkRetVal.AssignTo (&flThinkFrequency))
8449- {
8450- // no return value stops thinking
8451- ScriptStopThink ();
8452- return ;
8453- }
8454-
8455- SetNextThink (gpGlobals->curtime + flThinkFrequency, " ScriptThinkH" );
8528+ DevWarning (" %s FAILED to call script think function (invalid closure)!\n " , GetDebugName ());
8529+ ScriptStopThink ();
8530+ return ;
84568531 }
8457- else
8532+
8533+ float flThinkFrequency = 0 .f ;
8534+ if ( !varThinkRetVal.AssignTo (&flThinkFrequency) )
84588535 {
8459- DevWarning (" %s FAILED to call script think function (invalid closure)!\n " , GetDebugName ());
8536+ // no return value stops thinking
8537+ ScriptStopThink ();
8538+ return ;
84608539 }
8540+
8541+ SetNextThink ( gpGlobals->curtime + flThinkFrequency, " ScriptThinkH" );
84618542}
84628543
8463- void CBaseEntity::ScriptSetThink (HSCRIPT hFunc, float time )
8544+ void CBaseEntity::ScriptSetThink ( HSCRIPT hFunc, float flTime )
84648545{
8465- if (hFunc)
8546+ if ( hFunc )
84668547 {
8467- if (m_hfnThink)
8548+ if ( m_hfnThink )
84688549 {
84698550 // release old func
84708551 ScriptStopThink ();
@@ -8473,7 +8554,8 @@ void CBaseEntity::ScriptSetThink(HSCRIPT hFunc, float time)
84738554 // no type check here, print error on call instead
84748555 m_hfnThink = hFunc;
84758556
8476- SetContextThink ( &CBaseEntity::ScriptThinkH, gpGlobals->curtime + time, " ScriptThinkH" );
8557+ flTime = max ( 0 , flTime );
8558+ SetContextThink ( &CBaseEntity::ScriptThinkH, gpGlobals->curtime + flTime, " ScriptThinkH" );
84778559 }
84788560 else
84798561 {
0 commit comments