initial value of reference to non-const must be an lvalue

I am trying to make Aimbot for one online game , but problem is it seems like I am not experienced enough.Soo I tired to take code of someone else and customize it ,but It had alot of erros ,I managed to fix all of them myself but this one I couldnt.

Declaration
Vector3 angleDifferenceToEntity(BaseEntity& localPlayer, BaseEntity& entity, uint32_t boneId);
Defenition
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
    Vector3 Hacks::angleDifferenceToEntity(BaseEntity& localPlayer, BaseEntity& entity, uint32_t boneId)
  {
    Vector3 viewAngles = client->getViewAngles();

    Vector3 aimAngles = aimAnglesTo(localPlayer, entity.getBonePosition(boneId));

    Vector3 dAngle(-1, -1, 0);

    if (aimAngles(0) != aimAngles(0) || aimAngles(1) != aimAngles(1))
      return dAngle;


    dAngle(0) = abs(aimAngles(0) - viewAngles(0));
    dAngle(1) = abs(aimAngles(1) - viewAngles(1));

    return dAngle;
  }


Error happens at Vector3 aimAngles = aimAnglesTo(localPlayer, entity.getBonePosition(boneId));
It has something to do with Pointers but I dont know for real soo thats why I am asking for help.
Why do you think it has something to do with pointers?

We'd need to know far more about the code than you've shown us. In particular:

- which reference is that error message talking about? The error message will be unambiguous about this.
- What's the signature of aimAnglesTo()?
- How is BaseEntity.getBonePosition() defined? In particular, what is it returning?

If I had to guess, based on the limited information you've decided to give us, my guess would be that BaseEntity.getBonePosition() is returning something that can't be used to initialise a reference. It's probably returning something by value, which means you're trying to take a reference to an anonymous temporary object.
I think you are right since in every function I tired to add BaseEntity.getBonePosition() it gives me same error.

'cs::Vector3 cs::Hacks::aimAnglesTo(cs::BaseEntity &,cs::Vector3 &)': cannot convert argument 2 from 'cs::Vector3' to 'cs::Vector3 &'


aimAnglesTo()
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
  Vector3 Hacks::aimAnglesTo(BaseEntity& localPlayer, Vector3& target)
  {
    Vector3 localPosition = localPlayer.getAbsolutePosition();

    Vector3 punchAngles = localPlayer.getAimPunch();

    Vector3 dPosition = localPosition - target;

    double hypotenuse = sqrt(dPosition(0)*dPosition(0) + dPosition(1)*dPosition(1));

    Vector3 a((float)(atan2f(dPosition(2), hypotenuse) * 57.295779513082f), (float)(atanf(dPosition(1) / dPosition(0)) * 57.295779513082f), 0);

    if (dPosition(0) >= 0.f)
      a(1) += 180.0f;

    Vector3 aimAngles;
    aimAngles(0) = a(0);     // up and down
    aimAngles(1) = a(1);      // left and right

    aimAngles(0) -= punchAngles(0) * 2;
    aimAngles(1) -= punchAngles(1) * 2;

    normalizeAngles(aimAngles);
    clampAngles(aimAngles);

    aimAngles(2) = 0.f;
    return aimAngles;
  }



1
2
3
4
5
6
7
8
9
10
11
  Vector3 BaseEntity::getBonePosition(uint32_t boneId)
  {
    uint32_t boneBase = memory->read<DWORD>(base + netvars::m_dwBoneMatrix);

    Vector3 bonePosition;
    bonePosition(0) = memory->read<float>(boneBase + 0x30 * boneId + 0x0C);
    bonePosition(1) = memory->read<float>(boneBase + 0x30 * boneId + 0x1C);
    bonePosition(2) = memory->read<float>(boneBase + 0x30 * boneId + 0x2C);

    return bonePosition;
  }

Do you understand why you can't take a reference to an anonoymous temporary object? If not, then I strongly recommend you read up on references, to understand them better. They're an important part of C++.
Last edited on
Make it const correct:
1
2
// Vector3 Hacks::aimAnglesTo(BaseEntity& localPlayer, Vector3& target)
Vector3 Hacks::aimAnglesTo(BaseEntity& localPlayer, const Vector3& target)
> I am trying to make Aimbot for one online game ,
Why? Can't you play fair?
@MikeBoy I know they are important and thanks I will definitely learn about them than I will continue working on this.

@JLBorges Thanks alot :)

@salem c , oh I am playing this game fair for 15years and I dont think I will cheat in it ,I will just try to learn something ,and I think this will be good example since here I can check how does it work in-game.
Last edited on
Topic archived. No new replies allowed.