| 210 | } |
| 211 | |
| 212 | int GetClientAimTarget(edict_t *pEdict, bool only_players) |
| 213 | { |
| 214 | CBaseEntity *pEntity = pEdict->GetUnknown() ? pEdict->GetUnknown()->GetBaseEntity() : NULL; |
| 215 | |
| 216 | if (pEntity == NULL) |
| 217 | { |
| 218 | return -1; |
| 219 | } |
| 220 | |
| 221 | Vector eye_position; |
| 222 | QAngle eye_angles; |
| 223 | |
| 224 | /* Get the private information we need */ |
| 225 | serverClients->ClientEarPosition(pEdict, &eye_position); |
| 226 | |
| 227 | if (!GetEyeAngles(pEntity, &eye_angles)) |
| 228 | { |
| 229 | return -2; |
| 230 | } |
| 231 | |
| 232 | Vector aim_dir; |
| 233 | AngleVectors(eye_angles, &aim_dir); |
| 234 | VectorNormalize(aim_dir); |
| 235 | |
| 236 | Vector vec_end = eye_position + aim_dir * 8000; |
| 237 | |
| 238 | Ray_t ray; |
| 239 | ray.Init(eye_position, vec_end); |
| 240 | |
| 241 | trace_t tr; |
| 242 | CTraceFilterSimple simple(pEdict->GetIServerEntity()); |
| 243 | |
| 244 | enginetrace->TraceRay(ray, MASK_SOLID|CONTENTS_DEBRIS|CONTENTS_HITBOX, &simple, &tr); |
| 245 | |
| 246 | if (tr.fraction == 1.0f || tr.m_pEnt == NULL) |
| 247 | { |
| 248 | return -1; |
| 249 | } |
| 250 | |
| 251 | int ent_ref = gamehelpers->EntityToBCompatRef(tr.m_pEnt); |
| 252 | int ent_index = gamehelpers->ReferenceToIndex(ent_ref); |
| 253 | |
| 254 | IGamePlayer *pTargetPlayer = playerhelpers->GetGamePlayer(ent_index); |
| 255 | if (pTargetPlayer != NULL && !pTargetPlayer->IsInGame()) |
| 256 | { |
| 257 | return -1; |
| 258 | } |
| 259 | else if (only_players && pTargetPlayer == NULL) |
| 260 | { |
| 261 | return -1; |
| 262 | } |
| 263 | |
| 264 | return ent_ref; |
| 265 | } |
| 266 | |
| 267 | bool IsEyeAnglesSupported() |
| 268 | { |
no test coverage detected