Examples

From Ark & Atlas Server API
Jump to: navigation, search

Go Back: Plugin_Development

Chat Command Examples

Chat based command with a reply message

#include "API\Atlas\Atlas.h"
#pragma comment(lib, "ArkApi.lib")

void TestCMD(AShooterPlayerController* shooter_controller, FString* message, int mode)
{
 	if (!shooter_controller->PlayerStateField()) return;
	Log::GetLog()->warn("Test Chat Command Called: {}", message->ToString());
	ArkApi::GetApiUtils().SendServerMessage(shooter_controller, FColorList::Green, L"{}, you tried the test command", *ArkApi::GetApiUtils().GetCharacterName(NewPlayer));
}

void Load()
{
	Log::Get().Init("Test Plugin");
	ArkApi::GetCommands().AddChatCommand("/test", &TestCMD);
}

void Unload()
{
	ArkApi::GetCommands().RemoveChatCommand("/test");
}

BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
		Load();
		break;
	case DLL_PROCESS_DETACH:
		Unload();
		break;
	}
	return TRUE;
}

Go Back: Ark

Hook Examples

Sends a welcome message to a player 40 seconds after login

#include "API\Atlas\Atlas.h"
#include "Timer.h"
#pragma comment(lib, "ArkApi.lib")
DECLARE_HOOK(HandleNewPlayer_Implementation, bool, AShooterGameMode*, AShooterPlayerController*, UPrimalPlayerData*, AShooterCharacter*, bool);

void DelayedLoginCallBack(AShooterPlayerController * NewPlayer)
{
	if (NewPlayer)
	{
		ArkApi::GetApiUtils().SendServerMessage(NewPlayer, FColorList::Green, L"{}, Welcome to Server Name Here", *ArkApi::GetApiUtils().GetCharacterName(NewPlayer));
		ArkApi::GetApiUtils().SendNotification(NewPlayer, FColorList::Green, 1, 30, nullptr, L"{}, Welcome to Server Name Here", *ArkApi::GetApiUtils().GetCharacterName(NewPlayer));
	}
}

bool Hook_HandleNewPlayer_Implementation(AShooterGameMode* _this, AShooterPlayerController * NewPlayer, UPrimalPlayerData * PlayerData, AShooterCharacter * PlayerCharacter, bool bIsFromLogin)
{
	Log::GetLog()->warn("Player Logged In !!!!!!!!!");
	API::Timer::Get().DelayExecute(std::bind(DelayedLoginCallBack, NewPlayer), 40);
	return HandleNewPlayer_Implementation_original(_this, NewPlayer, PlayerData, PlayerCharacter, bIsFromLogin);
}

void Load()
{
	Log::Get().Init("Test Plugin");
	ArkApi::GetHooks().SetHook("AShooterGameMode.HandleNewPlayer_Implementation", &Hook_HandleNewPlayer_Implementation, &HandleNewPlayer_Implementation_original);
}

void Unload()
{
	ArkApi::GetHooks().DisableHook("AShooterGameMode.HandleNewPlayer_Implementation", &Hook_HandleNewPlayer_Implementation);
}

BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
		Load();
		break;
	case DLL_PROCESS_DETACH:
		Unload();
		break;
	}
	return TRUE;
}

HTTP Examples

HTTP Get Request

#include "API\Atlas\Atlas.h"
#include "Requests.h"
#pragma comment(lib, "ArkApi.lib")


void GetCallback(bool Success, std::string Result)
{
	Log::GetLog()->info("Ark Server Version: {}", Result);
}


API::Requests::Get().CreateGetRequest("http://arkdedicated.com/version", &GetCallback);

HTTP Post Request

#include "API\Atlas\Atlas.h"
#include "Requests.h"
#pragma comment(lib, "ArkApi.lib")


void PostCallback(bool Success, std::string Result)
{
	Log::GetLog()->info("Ark Server Version: {}", Result);
}


API::Requests::Get().CreatePostRequest("http://arkdedicated.com/version", &PostCallback, "PostDataHere");

Go Back: Plugin_Development