Beispiel #1
0
static cell_t GetClientEyeAngles(IPluginContext *pContext, const cell_t *params)
{
	IGamePlayer *pPlayer = playerhelpers->GetGamePlayer(params[1]);

	if (!pPlayer)
	{
		return pContext->ThrowNativeError("Invalid client index %d", params[1]);
	}
	else if (!pPlayer->IsInGame())
	{
		return pContext->ThrowNativeError("Client %d is not in game", params[1]);
	}

	edict_t *pEdict = pPlayer->GetEdict();
	CBaseEntity *pEntity = pEdict->GetUnknown() ? pEdict->GetUnknown()->GetBaseEntity() : NULL;

	/* We always set the angles for backwards compatibility -- 
	 * The original function had no return value.
	 */
	QAngle angles;
	bool got_angles = false;

	if (pEntity != NULL)
	{
		got_angles = GetEyeAngles(pEntity, &angles);
	}
	
	cell_t *addr;
	pContext->LocalToPhysAddr(params[2], &addr);
	addr[0] = sp_ftoc(angles.x);
	addr[1] = sp_ftoc(angles.y);
	addr[2] = sp_ftoc(angles.z);

	return got_angles ? 1 : 0;
}
Beispiel #2
0
int GetClientAimTarget(edict_t *pEdict, bool only_players)
{
	CBaseEntity *pEntity = pEdict->GetUnknown() ? pEdict->GetUnknown()->GetBaseEntity() : NULL;

	if (pEntity == NULL)
	{
		return -1;
	}

	Vector eye_position;
	QAngle eye_angles;

	/* Get the private information we need */
#if SOURCE_ENGINE == SE_DOTA
	serverClients->ClientEarPosition(IndexOfEdict(pEdict), &eye_position);
#else
	serverClients->ClientEarPosition(pEdict, &eye_position);
#endif

	if (!GetEyeAngles(pEntity, &eye_angles))
	{
		return -2;
	}

	Vector aim_dir;
	AngleVectors(eye_angles, &aim_dir);
	VectorNormalize(aim_dir);

	Vector vec_end = eye_position + aim_dir * 8000;

	Ray_t ray;
	ray.Init(eye_position, vec_end);

	trace_t tr;
	CTraceFilterSimple simple(pEdict->GetIServerEntity());

	enginetrace->TraceRay(ray, MASK_SOLID|CONTENTS_DEBRIS|CONTENTS_HITBOX, &simple, &tr);

	if (tr.fraction == 1.0f || tr.m_pEnt == NULL)
	{
		return -1;
	}

	int ent_ref = gamehelpers->EntityToBCompatRef(tr.m_pEnt);
	int ent_index = gamehelpers->ReferenceToIndex(ent_ref);

	IGamePlayer *pTargetPlayer = playerhelpers->GetGamePlayer(ent_index);
	if (pTargetPlayer != NULL && !pTargetPlayer->IsInGame())
	{
		return -1;
	}
	else if (only_players && pTargetPlayer == NULL)
	{
		return -1;
	}

	return ent_ref;
}
Beispiel #3
0
//----------------------------------------------------------------------------------------------------------------
void CClient::PreThink()
{
    int iLastWaypoint = iCurrentWaypoint;
    CPlayer::PreThink();

    // Client don't have access to waypoint modification.
    if ( FLAG_CLEARED(FCommandAccessWaypoint, iCommandAccessFlags) )
        return;

    // Check if lost waypoint, in that case add new one.
    if ( bAutoCreateWaypoints && m_bAlive &&
         ( !CWaypoint::IsValid(iCurrentWaypoint) ||
           (GetHead().DistToSqr(CWaypoints::Get(iCurrentWaypoint).vOrigin) >= SQR(CWaypoint::iDefaultDistance)) ) )
    {
        Vector vOrigin( GetHead() );

        // Add new waypoint, but distance from previous one must not be bigger than iDefaultDistance.
        if ( CWaypoint::IsValid(iLastWaypoint) )
        {
            CWaypoint& wLast = CWaypoints::Get(iLastWaypoint);
            vOrigin -= wLast.vOrigin;
            vOrigin.NormalizeInPlace();
            vOrigin *= CWaypoint::iDefaultDistance;
            vOrigin += wLast.vOrigin;
        }

        // Add new waypoint.
        iCurrentWaypoint = CWaypoints::Add(vOrigin);

        // Add paths from previous to current.
        if ( CWaypoint::IsValid(iLastWaypoint) )
        {
            float fHeight = GetPlayerInfo()->GetPlayerMaxs().z - GetPlayerInfo()->GetPlayerMins().z + 1;
            bool bIsCrouched = (fHeight < CMod::iPlayerHeight);

            CWaypoints::CreatePathsWithAutoFlags(iLastWaypoint, iCurrentWaypoint, bIsCrouched);
            iDestinationWaypoint = iLastWaypoint;
        }
    }

    // Calculate destination waypoint according to angles. Path's should be drawn.
    if ( !bLockDestinationWaypoint && (iPathDrawFlags != FPathDrawNone) &&
         (CWaypoints::fNextDrawWaypointsTime >= CBotrixPlugin::fTime) )
    {
        QAngle ang;
        GetEyeAngles(ang);
        iDestinationWaypoint = CWaypoints::GetAimedWaypoint( GetHead(), ang );
    }

    // Draw waypoints.
    CWaypoints::Draw(this); // TODO: should not draw for several admins...

    // Draw entities.
    CItems::Draw(this);
}