princess milk
Join Date: Nov 2010
Location: Somewhere in this world
02-14-2016
, 20:28
env_beam fires HookSingleEntityOutput callback only once
#1
So basiclly, my problem is that the callback in this code is only fired once. I need it to be called for every frame for every touch in order to play a sound when a player touches the 'beam'.
PHP Code:
HookSingleEntityOutput ( iEnt , "OnTouchedByEntity" , MineLaser_OnTouch , false );
Think code from
[Here]
SDK env_beam think code
PHP Code:
void CEnvBeam :: UpdateThink ( void )
{
// Apply damage every 1/10th of a second.
if ( ( m_flDamage > 0 ) && ( gpGlobals -> curtime >= m_flFireTime + 0.1 ) )
{
trace_t tr ;
UTIL_TraceLine ( GetAbsStartPos (), GetAbsEndPos (), MASK_SOLID , NULL , COLLISION_GROUP_NONE , & tr );
BeamDamage ( & tr );
// BeamDamage calls RelinkBeam, so no need to call it again.
}
else
{
RelinkBeam ();
}
if( m_TouchType != touch_none )
{
trace_t tr ;
Ray_t ray ;
ray . Init ( GetAbsStartPos (), GetAbsEndPos () );
if( m_TouchType == touch_player_or_npc_or_physicsprop )
{
CTraceFilterPlayersNPCsPhysicsProps traceFilter ;
enginetrace -> TraceRay ( ray , MASK_SHOT , & traceFilter , & tr );
}
else
{
CTraceFilterPlayersNPCs traceFilter ;
enginetrace -> TraceRay ( ray , MASK_SHOT , & traceFilter , & tr );
}
if( tr . fraction != 1.0 && PassesTouchFilters ( tr . m_pEnt ) )
{
m_OnTouchedByEntity . FireOutput ( tr . m_pEnt , this , 0 );
return;
}
}
SetNextThink ( gpGlobals -> curtime );
}
As you can see, the part that messes up with the (next) think is this
Code:
if( tr.fraction != 1.0 && PassesTouchFilters( tr.m_pEnt ) )
{
m_OnTouchedByEntity.FireOutput( tr.m_pEnt, this, 0 );
return ;
}
Things I have tried:
I have tried to set the next think time using the following code:
PHP Code:
SetEntProp ( iEnt , Prop_Data , "m_nNextThinkTick" , GetGameTickCount ());
I have also tried to reassign the TouchType value using DispatchKeyValue in MineLaser_OnTouch, but with no luck.
My plugin's code in case you're intrested
PHP Code:
// How I create the beam:
int CreateLaser ( Float : start [ 3 ], Float : end [ 3 ])
{
new ent = CreateEntityByName ( "env_beam" );
if ( ent != - 1 )
{
TeleportEntity ( ent , start , NULL_VECTOR , NULL_VECTOR );
SetEntityModel ( ent , MODEL_BEAM ); // This is where you would put the texture, ie "sprites/laser.vmt" or whatever.
SetEntPropVector ( ent , Prop_Data , "m_vecEndPos" , end );
DispatchKeyValue ( ent , "targetname" , g_szMineLaserTargetName );
DispatchKeyValue ( ent , "rendercolor" , g_szMineLaserColor );
DispatchKeyValue ( ent , "renderamt" , "67" );
DispatchKeyValue ( ent , "decalname" , "Bigshot" );
DispatchKeyValue ( ent , "life" , "0" );
DispatchKeyValue ( ent , "TouchType" , "0" );
DispatchSpawn ( ent );
SetEntPropFloat ( ent , Prop_Data , "m_fWidth" , 1.0 );
SetEntPropFloat ( ent , Prop_Data , "m_fEndWidth" , 1.0 );
DispatchKeyValue ( ent_laser , "TouchType" , "4" );
DispatchKeyValue ( ent_laser , "renderamt" , "255" );
ActivateEntity ( ent );
AcceptEntityInput ( ent , "TurnOn" );
}
return ent ;
}
public void MineLaser_OnTouch (const char [] output , int iEnt , int iActivator , float delay )
//public Action SDKCallback_TouchPost_MineLaser(int iEnt, int iActivator)
{
PrintToServer ( "Touch" );
//SetEntProp(iEnt, Prop_Data, "m_TouchType", 4);
//HookSingleEntityOutput(iEnt, "OnTouchedByEntity", MineLaser_OnTouch, false);
//SetEntProp(iEnt, Prop_Data, "m_nNextThinkTick", GetGameTickCount());
char szTargetName [ 32 ];
GetEntPropString ( iEnt , Prop_Data , "m_iName" , szTargetName , sizeof szTargetName );
if(! StrEqual ( szTargetName , g_szMineLaserTargetName ))
{
PrintToServer ( "Fail #1" );
return;
}
if (! IsPlayer ( iActivator ))
{
PrintToServer ( "Fail #2" );
return;
}
if (! IsPlayerAlive ( iActivator ))
{
PrintToServer ( "Fail #3" );
return;
}
float vOrigin [ 3 ];
GetClientAbsOrigin ( iActivator , vOrigin );
EmitSoundToAll ( g_szMineLaserTouchSound , iActivator );
PrintToServer ( "Touch Sound played" );
}
Any ideas?
__________________
اَشْهَدُ اَنْ لَّآ اِلٰهَ اِلَّا اللہُ وَحْدَه لَا شَرِيْكَ لَه وَ اَشْهَدُ اَنَّ مُحَمَّدًا عَبْدُه وَرَسُوْلُه
No longer active in AMXX. Sorry.
Last edited by pokemonmaster; 02-14-2016 at 20:33 .
Reason: Accidently posted before completing the formatting.. :/