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

Обратите внимание, пользователь заблокирован на форуме. Не рекомендуется проводить сделки.
Последнее редактирование:
  • Нравится
Реакции: 4el0ve4ik

kjor32

¯\_(ツ)_/¯
Всефорумный модератор
1,686
1,395
Как можно проверить сидит ли мой пед в транспорте?
 

Dheyker

Новичок
14
0
How to do this in C++?
Lua:
local inicfg = require "inicfg"

local color  =  imgui.ImFloat4(mainIni.color.R/255, mainIni.color.G/255, mainIni.color.B/255, 255)

if imgui.ColorEdit4('Color', color) then
   local clr = join_argb(0, color.v[1] * 255, color.v[2] * 255, color.v[3] * 255, color.v[4] * 255)
   local r,g,b,a = color.v[1] * 255, color.v[2] * 255, color.v[3] * 255, color.v[4] * 255
   mainIni.config.hex = ("%06X"):format(clr)
   mainIni.color.R = r
   mainIni.color.G = g
   mainIni.color.B = b      
   inicfg.save(mainIni, directIni)
end
 

!Sam#0235

Активный
121
39
Can someone help me rewrite these .lua snippets in C++? I tried it on my own but it didn't work
Lua:
   if move == true then
   cursor()
   repeat
   wait(0)
   cursorx, cursory = getCursorPos()
   sampToggleCursor(1)
   Ini.cfg.x = cursorx
   Ini.cfg.y = cursory                                                        
   if isKeyDown(27) then move = 0 end
   until isKeyDown(32)
   sampToggleCursor(0)
   sampSetCursorMode(0)              
   move = false          
   Ini.cfg.x = cursorx
   Ini.cfg.y = cursory
   inicfg.save(Ini, MyIni)
end
Lua:
function cursor()
        local x, y = getScreenResolution()
        local x = x / 2
        local y = x / 2
        --  local x = x - 100
        local y = y - -70
        local result, lib = loadDynamicLibrary("user32.dll")
        if result then
        local result, proc = getDynamicLibraryProcedure("SetCursorPos", lib)
        local a = callFunction(proc, 2, 0, x,y)
        freeDynamicLibrary(lib)
    end
end
 
Последнее редактирование:
  • Вау
Реакции: qdIbp

YaAkeGGa228

Участник
60
35
нужна помощь, не понимаю как параметры ввести юзеру.
так бы на луа выглядило:
lua:
sampRegisterChatCommand('cmd', function(arg)
    if arg:match('%d+:%d+:%d+:%d+') then
        a,b.c.e = arg:match('(%d+):(%d+):(%d+):(%d+)')
    else
        sampAddChatMessage('invalid parameters', -1)
    end
end)
а на плюсах я делаю что то типо:
cpp(sf):
SF->getSAMP()->registerChatCommand("cmd", [](std::string param) {
    SF->getSAMP()->getChat()->AddChatMessage(-1, "param: %s", param.c_str());
});
Но как юзеру вводить 4 аргумента, а так же проверять, верно ли он ввел?
 

YaAkeGGa228

