//-------------------------------------------------------------------------------------------------- // Use an entity's script instance to add an entity IO event (used for firing events on unnamed entities from vscript) //-------------------------------------------------------------------------------------------------- static void DoEntFireByInstanceHandle( HSCRIPT hTarget, const char *pszAction, const char *pszValue, float delay, HSCRIPT hActivator, HSCRIPT hCaller ) { const char *action = "Use"; variant_t value; if ( *pszAction ) { action = STRING( AllocPooledString( pszAction ) ); } if ( *pszValue ) { value.SetString( AllocPooledString( pszValue ) ); } if ( delay < 0 ) { delay = 0; } CBaseEntity* pTarget = ToEnt(hTarget); if ( !pTarget ) { Warning( "VScript error: DoEntFire was passed an invalid entity instance.\n" ); return; } g_EventQueue.AddEvent( pTarget, action, value, delay, ToEnt(hActivator), ToEnt(hCaller) ); }
static void DoEntFire( const char *pszTarget, const char *pszAction, const char *pszValue, float delay, HSCRIPT hActivator, HSCRIPT hCaller ) { const char *target = "", *action = "Use"; variant_t value; target = STRING( AllocPooledString( pszTarget ) ); // Don't allow them to run anything on a point_servercommand unless they're the host player. Otherwise they can ent_fire // and run any command on the server. Admittedly, they can only do the ent_fire if sv_cheats is on, but // people complained about users resetting the rcon password if the server briefly turned on cheats like this: // give point_servercommand // ent_fire point_servercommand command "rcon_password mynewpassword" if ( gpGlobals->maxClients > 1 && V_stricmp( target, "point_servercommand" ) == 0 ) { return; } if ( *pszAction ) { action = STRING( AllocPooledString( pszAction ) ); } if ( *pszValue ) { value.SetString( AllocPooledString( pszValue ) ); } if ( delay < 0 ) { delay = 0; } g_EventQueue.AddEvent( target, action, value, delay, ToEnt(hActivator), ToEnt(hCaller) ); }
//----------------------------------------------------------------------------- // Purpose: Spawn an instance of the entity //----------------------------------------------------------------------------- void CEnvEntityMaker::SpawnEntityAtEntityOriginFromScript( HSCRIPT hEntity ) { CBaseEntity *pTargetEntity = ToEnt( hEntity ); if ( pTargetEntity ) { SpawnEntity( pTargetEntity->GetAbsOrigin(), pTargetEntity->GetAbsAngles() ); } }
static float ScriptTraceLine( const Vector &vecStart, const Vector &vecEnd, HSCRIPT entIgnore ) { // UTIL_TraceLine( vecAbsStart, vecAbsEnd, MASK_BLOCKLOS, pLooker, COLLISION_GROUP_NONE, ptr ); trace_t tr; CBaseEntity *pLooker = ToEnt(entIgnore); UTIL_TraceLine( vecStart, vecEnd, MASK_NPCWORLDSTATIC, pLooker, COLLISION_GROUP_NONE, &tr); if (tr.fractionleftsolid && tr.startsolid) { return 1.0 - tr.fractionleftsolid; } else { return tr.fraction; } }
HSCRIPT FindByClassnameWithin( HSCRIPT hStartEntity , const char *szName, const Vector &vecSrc, float flRadius ) { return ToHScript( gEntList.FindEntityByClassnameWithin( ToEnt( hStartEntity ), szName, vecSrc, flRadius ) ); }
HSCRIPT FindByModel( HSCRIPT hStartEntity, const char *szModelName ) { return ToHScript( gEntList.FindEntityByModel( ToEnt( hStartEntity ), szModelName ) ); }
HSCRIPT FindByTarget( HSCRIPT hStartEntity, const char *szName ) { return ToHScript( gEntList.FindEntityByTarget( ToEnt( hStartEntity ), szName ) ); }
HSCRIPT FindInSphere( HSCRIPT hStartEntity, const Vector &vecCenter, float flRadius ) { return ToHScript( gEntList.FindEntityInSphere( ToEnt( hStartEntity ), vecCenter, flRadius ) ); }
HSCRIPT Next( HSCRIPT hStartEntity ) { return ToHScript( gEntList.NextEnt( ToEnt( hStartEntity ) ) ); }