object trigger_look { float stim; float distance; float processing; float eps; float singleUse; string entityName; void init(); void processStim(entity inflictor,float f); }; float length(vector v) { return sys.sqrt(v_x*v_x+v_y*v_y+v_z*v_z); } void trigger_look::init() { stim=getFloatKey("stim"); if (!stim) { stim=23; } distance=getFloatKey("distance"); if (!distance) { distance=1024; } eps=getFloatKey("tolerance"); if (!eps) { eps=0.1; } eps=1.0-eps; singleUse=getFloatKey("once"); entityName=getKey("entityname"); if (entityName=="") { entityName="player1"; } ResponseAdd(stim); ResponseSetAction(stim,"processStim"); ResponseEnable(stim,1); processing=0; } void trigger_look::processStim(entity inflictor,float f) { if (processing || entityName!=inflictor.getName()) { return; } processing=1; vector playerView,shieldToPlayer,playerViewDir; if (entityName=="player1") { playerView=inflictor.getViewAngles(); } else { playerView=inflictor.getAngles(); } shieldToPlayer=getOrigin()-inflictor.getOrigin(); shieldToPlayer_z-=64; if (entityName!="player1") { playerView_z=shieldToPlayer_z; } if (length(shieldToPlayer)>distance) { return; } playerViewDir_x=sys.cos(playerView_y)*sys.cos(playerView_x); playerViewDir_y=sys.sin(playerView_y)*sys.cos(playerView_x); playerViewDir_z=-sys.sin(playerView_x); float angle; angle=playerViewDir*shieldToPlayer/length(shieldToPlayer); if (angle>eps) { activateTargets(inflictor); if(singleUse) { ResponseEnable(stim,0); return; } } processing=0; }