Hey guys, I've recently gotten into gmod modding in C++ and am just wondering how I could print out my health to console.
So far, printing to console is working completely fine, and I have a lot of history with modding source engine and c++. But when I do something like this it crashes:
Here is my code
PHP Code:
#pragma once
#include <iostream>
#include <Windows.h>
#include "GarrysMod/Lua/Interface.h"
#include "GarrysMod/Lua/Types.h"
#include "GarrysMod/Lua/UserData.h"
#include "GarrysMod/Lua/LuaBase.h"
#include "cbase.h"
using namespace GarrysMod::Lua;
#define LOADINTERFACE(_module_, _version_, _out_) Sys_LoadInterface(_module_, _version_, NULL, reinterpret_cast<void**>(& _out_ ))
namespace GOGL
{
void GOGL_Print(const char* msg, ...)
{
ConColorMsg(Color(25, 25, 245, 255), msg);
}
int GOGL_HealthPrint()
{
IClientEntityList* entList = (IClientEntityList*)LOADINTERFACE("client.dll", VCLIENTENTITYLIST_INTERFACE_VERSION, entList);
IVEngineClient* eng = (IVEngineClient*)LOADINTERFACE("engine.dll", VENGINE_CLIENT_INTERFACE_VERSION_13, eng);
CBaseEntity* baseEnt = (CBaseEntity*)entList->GetClientEntity(eng->GetLocalPlayer());
GOGL::GOGL_Print("%i\n", baseEnt->GetHealth());
return 1;
}
}
It causes an error, and that error is (from visual studios 2013 debugger):
PHP Code:
First-chance exception at 0x359C1303 (gmcl_gogl5_win32.dll) in hl2.exe: 0xC0000005: Access violation reading location 0x00000001.
It should be working, but its obviously not. Thanks! All helps appreciated!
__________________