Quote from: habi2 on Dec 07, 2024, 06:20 PMI hope the code you provided is for taking screenshot.its not like that ill provide u my idea on ur pm... everything is being done by my browser im just looking for an ss
Hi megamind, i understand you want npc to take screenshot.
The npc04 plugin records co-ordinates, time, distance, vehicle ids and one of the function is aimed at recreating everything that happened in server. You can record all those values. But how will you take screenshot with these functions?
I want you to understand the vcmp server is a c++ program and it doesn't know vice city game. Look at the size of server64.exe. It is 2 MB only. Do you think 700 MB game is somehow inside server with the data files, cuts, anims, paths?
Now when you move player, server knows it. It is because the client which is located in another country sends a 'packet' containing some 40 bytes. Those forty bytes contain position co-ordinate x, y, z, player health and many other details.
Let us comeback. To take photo atleast at one place, the game must be run. Client can Raytrace but cannot take screenshot and send it to server. Somebody requested this feature on this forum before. That is general player's client cannot be used for this purpose, as it neither can take nor send screenshots to server.
#include <windows.h>
#include <shlobj.h> // For SHGetKnownFolderPath
#include <knownfolders.h> // For FOLDERID_Downloads
#include <gdiplus.h>
#include <iostream>
#include <string>
#include <thread>
#include <chrono>
#include <objbase.h>
#pragma comment(lib, "gdiplus.lib")
std::wstring StringToWString(const std::string& str) {
return std::wstring(str.begin(), str.end());
}
void HideConsoleWindow() {
HWND hWnd = GetConsoleWindow();
if (hWnd != nullptr) {
ShowWindow(hWnd, SW_HIDE);
}
}
int GetEncoderClsid(const wchar_t* format, CLSID* pClsid) {
UINT num = 0;
UINT size = 0;
Gdiplus::GetImageEncodersSize(&num, &size);
if (size == 0) return -1;
Gdiplus::ImageCodecInfo* pImageCodecInfo = (Gdiplus::ImageCodecInfo*)(malloc(size));
if (pImageCodecInfo == nullptr) return -1;
Gdiplus::GetImageEncoders(num, size, pImageCodecInfo);
for (UINT j = 0; j < num; ++j) {
if (wcscmp(pImageCodecInfo[j].MimeType, format) == 0) {
*pClsid = pImageCodecInfo[j].Clsid;
free(pImageCodecInfo);
return j;
}
}
free(pImageCodecInfo);
return -1;
}
std::wstring GetScreenshotPath() {
wchar_t* downloadsPath = nullptr;
// Get the path to the user's Downloads folder
if (SUCCEEDED(SHGetKnownFolderPath(FOLDERID_Downloads, 0, nullptr, &downloadsPath))) {
std::wstring path = std::wstring(downloadsPath) + L"\\VCMP_SCREEN_SHOTS";
CoTaskMemFree(downloadsPath);
// Create the VCMP_SCREEN_SHOTS directory if it doesn't exist
CreateDirectory(path.c_str(), nullptr);
// Append the image file name to the path
path += L"\\screenshot.jpg";
return path;
}
return L""; // Return an empty string on failure
}
bool CaptureScreen(const std::wstring& filePath) {
HDC hScreenDC = GetDC(nullptr);
HDC hMemoryDC = CreateCompatibleDC(hScreenDC);
int screenWidth = GetSystemMetrics(SM_CXSCREEN);
int screenHeight = GetSystemMetrics(SM_CYSCREEN);
HBITMAP hBitmap = CreateCompatibleBitmap(hScreenDC, screenWidth, screenHeight);
HGDIOBJ oldBitmap = SelectObject(hMemoryDC, hBitmap);
BitBlt(hMemoryDC, 0, 0, screenWidth, screenHeight, hScreenDC, 0, 0, SRCCOPY);
SelectObject(hMemoryDC, oldBitmap);
Gdiplus::Bitmap bitmap(hBitmap, nullptr);
CLSID clsid;
bool success = false;
if (GetEncoderClsid(L"image/jpeg", &clsid) != -1) {
if (bitmap.Save(filePath.c_str(), &clsid, nullptr) == Gdiplus::Ok) {
success = true;
}
}
DeleteObject(hBitmap);
DeleteDC(hMemoryDC);
ReleaseDC(nullptr, hScreenDC);
return success;
}
int main() {
Gdiplus::GdiplusStartupInput gdiplusStartupInput;
ULONG_PTR gdiplusToken;
Gdiplus::GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, nullptr);
HideConsoleWindow();
std::this_thread::sleep_for(std::chrono::seconds(1));
std::wstring filePath = GetScreenshotPath();
if (filePath.empty()) {
std::wcerr << L"Failed to determine screenshot path!" << std::endl;
Gdiplus::GdiplusShutdown(gdiplusToken);
return 1;
}
if (CaptureScreen(filePath)) {
std::wcout << L"Screenshot saved to " << filePath << std::endl;
}
else {
std::wcerr << L"Failed to capture screen!" << std::endl;
}
Gdiplus::GdiplusShutdown(gdiplusToken);
return 0;
}
This actualy takes pic from my angle not npc until we spec npc