首页 > 编程语言 >游戏程序报错:表达式必须是可修改的左值

游戏程序报错:表达式必须是可修改的左值

时间:2023-01-23 19:00:48浏览次数:44  
标签:case 左值 CEntity WEAPONTYPE player globals 报错 表达式

提问:

 C++编程:表达式必须是可修改的左值

报错:
①表达式必须是可修改的左值 "weaponType":不能给常量赋值
②表达式必须是可修改的左值 “=”:左操作数必须为左值

如图一:

 

 如图二:

 

 图一:

#include "aimbot.h"
 
#include "../core/globals.h"
#include "../core/interfaces.h"
 
void hacks::RunAimbot(CUserCmd* cmd) noexcept
{
    // check if we are trying to shoot
    if (!(cmd->buttons & CUserCmd::IN_ATTACK))
        return;
 
    if (globals::localPlayer->IsDefusing())
        return;
 
    CEntity* activeWeapon = globals::localPlayer->GetActiveWeapon();
 
    if (!activeWeapon)
        return;
 
    const int weaponType = activeWeapon->GetWeaponType();
 
    switch (weaponType)
    {
    case CEntity::WEAPONTYPE_MACHINEGUN:
    case CEntity::WEAPONTYPE_RIFLE:
    case CEntity::WEAPONTYPE_SHOTGUN:
    case CEntity::WEAPONTYPE_SNIPER:
    case CEntity::WEAPONTYPE_PISTOL:
    {
        if (!activeWeapon->GetClip())
            return;
 
        if (weaponType = CEntity::WEAPONTYPE_SNIPER)
        {
            if (!globals::localPlayer->IsScoped())
                return;
        }
 
        break;
    }
 
    default:
        return;
    }
 

 图二:

CVector bestAngle{ };
    float bestFov{ 5.f };
 
    for (int i = 1; i <= interfaces::globals->maxClients; ++i)
    {
        CEntity* player = interfaces::entityList->GetEntityFromIndex(i);
 
        if (!player)
            continue;
 
        if (player->IsDormant() || !player->IsAlive())
            continue;
 
        if (player->GetTeam() = globals::localPlayer->GetTeam())
            continue;
 
        if (player->HasGunGameImmunity())
            continue;
 
        // player's bone matrix
        CMatrix3x4 bones[128];
        if (!player->SetupBones(bones, 125, 256, interfaces::globals->currentTime))
            continue;
 
        // our eye position
        CVector localEyePostition;
        globals::localPlayer->GetEyePosition(localEyePostition);
 
        // our aim punch
        CVector aimPunch{ };
 
        switch (weaponType)
        {
        case CEntity::WEAPONTYPE_RIFLE:
        case CEntity::WEAPONTYPE_SUBMACHINEGUN:
        case CEntity::WEAPONTYPE_MACHINEGUN:
            globals::localPlayer->GetAimPunch(aimPunch);
        }
 

 

解答:

 判断相等是用两个等于号==不是一个,一个表示赋值,你那两个地方都需要修改为两个等于号==

标签:case,左值,CEntity,WEAPONTYPE,player,globals,报错,表达式
From: https://www.cnblogs.com/dituirenwu/p/17065383.html

相关文章