In this tutorial I will show you how you create a Manager class for example players,monsters, npcs, objects etc etc.
As example we will create a player manager function.
Ok first we create 2 files called PlayerManager.h and PlayerManager.cpp
Now open the PlayerManager.h and paste this into it:
Now safe and open GameServer.h and go to the top of the file where you can see
bellow it you write
So it will look like this:
Now you go to the function:
In Akcore files its looking like this:
change to:
Now we work on PlayerManager.cpp file
Now your player manager should be done!
You have now your own thread and a playermanager.
What is this good for?
Example:
There is a loop running, you can add your player list into there and do checks for every player without issues!
Example:
pPlayer->CheckIfPcHealth()
^
this could be a function to check players health and do whatever you want.
You also can add timers (which is a must)
As example we will create a player manager function.
Ok first we create 2 files called PlayerManager.h and PlayerManager.cpp

Now open the PlayerManager.h and paste this into it:
Code:
#pragma once
#include "PlayerInfos.h"
#include "NtlThread.h"
class CPlayerManager : /*public PlayerInfos,*/ public CNtlRunObject
{
public:
CPlayerManager();
~CPlayerManager();
public:
void Init();
void Release();
void CreatePlayerThread();
void Run();
private:
bool m_bRun;
CNtlThread * pThread;
};
extern CPlayerManager * g_pPlayerManager;
Now safe and open GameServer.h and go to the top of the file where you can see
Code:
#pragma once
Code:
#include "PlayerManager.h"
So it will look like this:
Code:
#pragma once
#include "PlayerManager.h"
Now you go to the function:
Code:
int OnAppStart()
In Akcore files its looking like this:
Code:
int OnAppStart()
{
dwThreadId = 0;
if(CreateTableContainer(1))
{
return NTL_SUCCESS;
}else{
printf("FAILED LOADING TABLES !!! \n");
return NTL_SUCCESS;
}
}
change to:
Code:
int OnAppStart()
{
dwThreadId = 0;
if(CreateTableContainer(1))
{
NTL_PRINT(PRINT_APP, "Create Player Manager");
g_pPlayerManager = new CPlayerManager;
g_pPlayerManager->Init();
return NTL_SUCCESS;
}else{
printf("FAILED LOADING TABLES !!! \n");
return NTL_SUCCESS;
}
}
Now we work on PlayerManager.cpp file
Code:
// PlayerManager.cpp: implementation of the CPlayerManager class.
// By Daneos @ RageZone
//////////////////////////////////////////////////////////////////////
#include "Stdafx.h"
#include "GameServer.h"
CPlayerManager* g_pPlayerManager = NULL;
CPlayerManager::CPlayerManager()
{
m_bRun = true;
}
CPlayerManager::~CPlayerManager()
{
Release();
}
void CPlayerManager::Init()
{
CreatePlayerThread();
}
void CPlayerManager::Release()
{
}
void CPlayerManager::Run()
{
CGameServer * app = (CGameServer*) NtlSfxGetApp();
while( m_bRun )
{
Sleep(100);
}
}
void CPlayerManager::CreatePlayerThread()
{
pThread = CNtlThreadFactory::CreateThread( this , "CPMThread" );
pThread->Start();
}
Now your player manager should be done!
You have now your own thread and a playermanager.
What is this good for?
Example:
There is a loop running, you can add your player list into there and do checks for every player without issues!
Example:
Code:
void CPlayerManager::Run()
{
CGameServer * app = (CGameServer*) NtlSfxGetApp();
while( m_bRun )
{
for( itertype(g_pUserTable->m_map_Player) it = g_pUserTable->m_map_Player.begin(); it != g_pUserTable->m_map_Player.end(); it++ )
{
PlayerInfos* pPlayer = it->second;
if (pPlayer)
{
// pPlayer->CheckIfPcHealth();
}
}
Sleep(100);
}
}
pPlayer->CheckIfPcHealth()
^
this could be a function to check players health and do whatever you want.
You also can add timers (which is a must)
Code:
if( (timeGetTime() - pPlayer->dwRecoverLpEpCheckTime) >= 2000)
{
}
Code:
void CPlayerManager::Run()
{
CGameServer * app = (CGameServer*) NtlSfxGetApp();
while( m_bRun )
{
for( itertype(g_pUserTable->m_map_Player) it = g_pUserTable->m_map_Player.begin(); it != g_pUserTable->m_map_Player.end(); it++ )
{
PlayerInfos* pPlayer = it->second;
if (pPlayer)
{
if( (timeGetTime() - pPlayer->dwRecoverLpEpCheckTime) >= 2000)
{
// pPlayer->CheckIfPcHealth();
}
}
}
Sleep(100);
}
}