Другое С/С++ Вопрос - Ответ

0xff65

Участник
36
2

Вложения

  • IMG_3342.jpeg
    IMG_3342.jpeg
    106 KB · Просмотры: 38

0xff65

Участник
36
2
Приветствую, выхожу из машины плагин перестает работать почему-то, pPed->m_pVehicle


C++:
#include "plugin.h"
#include "CWorld.h"
#include "CCamera.h"
#include "extensions/ScriptCommands.h"

using namespace plugin;

class Project5 {
public:
    std::unordered_map<std::uint8_t, std::vector<std::uint8_t>> vKeys = {
        {49, {31, 30}},
        {50, {22, 23, 24, 91}},
        {51, {25, 27, 26}},
        {52, {29}},
        {53, {34, 33}}
    };

    Project5() {
        Events::drawingEvent += [this] {
            if (!isPlayerPlaying() || isInputActive())
                return;

            for (const auto& [key, weapons] : vKeys) {
                if (KeyPressed(key)) {
                    printf("Key: %d\n", key);
                    CPed* pPed = CWorld::Players[CWorld::PlayerInFocus].m_pPed;
                    std::uint32_t nHandle = CPools::GetPedRef(pPed);
                    for (std::uint8_t nWeapon : weapons) {
                        printf("Weapon: %d\n", nWeapon);
                        if (Command<Commands::HAS_CHAR_GOT_WEAPON>(nHandle, nWeapon)) {
                            Command<Commands::SET_CURRENT_CHAR_WEAPON>(nHandle, 0);
                            Command<Commands::SET_CURRENT_CHAR_WEAPON>(nHandle, nWeapon);
                            break;
                        }
                    }
                }
            }
            };
    }

    bool isPlayerPlaying() {
        return CWorld::Players[CWorld::PlayerInFocus].m_pPed != nullptr;
    }

    bool isInputActive() {
        CPed* pPed = CWorld::Players[CWorld::PlayerInFocus].m_pPed;
        return (pPed && pPed->m_pVehicle);
    }
} Project5Plugin;