Участник
60
35
Если хотя бы один аргумент не может быть преобразован в число, мы выводим сообщение об ошибке
Lua:
sampRegisterChatCommand('cmd', function(arg)
    local args = arg:split(":")
    if #args == 4 then
        local a,b,c,e = tonumber(args[1]), tonumber(args[2]), tonumber(args[3]), tonumber(args[4])
        if a and b and c and e then
            -- все аргументы были успешно преобразованы в числа
            -- здесь можно использовать a, b, c, e в качестве аргументов для дальнейшей обработки
        else
            sampAddChatMessage('invalid parameters', -1)
        end
    else
        sampAddChatMessage('invalid parameters', -1)
    end
end)
C++ :
C++:
void cmd(std::string arg) {
    std::vector<std::string> args = split(arg, ":");
    if (args.size() == 4) {
        int a = std::stoi(args[0]);
        int b = std::stoi(args[1]);
        int c = std::stoi(args[2]);
        int e = std::stoi(args[3]);
        if (a && b && c && e) {
            // все аргументы были успешно преобразованы в числа
            // здесь можно использовать a, b, c, e в качестве аргументов для дальнейшей обработки
        } else {
            sampAddChatMessage("invalid parameters", -1);
        }
    } else {
        sampAddChatMessage("invalid parameters", -1);
    }
}
Или
C++:
void cmd(std::string arg) {
    std::vector<std::string> args = split(arg, ":");
    if (args.size() == 4 && std::all_of(args.begin(), args.end(), [](const std::string& s) {
            return !s.empty() && std::all_of(s.begin(), s.end(), [](char c) { return std::isdigit(c); });
        })) {
        int a = std::stoi(args[0]);
        int b = std::stoi(args[1]);
        int c = std::stoi(args[2]);
        int e = std::stoi(args[3]);
        // все аргументы были успешно преобразованы в числа
        // здесь можно использовать a, b, c, e в качестве аргументов для дальнейшей обработки
    } else {
        sampAddChatMessage("invalid parameters", -1);
    }
}
нужна помощь, не понимаю как параметры ввести юзеру.
так бы на луа выглядило:
lua:
sampRegisterChatCommand('cmd', function(arg)
    if arg:match('%d+:%d+:%d+:%d+') then
        a,b.c.e = arg:match('(%d+):(%d+):(%d+):(%d+)')
    else
        sampAddChatMessage('invalid parameters', -1)
    end
end)
а на плюсах я делаю что то типо:
cpp(sf):
SF->getSAMP()->registerChatCommand("cmd", [](std::string param) {
    SF->getSAMP()->getChat()->AddChatMessage(-1, "param: %s", param.c_str());
});
Но как юзеру вводить 4 аргумента, а так же проверять, верно ли он ввел?
cpp:
void __stdcall cmd(std::string arg) {
    std::regex ip_regex("\\d+\\:\\d+\\:\\d+\\:\\d+");
    std::smatch match;
    if (std::regex_search(arg, match, ip_regex)) {
        std::string ip = match[0];
        std::regex time_regex("(\\d+):(\\d+):(\\d+):(\\d+)");
        if (std::regex_search(ip, match, time_regex)) {
            int a = std::stoi(match[1]);
            int b = std::stoi(match[2]);
            int c = std::stoi(match[3]);
            int e = std::stoi(match[4]);
            SF->getSAMP()->getChat()->AddChatMessage(-1, "%d %d %d %d", a, b, c, e);
        }
        else {
            SF->getSAMP()->getDialog()->ShowDialog(1234, DIALOG_STYLE_MSGBOX, "назв", "текст", "далее", "отмена");
        }
    }
    else {
        SF->getSAMP()->getDialog()->ShowDialog(1234, DIALOG_STYLE_MSGBOX, "назв", "текст", "далее", "отмена");
    }
}

//Вызывать: SF->getSAMP()->registerChatCommand("capturwik", cmd);
мб кому то надо, а так же себе на будущее
 

Dheyker

Новичок
14
0
How to do this in C++?
Lua:
local inicfg = require "inicfg"

local color  =  imgui.ImFloat4(mainIni.color.R/255, mainIni.color.G/255, mainIni.color.B/255, 255)

if imgui.ColorEdit4('Color', color) then
   local clr = join_argb(0, color.v[1] * 255, color.v[2] * 255, color.v[3] * 255, color.v[4] * 255)
   local r,g,b,a = color.v[1] * 255, color.v[2] * 255, color.v[3] * 255, color.v[4] * 255
   mainIni.config.hex = ("%06X"):format(clr)
   mainIni.color.R = r
   mainIni.color.G = g
   mainIni.color.B = b     
   inicfg.save(mainIni, directIni)
end
up
 

kjor32

¯\_(ツ)_/¯
Всефорумный модератор
1,686
1,395
Как вывести сообщение в консоль сф? если в луа это просто print()
 

Dzho_Handerson

Новичок
6
0
Приветствую, подскажите как удалить лишние пункты из меню esc samp через asi? Source code
 
Последнее редактирование:

LorianS1

Новичок
8
4
How to do this in C++?
Lua:
local inicfg = require "inicfg"

local color  =  imgui.ImFloat4(mainIni.color.R/255, mainIni.color.G/255, mainIni.color.B/255, 255)

if imgui.ColorEdit4('Color', color) then
   local clr = join_argb(0, color.v[1] * 255, color.v[2] * 255, color.v[3] * 255, color.v[4] * 255)
   local r,g,b,a = color.v[1] * 255, color.v[2] * 255, color.v[3] * 255, color.v[4] * 255
   mainIni.config.hex = ("%06X"):format(clr)
   mainIni.color.R = r
   mainIni.color.G = g
   mainIni.color.B = b    
   inicfg.save(mainIni, directIni)
end
C++:
#include <iostream>
#include <Windows.h>
#include <string>
#include <sstream>
#include <iomanip>

#include "inih/INIReader.h"
#include "imgui/imgui.h"

// A function that combines the values of the color components into a single number
DWORD JoinARGB(BYTE a, BYTE r, BYTE g, BYTE b)
{
    return ((a & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF);
}

int main()
{
    INIReader mainIni("config.ini");

    ImVec4 color(mainIni.GetReal("color", "R", 0) / 255.0f, mainIni.GetReal("color", "G", 0) / 255.0f, mainIni.GetReal("color", "B", 0) / 255.0f, 1.0f);

    if (ImGui::ColorEdit4("Color", (float*)&color))
    {
        DWORD clr = JoinARGB(0, static_cast<BYTE>(color.x * 255), static_cast<BYTE>(color.y * 255), static_cast<BYTE>(color.z * 255));
        mainIni.Set("config", "hex", ("#%02X%02X%02X").c_str(), static_cast<BYTE>(color.x * 255), static_cast<BYTE>(color.y * 255), static_cast<BYTE>(color.z * 255));
        mainIni.SetReal("color", "R", static_cast<double>(color.x * 255));
        mainIni.SetReal("color", "G", static_cast<double>(color.y * 255));
        mainIni.SetReal("color", "B", static_cast<double>(color.z * 255));
        mainIni.SaveFile("config.ini");
    }

    return 0;
}
 
  • Эм
  • Нравится
Реакции: Dheyker и AdCKuY_DpO4uLa

LorianS1

Новичок
8
4
Can someone help me rewrite these .lua snippets in C++? I tried it on my own but it didn't work
Lua:
   if move == true then
   cursor()
   repeat
   wait(0)
   cursorx, cursory = getCursorPos()
   sampToggleCursor(1)
   Ini.cfg.x = cursorx
   Ini.cfg.y = cursory                                                       
   if isKeyDown(27) then move = 0 end
   until isKeyDown(32)
   sampToggleCursor(0)
   sampSetCursorMode(0)             
   move = false         
   Ini.cfg.x = cursorx
   Ini.cfg.y = cursory
   inicfg.save(Ini, MyIni)
end
Lua:
function cursor()
        local x, y = getScreenResolution()
        local x = x / 2
        local y = x / 2
        --  local x = x - 100
        local y = y - -70
        local result, lib = loadDynamicLibrary("user32.dll")
        if result then
        local result, proc = getDynamicLibraryProcedure("SetCursorPos", lib)
        local a = callFunction(proc, 2, 0, x,y)
        freeDynamicLibrary(lib)
    end
end
sure.

1.

C++:
#include "inicfg.h"

ImVec4 color(mainIni.color.R/255.0f, mainIni.color.G/255.0f, mainIni.color.B/255.0f, 1.0f);

if (ImGui::ColorEdit4("Color", &color.x))
{
    int clr = join_argb(0, color.x * 255, color.y * 255, color.z * 255, color.w * 255);
    int r = color.x * 255, g = color.y * 255, b = color.z * 255, a = color.w * 255;
    mainIni.config.hex = ("%06X").format(clr);
    mainIni.color.R = r;
    mainIni.color.G = g;
    mainIni.color.B = b;
    inicfg::save(mainIni, directIni);
}
2.
C++:
#include <Windows.h>

void cursor() {
    int x = GetSystemMetrics(SM_CXSCREEN) / 2;
    int y = GetSystemMetrics(SM_CYSCREEN) / 2;
    // x = x - 100; // uncomment this line if you want to move the cursor to the left by 100px
    y = y + 70; // moves the cursor 70 pixels down
    SetCursorPos(x, y); // set the cursor to a new position
}
p.s
In this code, we use the GetSystemMetrics WinAPI function to get the screen resolution, and then use the SetCursorPos function to move the cursor to the specified location. By default, the cursor will be shifted 70 pixels down. If you want to move the cursor to the left by 100 pixels, then uncomment the line x = x - 100;.
 
  • Нравится
Реакции: !Sam#0235