2015-09-30 02:56:11 +02:00
|
|
|
#include "Core.hpp"
|
|
|
|
#include "Logger.hpp"
|
|
|
|
#include "Entity.hpp"
|
|
|
|
#include "Register.hpp"
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#include "Base/Color3.hpp"
|
|
|
|
#include "Base/Vector2i.hpp"
|
|
|
|
#include "Misc/Automobile.hpp"
|
|
|
|
#include "Misc/Model.hpp"
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#include <SimpleIni.h>
|
|
|
|
#include <format.h>
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#include <sqstdio.h>
|
|
|
|
#include <sqstdblob.h>
|
|
|
|
#include <sqstdmath.h>
|
|
|
|
#include <sqstdsystem.h>
|
|
|
|
#include <sqstdstring.h>
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#include <cstdarg>
|
|
|
|
#include <sstream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <exception>
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
const Core::Pointer _Core = Core::Inst();
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
static std::shared_ptr<CSimpleIni> g_Config;
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Core::Core() noexcept
|
|
|
|
: m_State(SQMOD_SUCCESS)
|
|
|
|
, m_Options()
|
|
|
|
, m_VM(nullptr)
|
|
|
|
, m_RootTable(nullptr)
|
|
|
|
, m_Scripts()
|
|
|
|
, m_ErrorMsg()
|
|
|
|
, m_PlayerTrack()
|
|
|
|
, m_VehicleTrack()
|
|
|
|
{
|
|
|
|
// Create a few shared buffers
|
|
|
|
MakeBuffer(8);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Core::~Core()
|
|
|
|
{
|
|
|
|
this->Terminate();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::_Finalizer(Core * ptr) noexcept
|
|
|
|
{
|
|
|
|
if (ptr) delete ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Core::Pointer Core::Inst() noexcept
|
|
|
|
{
|
|
|
|
if (!_Core)
|
|
|
|
{
|
|
|
|
return Pointer(new Core(), &Core::_Finalizer);
|
|
|
|
}
|
2015-10-02 00:34:28 +02:00
|
|
|
|
2015-09-30 02:56:11 +02:00
|
|
|
return Pointer(nullptr, &Core::_Finalizer);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool Core::Init() noexcept
|
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
LogMsg("%s", CenterStr("INITIALIZING", '*'));
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
if (!this->Configure() || !this->CreateVM() || !this->LoadScripts())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-25 02:20:33 +02:00
|
|
|
LogMsg("%s", CenterStr("SUCCESS", '*'));
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Core::Load() noexcept
|
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
LogMsg("%s", CenterStr("LOADING", '*'));
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
if (!this->Execute())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-25 02:20:33 +02:00
|
|
|
LogMsg("%s", CenterStr("SUCCESS", '*'));
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::Deinit() noexcept
|
|
|
|
{
|
|
|
|
this->DestroyVM();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Core::Unload() noexcept
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::Terminate() noexcept
|
|
|
|
{
|
|
|
|
this->Deinit();
|
|
|
|
this->Unload();
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::SetState(SQInteger val) noexcept
|
|
|
|
{
|
|
|
|
m_State = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
SQInteger Core::GetState() const noexcept
|
|
|
|
{
|
|
|
|
return m_State;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
string Core::GetOption(const string & name) const noexcept
|
|
|
|
{
|
|
|
|
OptionPool::const_iterator elem = m_Options.find(name);
|
|
|
|
return (elem == m_Options.cend()) ? string() : elem->second;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Core::SetOption(const string & name, const string & value) noexcept
|
|
|
|
{
|
|
|
|
m_Options[name] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Core::Buffer Core::PullBuffer(unsigned sz) noexcept
|
|
|
|
{
|
|
|
|
Buffer buf;
|
|
|
|
if (m_BufferPool.empty())
|
|
|
|
{
|
|
|
|
buf.resize(sz);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buf = std::move(m_BufferPool.back());
|
|
|
|
m_BufferPool.pop();
|
|
|
|
}
|
|
|
|
return std::move(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::PushBuffer(Buffer && buf) noexcept
|
|
|
|
{
|
|
|
|
m_BufferPool.push(std::move(buf));
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::MakeBuffer(unsigned num, unsigned sz) noexcept
|
|
|
|
{
|
|
|
|
while (num--)
|
|
|
|
{
|
|
|
|
m_BufferPool.emplace(sz);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::ConnectPlayer(SQInt32 id, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
// Attempt to activate the instance in the plugin at the received identifier
|
|
|
|
if (EntMan< CPlayer >::Activate(id, false))
|
|
|
|
{
|
|
|
|
// Trigger the specific event
|
|
|
|
OnPlayerCreated(id, header, payload);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LogErr("Unable to create a new <CPlayer> instance");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::DisconnectPlayer(SQInt32 id, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
// Check to be sure we have this player instance active
|
|
|
|
if (Reference< CPlayer >::Verify(id))
|
|
|
|
{
|
|
|
|
// Trigger the specific event
|
|
|
|
OnPlayerDestroyed(id, header, payload);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool Core::Configure() noexcept
|
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
LogDbg("Attempting to instantiate the configuration file");
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
if (g_Config)
|
|
|
|
{
|
|
|
|
g_Config->Reset();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_Config.reset(new CSimpleIniA(true, true, true));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!g_Config)
|
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
LogFtl("Unable to instantiate the configuration class");
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-25 02:20:33 +02:00
|
|
|
LogDbg("Attempting to load the configuration file.");
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
SI_Error ini_ret = g_Config->LoadFile(_SC("./sqmod.ini"));
|
|
|
|
|
|
|
|
if (ini_ret < 0)
|
|
|
|
{
|
|
|
|
switch (ini_ret)
|
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
case SI_FAIL: LogErr("Failed to load the configuration file. Probably invalid"); break;
|
|
|
|
case SI_NOMEM: LogErr("Run out of memory while loading the configuration file"); break;
|
|
|
|
case SI_FILE: LogErr("Failed to load the configuration file. %s", strerror(errno)); break;
|
|
|
|
default: LogErr("Failed to load the configuration file for some unforeseen reason");
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-25 02:20:33 +02:00
|
|
|
LogDbg("Applying the specified logging filters");
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
if (!SToB(g_Config->GetValue("ConsoleLog", "Debug", "true"))) _Log->DisableConsoleLevel(Logger::LEVEL_DBG);
|
|
|
|
if (!SToB(g_Config->GetValue("ConsoleLog", "Message", "true"))) _Log->DisableConsoleLevel(Logger::LEVEL_MSG);
|
|
|
|
if (!SToB(g_Config->GetValue("ConsoleLog", "Success", "true"))) _Log->DisableConsoleLevel(Logger::LEVEL_SCS);
|
|
|
|
if (!SToB(g_Config->GetValue("ConsoleLog", "Info", "true"))) _Log->DisableConsoleLevel(Logger::LEVEL_INF);
|
|
|
|
if (!SToB(g_Config->GetValue("ConsoleLog", "Warning", "true"))) _Log->DisableConsoleLevel(Logger::LEVEL_WRN);
|
|
|
|
if (!SToB(g_Config->GetValue("ConsoleLog", "Error", "true"))) _Log->DisableConsoleLevel(Logger::LEVEL_ERR);
|
|
|
|
if (!SToB(g_Config->GetValue("ConsoleLog", "Fatal", "true"))) _Log->DisableConsoleLevel(Logger::LEVEL_FTL);
|
|
|
|
|
|
|
|
if (!SToB(g_Config->GetValue("FileLog", "Debug", "true"))) _Log->DisableFileLevel(Logger::LEVEL_DBG);
|
|
|
|
if (!SToB(g_Config->GetValue("FileLog", "Message", "true"))) _Log->DisableFileLevel(Logger::LEVEL_MSG);
|
|
|
|
if (!SToB(g_Config->GetValue("FileLog", "Success", "true"))) _Log->DisableFileLevel(Logger::LEVEL_SCS);
|
|
|
|
if (!SToB(g_Config->GetValue("FileLog", "Info", "true"))) _Log->DisableFileLevel(Logger::LEVEL_INF);
|
|
|
|
if (!SToB(g_Config->GetValue("FileLog", "Warning", "true"))) _Log->DisableFileLevel(Logger::LEVEL_WRN);
|
|
|
|
if (!SToB(g_Config->GetValue("FileLog", "Error", "true"))) _Log->DisableFileLevel(Logger::LEVEL_ERR);
|
|
|
|
if (!SToB(g_Config->GetValue("FileLog", "Fatal", "true"))) _Log->DisableFileLevel(Logger::LEVEL_FTL);
|
|
|
|
|
2015-10-25 02:20:33 +02:00
|
|
|
LogDbg("Reading the options from the general section");
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
CSimpleIniA::TNamesDepend general_options;
|
|
|
|
|
|
|
|
if (g_Config->GetAllKeys("Options", general_options) || general_options.size() > 0)
|
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
for (const auto & cfg_option : general_options)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
CSimpleIniA::TNamesDepend option_list;
|
|
|
|
|
|
|
|
if (!g_Config->GetAllValues("Options", cfg_option.pItem, option_list))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
option_list.sort(CSimpleIniA::Entry::LoadOrder());
|
|
|
|
|
2015-10-25 02:20:33 +02:00
|
|
|
for (const auto & cfg_value : option_list)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
m_Options[cfg_option.pItem] = cfg_value.pItem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
LogInf("No options specified in the configuration file");
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool Core::CreateVM() noexcept
|
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
LogDbg("Acquiring the virtual machine stack size");
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
// Start with an unknown stack size
|
|
|
|
SQInteger stack_size = SQMOD_UNKNOWN;
|
|
|
|
|
|
|
|
// Attempt to get it from the configuration file
|
|
|
|
try
|
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
stack_size = SToI< SQInteger >::Fn(GetOption(_SC("VMStackSize")), 0, 10);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
catch (const std::invalid_argument & e)
|
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
LogWrn("Unable to extract option value: %s", e.what());
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Validate the stack size
|
|
|
|
if (stack_size <= 0)
|
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
LogWrn("Invalid stack size. Reverting to default size: %d", SQMOD_STACK_SIZE);
|
2015-09-30 02:56:11 +02:00
|
|
|
SetOption(_SC("VMStackSize"), std::to_string(SQMOD_STACK_SIZE));
|
|
|
|
stack_size = SQMOD_STACK_SIZE;
|
|
|
|
}
|
|
|
|
|
2015-10-25 02:20:33 +02:00
|
|
|
LogInf("Creating a virtual machine with a stack size of: %d", stack_size);
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
m_VM = sq_open(stack_size);
|
|
|
|
|
|
|
|
if (!m_VM)
|
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
LogFtl("Unable to open a virtual machine with a stack size: %d", stack_size);
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DefaultVM::Set(m_VM);
|
|
|
|
ErrorHandling::Enable(true);
|
|
|
|
m_RootTable.reset(new RootTable(m_VM));
|
|
|
|
m_Scripts.clear();
|
|
|
|
}
|
|
|
|
|
2015-10-25 02:20:33 +02:00
|
|
|
LogDbg("Registering the standard libraries");
|
|
|
|
// Register the standard libraries
|
2015-09-30 02:56:11 +02:00
|
|
|
sq_pushroottable(m_VM);
|
|
|
|
sqstd_register_iolib(m_VM);
|
|
|
|
sqstd_register_bloblib(m_VM);
|
|
|
|
sqstd_register_mathlib(m_VM);
|
|
|
|
sqstd_register_systemlib(m_VM);
|
|
|
|
sqstd_register_stringlib(m_VM);
|
|
|
|
sq_pop(m_VM, 1);
|
|
|
|
|
2015-10-25 02:20:33 +02:00
|
|
|
LogDbg("Setting the base output function");
|
|
|
|
// Set the function that handles the text output
|
2015-09-30 02:56:11 +02:00
|
|
|
sq_setprintfunc(m_VM, PrintFunc, ErrorFunc);
|
|
|
|
|
2015-10-25 02:20:33 +02:00
|
|
|
LogDbg("Setting the base error handlers");
|
|
|
|
// Se the error handlers
|
2015-09-30 02:56:11 +02:00
|
|
|
sq_setcompilererrorhandler(m_VM, CompilerErrorHandler);
|
|
|
|
sq_newclosure(m_VM, RuntimeErrorHandler, 0);
|
|
|
|
sq_seterrorhandler(m_VM);
|
|
|
|
|
2015-10-25 02:20:33 +02:00
|
|
|
LogDbg("Registering the plugin API");
|
|
|
|
// Register the plugin API
|
2015-09-30 02:56:11 +02:00
|
|
|
if (!RegisterAPI(m_VM))
|
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
LogFtl("Unable to register the plugin API");
|
2015-09-30 02:56:11 +02:00
|
|
|
return false;
|
|
|
|
}
|
2015-10-25 02:20:33 +02:00
|
|
|
// At this point the VM is ready
|
2015-09-30 02:56:11 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Core::DestroyVM() noexcept
|
|
|
|
{
|
2015-10-03 18:44:26 +02:00
|
|
|
// See if the Virtual Machine wasn't already destroyed
|
2015-10-02 00:34:28 +02:00
|
|
|
if (m_VM != nullptr)
|
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
// Let instances know that they should release links to this VM
|
|
|
|
VMClose.Emit();
|
2015-10-03 18:44:26 +02:00
|
|
|
// Release the references to the script objects
|
|
|
|
m_Scripts.clear();
|
2015-10-25 02:20:33 +02:00
|
|
|
// Release the reference to the root table
|
|
|
|
m_RootTable.reset();
|
|
|
|
// Assertions during close may cause double delete
|
|
|
|
HSQUIRRELVM sq_vm = m_VM;
|
2015-10-03 20:54:34 +02:00
|
|
|
// Explicitly set the virtual machine to null
|
2015-10-02 00:34:28 +02:00
|
|
|
m_VM = nullptr;
|
2015-10-25 02:20:33 +02:00
|
|
|
// Close the Virtual Machine
|
|
|
|
sq_close(sq_vm);
|
2015-10-02 00:34:28 +02:00
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool Core::LoadScripts() noexcept
|
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
LogDbg("Attempting to compile the specified scripts");
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
if (!g_Config)
|
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
LogWrn("Cannot compile any scripts without the configurations");
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSimpleIniA::TNamesDepend script_list;
|
|
|
|
g_Config->GetAllValues("Scripts", "Source", script_list);
|
|
|
|
|
|
|
|
if (script_list.size() <= 0)
|
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
LogWrn("No scripts specified in the configuration file");
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
script_list.sort(CSimpleIniA::Entry::LoadOrder());
|
|
|
|
|
|
|
|
for (auto const & cfg_script : script_list)
|
|
|
|
{
|
|
|
|
string path(cfg_script.pItem);
|
|
|
|
|
|
|
|
if (m_Scripts.find(path) != m_Scripts.cend())
|
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
LogWrn("Script was already loaded: %s", path.c_str());
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (!Compile(path))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
LogScs("Successfully compiled script: %s", path.c_str());
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (m_Scripts.empty())
|
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
LogErr("No scripts compiled. No reason to load the plugin");
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
bool Core::Compile(const string & name) noexcept
|
|
|
|
{
|
|
|
|
if (name.empty())
|
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
LogErr("Cannot compile script without a valid name");
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::pair< SqScriptPool::iterator, bool > res = m_Scripts.emplace(name, Script(m_VM));
|
|
|
|
|
|
|
|
if (res.second)
|
|
|
|
{
|
|
|
|
res.first->second.CompileFile(name);
|
|
|
|
|
|
|
|
if (Error::Occurred(m_VM))
|
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
LogErr("Unable to compile script: %s", name.c_str());
|
|
|
|
LogInf("=> %s", Error::Message(m_VM).c_str());
|
2015-09-30 02:56:11 +02:00
|
|
|
m_Scripts.erase(res.first);
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
LogErr("Unable to queue script: %s", name.c_str());
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Core::Execute() noexcept
|
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
LogDbg("Attempting to execute the specified scripts");
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
for (auto & elem : m_Scripts)
|
|
|
|
{
|
|
|
|
elem.second.Run();
|
|
|
|
|
|
|
|
if (Error::Occurred(m_VM))
|
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
LogErr("Unable to execute script: %s", elem.first.c_str());
|
|
|
|
LogInf("=> %s", Error::Message(m_VM).c_str());
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
LogScs("Successfully executed script: %s", elem.first.c_str());
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::PrintCallstack() noexcept
|
|
|
|
{
|
|
|
|
SQStackInfos si;
|
|
|
|
|
|
|
|
|
2015-10-25 02:20:33 +02:00
|
|
|
LogMsg("%s", CenterStr("CALLSTACK", '*'));
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
for (SQInteger level = 1; SQ_SUCCEEDED(sq_stackinfos(m_VM, level, &si)); ++level)
|
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
LogInf("FUNCTION %s()", si.funcname ? si.funcname : _SC("unknown"));
|
|
|
|
LogInf("=> [%d] : {%s}", si.line, si.source ? si.source : _SC("unknown"));
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const SQChar * s_ = 0, * name = 0;
|
|
|
|
SQInteger i_, seq = 0;
|
|
|
|
SQFloat f_;
|
|
|
|
SQUserPointer p_;
|
|
|
|
|
2015-10-25 02:20:33 +02:00
|
|
|
LogMsg("%s", CenterStr("LOCALS", '*'));
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
for (SQInteger level = 0; level < 10; level++) {
|
|
|
|
seq = 0;
|
|
|
|
while((name = sq_getlocal(m_VM, level, seq))) {
|
|
|
|
++seq;
|
|
|
|
switch(sq_gettype(m_VM, -1))
|
|
|
|
{
|
|
|
|
case OT_NULL:
|
2015-10-25 02:20:33 +02:00
|
|
|
LogInf("NULL [%s] : ...", name);
|
2015-09-30 02:56:11 +02:00
|
|
|
break;
|
|
|
|
case OT_INTEGER:
|
|
|
|
sq_getinteger(m_VM, -1, &i_);
|
2015-10-25 02:20:33 +02:00
|
|
|
LogInf("INTEGER [%s] : {%d}", name, i_);
|
2015-09-30 02:56:11 +02:00
|
|
|
break;
|
|
|
|
case OT_FLOAT:
|
|
|
|
sq_getfloat(m_VM, -1, &f_);
|
2015-10-25 02:20:33 +02:00
|
|
|
LogInf("FLOAT [%s] : {%f}", name, f_);
|
2015-09-30 02:56:11 +02:00
|
|
|
break;
|
|
|
|
case OT_USERPOINTER:
|
|
|
|
sq_getuserpointer(m_VM, -1, &p_);
|
2015-10-25 02:20:33 +02:00
|
|
|
LogInf("USERPOINTER [%s] : {%p}\n", name, p_);
|
2015-09-30 02:56:11 +02:00
|
|
|
break;
|
|
|
|
case OT_STRING:
|
|
|
|
sq_getstring(m_VM, -1, &s_);
|
2015-10-25 02:20:33 +02:00
|
|
|
LogInf("STRING [%s] : {%s}", name, s_);
|
2015-09-30 02:56:11 +02:00
|
|
|
break;
|
|
|
|
case OT_TABLE:
|
2015-10-25 02:20:33 +02:00
|
|
|
LogInf("TABLE [%s] : ...", name);
|
2015-09-30 02:56:11 +02:00
|
|
|
break;
|
|
|
|
case OT_ARRAY:
|
2015-10-25 02:20:33 +02:00
|
|
|
LogInf("ARRAY [%s] : ...", name);
|
2015-09-30 02:56:11 +02:00
|
|
|
break;
|
|
|
|
case OT_CLOSURE:
|
2015-10-25 02:20:33 +02:00
|
|
|
LogInf("CLOSURE [%s] : ...", name);
|
2015-09-30 02:56:11 +02:00
|
|
|
break;
|
|
|
|
case OT_NATIVECLOSURE:
|
2015-10-25 02:20:33 +02:00
|
|
|
LogInf("NATIVECLOSURE [%s] : ...", name);
|
2015-09-30 02:56:11 +02:00
|
|
|
break;
|
|
|
|
case OT_GENERATOR:
|
2015-10-25 02:20:33 +02:00
|
|
|
LogInf("GENERATOR [%s] : ...", name);
|
2015-09-30 02:56:11 +02:00
|
|
|
break;
|
|
|
|
case OT_USERDATA:
|
2015-10-25 02:20:33 +02:00
|
|
|
LogInf("USERDATA [%s] : ...", name);
|
2015-09-30 02:56:11 +02:00
|
|
|
break;
|
|
|
|
case OT_THREAD:
|
2015-10-25 02:20:33 +02:00
|
|
|
LogInf("THREAD [%s] : ...", name);
|
2015-09-30 02:56:11 +02:00
|
|
|
break;
|
|
|
|
case OT_CLASS:
|
2015-10-25 02:20:33 +02:00
|
|
|
LogInf("CLASS [%s] : ...", name);
|
2015-09-30 02:56:11 +02:00
|
|
|
break;
|
|
|
|
case OT_INSTANCE:
|
2015-10-25 02:20:33 +02:00
|
|
|
LogInf("INSTANCE [%s] : ...", name);
|
2015-09-30 02:56:11 +02:00
|
|
|
break;
|
|
|
|
case OT_WEAKREF:
|
2015-10-25 02:20:33 +02:00
|
|
|
LogInf("WEAKREF [%s] : ...", name);
|
2015-09-30 02:56:11 +02:00
|
|
|
break;
|
|
|
|
case OT_BOOL:
|
|
|
|
sq_getinteger(m_VM, -1, &i_);
|
2015-10-25 02:20:33 +02:00
|
|
|
LogInf("BOOL [%s] : {%s}", name, i_ ? _SC("true") : _SC("false"));
|
2015-09-30 02:56:11 +02:00
|
|
|
break;
|
|
|
|
default:
|
2015-10-25 02:20:33 +02:00
|
|
|
LogErr("UNKNOWN [%s] : ...", name);
|
2015-09-30 02:56:11 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
sq_pop(m_VM, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::PrintFunc(HSQUIRRELVM vm, const SQChar * str, ...) noexcept
|
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
// Prepare the arguments list
|
2015-09-30 02:56:11 +02:00
|
|
|
va_list args;
|
|
|
|
va_start(args, str);
|
2015-10-25 02:20:33 +02:00
|
|
|
// Acquire a buffer from the buffer pool
|
|
|
|
Core::Buffer vbuf = _Core->PullBuffer();
|
|
|
|
// Attempt to process the specified format string
|
|
|
|
SQInt32 fmt_ret = std::vsnprintf(vbuf.data(), vbuf.size(), str, args);
|
|
|
|
// See if the formatting was successful
|
2015-09-30 02:56:11 +02:00
|
|
|
if (fmt_ret < 0)
|
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
// Return the buffer back to the buffer pool
|
|
|
|
_Core->PushBuffer(std::move(vbuf));
|
|
|
|
LogErr("Format error");
|
2015-09-30 02:56:11 +02:00
|
|
|
return;
|
|
|
|
}
|
2015-10-25 02:20:33 +02:00
|
|
|
// See if the buffer was big enough
|
|
|
|
else if (_SCSZT(fmt_ret) > vbuf.size())
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
// Resize the buffer to accomodate the required size
|
|
|
|
vbuf.resize(++fmt_ret);
|
|
|
|
// Attempt to process the specified format string again
|
|
|
|
fmt_ret = std::vsnprintf(vbuf.data(), vbuf.size(), str, args);
|
|
|
|
// See if the formatting was successful
|
|
|
|
if (fmt_ret < 0)
|
|
|
|
{
|
|
|
|
// Return the buffer back to the buffer pool
|
|
|
|
_Core->PushBuffer(std::move(vbuf));
|
|
|
|
LogErr("Format error");
|
|
|
|
return;
|
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
2015-10-25 02:20:33 +02:00
|
|
|
// Release the arguments list
|
2015-09-30 02:56:11 +02:00
|
|
|
va_end(args);
|
2015-10-25 02:20:33 +02:00
|
|
|
// Output the buffer content
|
|
|
|
LogMsg("%s", vbuf.data());
|
|
|
|
// Return the buffer back to the buffer pool
|
|
|
|
_Core->PushBuffer(std::move(vbuf));
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::ErrorFunc(HSQUIRRELVM vm, const SQChar * str, ...) noexcept
|
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
// Prepare the arguments list
|
2015-09-30 02:56:11 +02:00
|
|
|
va_list args;
|
|
|
|
va_start(args, str);
|
2015-10-25 02:20:33 +02:00
|
|
|
// Acquire a buffer from the buffer pool
|
|
|
|
Core::Buffer vbuf = _Core->PullBuffer();
|
|
|
|
// Attempt to process the specified format string
|
|
|
|
SQInt32 fmt_ret = std::vsnprintf(vbuf.data(), vbuf.size(), str, args);
|
|
|
|
// See if the formatting was successful
|
|
|
|
if (fmt_ret < 0)
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
// Return the buffer back to the buffer pool
|
|
|
|
_Core->PushBuffer(std::move(vbuf));
|
|
|
|
LogErr("Format error");
|
|
|
|
return;
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
2015-10-25 02:20:33 +02:00
|
|
|
// See if the buffer was big enough
|
|
|
|
else if (_SCSZT(fmt_ret) > vbuf.size())
|
|
|
|
{
|
|
|
|
// Resize the buffer to accomodate the required size
|
|
|
|
vbuf.resize(++fmt_ret);
|
|
|
|
// Attempt to process the specified format string again
|
|
|
|
fmt_ret = std::vsnprintf(vbuf.data(), vbuf.size(), str, args);
|
|
|
|
// See if the formatting was successful
|
|
|
|
if (fmt_ret < 0)
|
|
|
|
{
|
|
|
|
// Return the buffer back to the buffer pool
|
|
|
|
_Core->PushBuffer(std::move(vbuf));
|
|
|
|
LogErr("Format error");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Release the arguments list
|
2015-09-30 02:56:11 +02:00
|
|
|
va_end(args);
|
2015-10-25 02:20:33 +02:00
|
|
|
// Output the buffer content
|
|
|
|
LogErr("%s", vbuf.data());
|
|
|
|
// Return the buffer back to the buffer pool
|
|
|
|
_Core->PushBuffer(std::move(vbuf));
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
SQInteger Core::RuntimeErrorHandler(HSQUIRRELVM vm) noexcept
|
|
|
|
{
|
|
|
|
if (sq_gettop(vm) < 1)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SQChar * err_msg = NULL;
|
|
|
|
|
|
|
|
if (SQ_SUCCEEDED(sq_getstring(vm, 2, &err_msg)))
|
|
|
|
{
|
|
|
|
_Core->m_ErrorMsg.assign(err_msg);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_Core->m_ErrorMsg.assign(_SC("An unknown runtime error has occurred"));
|
|
|
|
}
|
|
|
|
|
2015-10-25 02:20:33 +02:00
|
|
|
LogMsg("%s", CenterStr("ERROR", '*'));
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2015-10-25 02:20:33 +02:00
|
|
|
LogInf("[MESSAGE] : %s", _Core->m_ErrorMsg.c_str());
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
if (_Log->GetVerbosity() > 0)
|
|
|
|
{
|
|
|
|
_Core->PrintCallstack();
|
|
|
|
}
|
|
|
|
|
2015-10-25 02:20:33 +02:00
|
|
|
LogMsg("%s", CenterStr("CONCLUDED", '*'));
|
2015-09-30 02:56:11 +02:00
|
|
|
|
|
|
|
return SQ_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Core::CompilerErrorHandler(HSQUIRRELVM vm, const SQChar * desc, const SQChar * src, SQInteger line, SQInteger column) noexcept
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
_Core->m_ErrorMsg.assign(fmt::format("{0:s} : {1:d}:{2:d} : {3:s}", src, line, column, desc).c_str());
|
|
|
|
}
|
|
|
|
catch (const std::exception & e)
|
|
|
|
{
|
2015-10-25 02:20:33 +02:00
|
|
|
LogErr("Compiler error: %s", e.what());
|
2015-09-30 02:56:11 +02:00
|
|
|
_Core->m_ErrorMsg.assign(_SC("An unknown compiler error has occurred"));
|
|
|
|
}
|
|
|
|
|
2015-10-25 02:20:33 +02:00
|
|
|
LogErr("%s", _Core->m_ErrorMsg.c_str());
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Reference< CBlip > Core::CreateBlip(SQInt32 index, SQInt32 world, const Vector3 & pos, SQInt32 scale, \
|
2015-10-11 23:26:14 +02:00
|
|
|
const Color4 & color, SQInt32 sprite, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
// Attempt to create an instance on the server and obtain it's identifier
|
|
|
|
SQInt32 id = _Func->CreateCoordBlip(index, world, pos.x, pos.y, pos.z, scale, color.GetRGBA(), sprite);
|
|
|
|
// Attempt to activate the instance in the plugin at the received identifier
|
|
|
|
if (EntMan< CBlip >::Activate(id, true, world, scale, sprite, pos, color))
|
|
|
|
{
|
|
|
|
// Trigger the specific event
|
|
|
|
OnBlipCreated(id, header, payload);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LogErr("Unable to create a new <CBlip> instance");
|
|
|
|
}
|
|
|
|
// Return the obtained reference as is
|
|
|
|
return Reference< CBlip >(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Reference< CCheckpoint > Core::CreateCheckpoint(const Reference< CPlayer > & player, SQInt32 world, const Vector3 & pos, \
|
2015-10-11 23:26:14 +02:00
|
|
|
const Color4 & color, SQFloat radius, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
// See if the specified player reference is valid
|
|
|
|
if (!player)
|
|
|
|
{
|
|
|
|
LogWrn("Attempting to create a <Checkpoint> instance on an invalid player: %d", _SCI32(player));
|
|
|
|
}
|
|
|
|
// Attempt to create an instance on the server and obtain it's identifier
|
|
|
|
SQInt32 id = _Func->CreateCheckpoint(_SCI32(player), world, pos.x, pos.y, pos.z, color.r, color.g, color.b, color.a, radius);
|
|
|
|
// Attempt to activate the instance in the plugin at the received identifier
|
|
|
|
if (EntMan< CCheckpoint >::Activate(id, true))
|
|
|
|
{
|
|
|
|
// Trigger the specific event
|
|
|
|
OnCheckpointCreated(id, header, payload);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LogErr("Unable to create a new <CCheckpoint> instance");
|
|
|
|
}
|
|
|
|
// Return the obtained reference as is
|
|
|
|
return Reference< CCheckpoint >(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Reference< CKeybind > Core::CreateKeybind(SQInt32 slot, bool release, SQInt32 primary, SQInt32 secondary, \
|
2015-10-11 23:26:14 +02:00
|
|
|
SQInt32 alternative, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
// Attempt to create an instance on the server and obtain it's identifier
|
|
|
|
SQInt32 id = _Func->RegisterKeyBind(slot, release, primary, secondary, alternative);
|
|
|
|
// Attempt to activate the instance in the plugin at the received identifier
|
|
|
|
if (EntMan< CKeybind >::Activate(id, true, primary, secondary, alternative, release))
|
|
|
|
{
|
|
|
|
// Trigger the specific event
|
|
|
|
OnKeybindCreated(id, header, payload);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LogErr("Unable to create a new <CKeybind> instance");
|
|
|
|
}
|
|
|
|
// Return the obtained reference as is
|
|
|
|
return Reference< CKeybind >(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Reference< CObject > Core::CreateObject(const CModel & model, SQInt32 world, const Vector3 & pos, SQInt32 alpha, \
|
2015-10-11 23:26:14 +02:00
|
|
|
SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
// See if the specified model is valid
|
|
|
|
if (!model)
|
|
|
|
{
|
|
|
|
LogWrn("Attempting to create an <Object> instance with an invalid model: %d", _SCI32(model));
|
|
|
|
}
|
|
|
|
// Attempt to create an instance on the server and obtain it's identifier
|
|
|
|
SQInt32 id = _Func->CreateObject(_SCI32(model), world, pos.x, pos.y, pos.z, alpha);
|
|
|
|
// Attempt to activate the instance in the plugin at the received identifier
|
|
|
|
if (EntMan< CObject >::Activate(id, true))
|
|
|
|
{
|
|
|
|
// Trigger the specific event
|
|
|
|
OnObjectCreated(id, header, payload);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LogErr("Unable to create a new <CObject> instance");
|
|
|
|
}
|
|
|
|
// Return the obtained reference as is
|
|
|
|
return Reference< CObject >(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Reference< CPickup > Core::CreatePickup(const CModel & model, SQInt32 world, SQInt32 quantity, const Vector3 & pos, \
|
2015-10-11 23:26:14 +02:00
|
|
|
SQInt32 alpha, bool automatic, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
// See if the specified model is valid
|
|
|
|
if (!model)
|
|
|
|
{
|
|
|
|
LogWrn("Attempting to create a <Pickup> instance with an invalid model: %d", _SCI32(model));
|
|
|
|
}
|
|
|
|
// Attempt to create an instance on the server and obtain it's identifier
|
|
|
|
SQInt32 id = _Func->CreatePickup(_SCI32(model), world, quantity, pos.x, pos.y, pos.z, alpha, automatic);
|
|
|
|
// Attempt to activate the instance in the plugin at the received identifier
|
|
|
|
if (EntMan< CPickup >::Activate(id, true))
|
|
|
|
{
|
|
|
|
// Trigger the specific event
|
|
|
|
OnPickupCreated(id, header, payload);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LogErr("Unable to create a new <CPickup> instance");
|
|
|
|
}
|
|
|
|
// Return the obtained reference as is
|
|
|
|
return Reference< CPickup >(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Reference< CSphere > Core::CreateSphere(const Reference< CPlayer > & player, SQInt32 world, const Vector3 & pos, \
|
2015-10-11 23:26:14 +02:00
|
|
|
const Color3 & color, SQFloat radius, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
// See if the specified player reference is valid
|
|
|
|
if (!player)
|
|
|
|
{
|
|
|
|
LogWrn("Attempting to create a <Sphere> instance on an invalid player: %d", _SCI32(player));
|
|
|
|
}
|
|
|
|
// Attempt to create an instance on the server and obtain it's identifier
|
|
|
|
SQInt32 id = _Func->CreateSphere(_SCI32(player), world, pos.x, pos.y, pos.z, color.r, color.g, color.b, radius);
|
|
|
|
// Attempt to activate the instance in the plugin at the received identifier
|
|
|
|
if (EntMan< CSphere >::Activate(id, true))
|
|
|
|
{
|
|
|
|
// Trigger the specific event
|
|
|
|
OnSphereCreated(id, header, payload);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LogErr("Unable to create a new <CSphere> instance");
|
|
|
|
}
|
|
|
|
// Return the obtained reference as is
|
|
|
|
return Reference< CSphere >(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Reference< CSprite > Core::CreateSprite(SQInt32 index, const String & file, const Vector2i & pos, const Vector2i & rot, \
|
2015-10-11 23:26:14 +02:00
|
|
|
SQFloat angle, SQInt32 alpha, bool rel, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
// See if the specified file path is valid
|
|
|
|
if (file.empty())
|
|
|
|
{
|
|
|
|
LogWrn("Attempting to create a <Sprite> instance with an empty path: %d", file.size());
|
|
|
|
}
|
|
|
|
// Attempt to create an instance on the server and obtain it's identifier
|
|
|
|
SQInt32 id = _Func->CreateSprite(index, file.c_str(), pos.x, pos.y, rot.x, rot.y, angle, alpha, rel);
|
|
|
|
// Attempt to activate the instance in the plugin at the received identifier
|
|
|
|
if (EntMan< CSprite >::Activate(id, true, file))
|
|
|
|
{
|
|
|
|
// Trigger the specific event
|
|
|
|
OnSpriteCreated(id, header, payload);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LogErr("Unable to create a new <CSprite> instance");
|
|
|
|
}
|
|
|
|
// Return the obtained reference as is
|
|
|
|
return Reference< CSprite >(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Reference< CTextdraw > Core::CreateTextdraw(SQInt32 index, const String & text, const Vector2i & pos, \
|
2015-10-11 23:26:14 +02:00
|
|
|
const Color4 & color, bool rel, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
// See if the specified text is valid
|
|
|
|
if (text.empty())
|
|
|
|
{
|
|
|
|
LogWrn("Attempting to create a <Textdraw> instance with an empty text: %d", text.size());
|
|
|
|
}
|
|
|
|
// Attempt to create an instance on the server and obtain it's identifier
|
|
|
|
SQInt32 id = _Func->CreateTextdraw(index, text.c_str(), pos.x, pos.y, color.GetRGBA(), rel);
|
|
|
|
// Attempt to activate the instance in the plugin at the received identifier
|
|
|
|
if (EntMan< CTextdraw >::Activate(id, true, text))
|
|
|
|
{
|
|
|
|
// Trigger the specific event
|
|
|
|
OnTextdrawCreated(id, header, payload);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LogErr("Unable to create a new <CTextdraw> instance");
|
|
|
|
}
|
|
|
|
// Return the obtained reference as is
|
|
|
|
return Reference< CTextdraw >(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
Reference< CVehicle > Core::CreateVehicle(const CAutomobile & model, SQInt32 world, const Vector3 & pos, \
|
2015-10-11 23:26:14 +02:00
|
|
|
SQFloat angle, SQInt32 primary, SQInt32 secondary, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
// See if the specified model is valid
|
|
|
|
if (!model)
|
|
|
|
{
|
|
|
|
LogWrn("Attempting to create an <Vehicle> instance with an invalid model: %d", _SCI32(model));
|
|
|
|
}
|
|
|
|
// Attempt to create an instance on the server and obtain it's identifier
|
|
|
|
SQInt32 id = _Func->CreateVehicle(_SCI32(model), world, pos.x, pos.y, pos.z, angle, primary, secondary);
|
|
|
|
// Attempt to activate the instance in the plugin at the received identifier
|
|
|
|
if (EntMan< CVehicle >::Activate(id, true))
|
|
|
|
{
|
|
|
|
// Trigger the specific event
|
|
|
|
OnVehicleCreated(id, header, payload);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
LogErr("Unable to create a new <CVehicle> instance");
|
|
|
|
}
|
|
|
|
// Return the obtained reference as is
|
|
|
|
return Reference< CVehicle >(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-10-11 23:26:14 +02:00
|
|
|
bool Core::DestroyBlip(SQInt32 id, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-10-11 23:26:14 +02:00
|
|
|
bool Core::DestroyCheckpoint(SQInt32 id, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-10-11 23:26:14 +02:00
|
|
|
bool Core::DestroyKeybind(SQInt32 id, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-10-11 23:26:14 +02:00
|
|
|
bool Core::DestroyObject(SQInt32 id, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-10-11 23:26:14 +02:00
|
|
|
bool Core::DestroyPickup(SQInt32 id, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-10-11 23:26:14 +02:00
|
|
|
bool Core::DestroyPlayer(SQInt32 id, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-10-11 23:26:14 +02:00
|
|
|
bool Core::DestroySphere(SQInt32 id, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-10-11 23:26:14 +02:00
|
|
|
bool Core::DestroySprite(SQInt32 id, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-10-11 23:26:14 +02:00
|
|
|
bool Core::DestroyTextdraw(SQInt32 id, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-10-11 23:26:14 +02:00
|
|
|
bool Core::DestroyVehicle(SQInt32 id, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnBlipCreated(SQInt32 blip, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
BlipCreated.Emit(blip, header, payload);
|
|
|
|
Reference< CBlip >::Get(blip).BlipCreated.Emit(blip, header, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnCheckpointCreated(SQInt32 checkpoint, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
CheckpointCreated.Emit(checkpoint, header, payload);
|
|
|
|
Reference< CCheckpoint >::Get(checkpoint).CheckpointCreated.Emit(checkpoint, header, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnKeybindCreated(SQInt32 keybind, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
KeybindCreated.Emit(keybind, header, payload);
|
|
|
|
Reference< CKeybind >::Get(keybind).KeybindCreated.Emit(keybind, header, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnObjectCreated(SQInt32 object, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
ObjectCreated.Emit(object, header, payload);
|
|
|
|
Reference< CObject >::Get(object).ObjectCreated.Emit(object, header, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnPickupCreated(SQInt32 pickup, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
PickupCreated.Emit(pickup, header, payload);
|
|
|
|
Reference< CPickup >::Get(pickup).PickupCreated.Emit(pickup, header, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnPlayerCreated(SQInt32 player, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
PlayerCreated.Emit(player, header, payload);
|
|
|
|
Reference< CPlayer >::Get(player).PlayerCreated.Emit(player, header, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnSphereCreated(SQInt32 sphere, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
SphereCreated.Emit(sphere, header, payload);
|
|
|
|
Reference< CSphere >::Get(sphere).SphereCreated.Emit(sphere, header, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnSpriteCreated(SQInt32 sprite, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
SpriteCreated.Emit(sprite, header, payload);
|
|
|
|
Reference< CSprite >::Get(sprite).SpriteCreated.Emit(sprite, header, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnTextdrawCreated(SQInt32 textdraw, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
TextdrawCreated.Emit(textdraw, header, payload);
|
|
|
|
Reference< CTextdraw >::Get(textdraw).TextdrawCreated.Emit(textdraw, header, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnVehicleCreated(SQInt32 vehicle, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
VehicleCreated.Emit(vehicle, header, payload);
|
|
|
|
Reference< CVehicle >::Get(vehicle).VehicleCreated.Emit(vehicle, header, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnBlipDestroyed(SQInt32 blip, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
BlipDestroyed.Emit(blip, header, payload);
|
|
|
|
Reference< CBlip >::Get(blip).BlipDestroyed.Emit(blip, header, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnCheckpointDestroyed(SQInt32 checkpoint, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
CheckpointDestroyed.Emit(checkpoint, header, payload);
|
|
|
|
Reference< CCheckpoint >::Get(checkpoint).CheckpointDestroyed.Emit(checkpoint, header, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnKeybindDestroyed(SQInt32 keybind, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
KeybindDestroyed.Emit(keybind, header, payload);
|
|
|
|
Reference< CKeybind >::Get(keybind).KeybindDestroyed.Emit(keybind, header, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnObjectDestroyed(SQInt32 object, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
ObjectDestroyed.Emit(object, header, payload);
|
|
|
|
Reference< CObject >::Get(object).ObjectDestroyed.Emit(object, header, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnPickupDestroyed(SQInt32 pickup, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
PickupDestroyed.Emit(pickup, header, payload);
|
|
|
|
Reference< CPickup >::Get(pickup).PickupDestroyed.Emit(pickup, header, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnPlayerDestroyed(SQInt32 player, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
PlayerDestroyed.Emit(player, header, payload);
|
|
|
|
Reference< CPlayer >::Get(player).PlayerDestroyed.Emit(player, header, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnSphereDestroyed(SQInt32 sphere, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
SphereDestroyed.Emit(sphere, header, payload);
|
|
|
|
Reference< CSphere >::Get(sphere).SphereDestroyed.Emit(sphere, header, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnSpriteDestroyed(SQInt32 sprite, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
SpriteDestroyed.Emit(sprite, header, payload);
|
|
|
|
Reference< CSprite >::Get(sprite).SpriteDestroyed.Emit(sprite, header, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnTextdrawDestroyed(SQInt32 textdraw, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
TextdrawDestroyed.Emit(textdraw, header, payload);
|
|
|
|
Reference< CTextdraw >::Get(textdraw).TextdrawDestroyed.Emit(textdraw, header, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnVehicleDestroyed(SQInt32 vehicle, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
VehicleDestroyed.Emit(vehicle, header, payload);
|
|
|
|
Reference< CVehicle >::Get(vehicle).VehicleDestroyed.Emit(vehicle, header, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnBlipCustom(SQInt32 blip, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
BlipCustom.Emit(blip, header, payload);
|
|
|
|
Reference< CBlip >::Get(blip).BlipCustom.Emit(blip, header, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnCheckpointCustom(SQInt32 checkpoint, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
CheckpointCustom.Emit(checkpoint, header, payload);
|
|
|
|
Reference< CCheckpoint >::Get(checkpoint).CheckpointCustom.Emit(checkpoint, header, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnKeybindCustom(SQInt32 keybind, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
KeybindCustom.Emit(keybind, header, payload);
|
|
|
|
Reference< CKeybind >::Get(keybind).KeybindCustom.Emit(keybind, header, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnObjectCustom(SQInt32 object, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
ObjectCustom.Emit(object, header, payload);
|
|
|
|
Reference< CObject >::Get(object).ObjectCustom.Emit(object, header, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnPickupCustom(SQInt32 pickup, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
PickupCustom.Emit(pickup, header, payload);
|
|
|
|
Reference< CPickup >::Get(pickup).PickupCustom.Emit(pickup, header, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnPlayerCustom(SQInt32 player, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
PlayerCustom.Emit(player, header, payload);
|
|
|
|
Reference< CPlayer >::Get(player).PlayerCustom.Emit(player, header, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnSphereCustom(SQInt32 sphere, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
SphereCustom.Emit(sphere, header, payload);
|
|
|
|
Reference< CSphere >::Get(sphere).SphereCustom.Emit(sphere, header, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnSpriteCustom(SQInt32 sprite, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
SpriteCustom.Emit(sprite, header, payload);
|
|
|
|
Reference< CSprite >::Get(sprite).SpriteCustom.Emit(sprite, header, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnTextdrawCustom(SQInt32 textdraw, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
TextdrawCustom.Emit(textdraw, header, payload);
|
|
|
|
Reference< CTextdraw >::Get(textdraw).TextdrawCustom.Emit(textdraw, header, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnVehicleCustom(SQInt32 vehicle, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
VehicleCustom.Emit(vehicle, header, payload);
|
|
|
|
Reference< CVehicle >::Get(vehicle).VehicleCustom.Emit(vehicle, header, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::OnPlayerAway(SQInt32 player, bool status) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
PlayerAway.Emit(player, status);
|
|
|
|
Reference< CPlayer >::Get(player).PlayerAway.Emit(player, status);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::OnPlayerGameKeys(SQInt32 player, SQInt32 previous, SQInt32 current) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
PlayerGameKeys.Emit(player, previous, current);
|
|
|
|
Reference< CPlayer >::Get(player).PlayerGameKeys.Emit(player, previous, current);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnPlayerName(SQInt32 player, const SQChar * previous, const SQChar * current) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
PlayerRename.Emit(player, previous, current);
|
|
|
|
Reference< CPlayer >::Get(player).PlayerRename.Emit(player, previous, current);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::OnPlayerRequestClass(SQInt32 player, SQInt32 offset) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
PlayerRequestClass.Emit(player, offset);
|
|
|
|
Reference< CPlayer >::Get(player).PlayerRequestClass.Emit(player, offset);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnPlayerRequestSpawn(SQInt32 player) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
PlayerRequestSpawn.Emit(player);
|
|
|
|
Reference< CPlayer >::Get(player).PlayerRequestSpawn.Emit(player);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::OnPlayerSpawn(SQInt32 player) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
PlayerSpawn.Emit(player);
|
|
|
|
Reference< CPlayer >::Get(player).PlayerSpawn.Emit(player);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::OnPlayerStartTyping(SQInt32 player) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
PlayerStartTyping.Emit(player);
|
|
|
|
Reference< CPlayer >::Get(player).PlayerStartTyping.Emit(player);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnPlayerStopTyping(SQInt32 player) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
PlayerStopTyping.Emit(player);
|
|
|
|
Reference< CPlayer >::Get(player).PlayerStopTyping.Emit(player);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::OnPlayerChat(SQInt32 player, const SQChar * message) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
PlayerChat.Emit(player, message);
|
|
|
|
Reference< CPlayer >::Get(player).PlayerChat.Emit(player, message);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnPlayerCommand(SQInt32 player, const SQChar * command) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
PlayerCommand.Emit(player, command);
|
|
|
|
Reference< CPlayer >::Get(player).PlayerCommand.Emit(player, command);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnPlayerMessage(SQInt32 player, SQInt32 receiver, const SQChar * message) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
PlayerMessage.Emit(player, receiver, message);
|
|
|
|
Reference< CPlayer >::Get(player).PlayerMessage.Emit(player, receiver, message);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::OnPlayerHealth(SQInt32 player, SQFloat previous, SQFloat current) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
PlayerHealth.Emit(player, previous, current);
|
|
|
|
Reference< CPlayer >::Get(player).PlayerHealth.Emit(player, previous, current);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnPlayerArmour(SQInt32 player, SQFloat previous, SQFloat current) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
PlayerArmour.Emit(player, previous, current);
|
|
|
|
Reference< CPlayer >::Get(player).PlayerArmour.Emit(player, previous, current);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnPlayerWeapon(SQInt32 player, SQInt32 previous, SQInt32 current) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
PlayerWeapon.Emit(player, previous, current);
|
|
|
|
Reference< CPlayer >::Get(player).PlayerWeapon.Emit(player, previous, current);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnPlayerMove(SQInt32 player, const Vector3 & previous, const Vector3 & current) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
PlayerMove.Emit(player, previous, current);
|
|
|
|
Reference< CPlayer >::Get(player).PlayerMove.Emit(player, previous, current);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::OnPlayerWasted(SQInt32 player, SQInt32 reason) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
PlayerWasted.Emit(player, reason);
|
|
|
|
Reference< CPlayer >::Get(player).PlayerWasted.Emit(player, reason);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnPlayerKilled(SQInt32 player, SQInt32 killer, SQInt32 reason, SQInt32 body_part) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
PlayerKilled.Emit(player, killer, reason, body_part);
|
|
|
|
Reference< CPlayer >::Get(player).PlayerKilled.Emit(player, killer, reason, body_part);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::OnPlayerSpectate(SQInt32 player, SQInt32 target) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
PlayerSpectate.Emit(player, target);
|
|
|
|
Reference< CPlayer >::Get(player).PlayerSpectate.Emit(player, target);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnPlayerCrashreport(SQInt32 player, const SQChar * report) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
PlayerCrashreport.Emit(player, report);
|
|
|
|
Reference< CPlayer >::Get(player).PlayerCrashreport.Emit(player, report);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::OnPlayerBurning(SQInt32 player, bool state) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
PlayerBurning.Emit(player, state);
|
|
|
|
Reference< CPlayer >::Get(player).PlayerBurning.Emit(player, state);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnPlayerCrouching(SQInt32 player, bool state) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
PlayerCrouching.Emit(player, state);
|
|
|
|
Reference< CPlayer >::Get(player).PlayerCrouching.Emit(player, state);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::OnPlayerState(SQInt32 player, SQInt32 previous, SQInt32 current) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
PlayerState.Emit(player, previous, current);
|
|
|
|
Reference< CPlayer >::Get(player).PlayerState.Emit(player, previous, current);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnPlayerAction(SQInt32 player, SQInt32 previous, SQInt32 current) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
PlayerAction.Emit(player, previous, current);
|
|
|
|
Reference< CPlayer >::Get(player).PlayerAction.Emit(player, previous, current);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::OnStateNone(SQInt32 player, SQInt32 previous) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
StateNone.Emit(player, previous);
|
|
|
|
Reference< CPlayer >::Get(player).StateNone.Emit(player, previous);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnStateNormal(SQInt32 player, SQInt32 previous) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
StateNormal.Emit(player, previous);
|
|
|
|
Reference< CPlayer >::Get(player).StateNormal.Emit(player, previous);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnStateShooting(SQInt32 player, SQInt32 previous) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
StateShooting.Emit(player, previous);
|
|
|
|
Reference< CPlayer >::Get(player).StateShooting.Emit(player, previous);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnStateDriver(SQInt32 player, SQInt32 previous) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
StateDriver.Emit(player, previous);
|
|
|
|
Reference< CPlayer >::Get(player).StateDriver.Emit(player, previous);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnStatePassenger(SQInt32 player, SQInt32 previous) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
StatePassenger.Emit(player, previous);
|
|
|
|
Reference< CPlayer >::Get(player).StatePassenger.Emit(player, previous);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnStateEnterDriver(SQInt32 player, SQInt32 previous) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
StateEnterDriver.Emit(player, previous);
|
|
|
|
Reference< CPlayer >::Get(player).StateEnterDriver.Emit(player, previous);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnStateEnterPassenger(SQInt32 player, SQInt32 previous) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
StateEnterPassenger.Emit(player, previous);
|
|
|
|
Reference< CPlayer >::Get(player).StateEnterPassenger.Emit(player, previous);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnStateExitVehicle(SQInt32 player, SQInt32 previous) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
StateExitVehicle.Emit(player, previous);
|
|
|
|
Reference< CPlayer >::Get(player).StateExitVehicle.Emit(player, previous);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnStateUnspawned(SQInt32 player, SQInt32 previous) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
StateUnspawned.Emit(player, previous);
|
|
|
|
Reference< CPlayer >::Get(player).StateUnspawned.Emit(player, previous);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::OnActionNone(SQInt32 player, SQInt32 previous) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
ActionNone.Emit(player, previous);
|
|
|
|
Reference< CPlayer >::Get(player).ActionNone.Emit(player, previous);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnActionNormal(SQInt32 player, SQInt32 previous) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
ActionNormal.Emit(player, previous);
|
|
|
|
Reference< CPlayer >::Get(player).ActionNormal.Emit(player, previous);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnActionAiming(SQInt32 player, SQInt32 previous) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
ActionAiming.Emit(player, previous);
|
|
|
|
Reference< CPlayer >::Get(player).ActionAiming.Emit(player, previous);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnActionShooting(SQInt32 player, SQInt32 previous) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
ActionShooting.Emit(player, previous);
|
|
|
|
Reference< CPlayer >::Get(player).ActionShooting.Emit(player, previous);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnActionJumping(SQInt32 player, SQInt32 previous) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
ActionJumping.Emit(player, previous);
|
|
|
|
Reference< CPlayer >::Get(player).ActionJumping.Emit(player, previous);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnActionLieDown(SQInt32 player, SQInt32 previous) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
ActionLieDown.Emit(player, previous);
|
|
|
|
Reference< CPlayer >::Get(player).ActionLieDown.Emit(player, previous);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnActionGettingUp(SQInt32 player, SQInt32 previous) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
ActionGettingUp.Emit(player, previous);
|
|
|
|
Reference< CPlayer >::Get(player).ActionGettingUp.Emit(player, previous);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnActionJumpVehicle(SQInt32 player, SQInt32 previous) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
ActionJumpVehicle.Emit(player, previous);
|
|
|
|
Reference< CPlayer >::Get(player).ActionJumpVehicle.Emit(player, previous);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnActionDriving(SQInt32 player, SQInt32 previous) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
ActionDriving.Emit(player, previous);
|
|
|
|
Reference< CPlayer >::Get(player).ActionDriving.Emit(player, previous);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnActionDying(SQInt32 player, SQInt32 previous) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
ActionDying.Emit(player, previous);
|
|
|
|
Reference< CPlayer >::Get(player).ActionDying.Emit(player, previous);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnActionWasted(SQInt32 player, SQInt32 previous) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
ActionWasted.Emit(player, previous);
|
|
|
|
Reference< CPlayer >::Get(player).ActionWasted.Emit(player, previous);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnActionEmbarking(SQInt32 player, SQInt32 previous) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
ActionEmbarking.Emit(player, previous);
|
|
|
|
Reference< CPlayer >::Get(player).ActionEmbarking.Emit(player, previous);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnActionDisembarking(SQInt32 player, SQInt32 previous) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
ActionDisembarking.Emit(player, previous);
|
|
|
|
Reference< CPlayer >::Get(player).ActionDisembarking.Emit(player, previous);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::OnVehicleRespawn(SQInt32 vehicle) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
VehicleRespawn.Emit(vehicle);
|
|
|
|
Reference< CVehicle >::Get(vehicle).VehicleRespawn.Emit(vehicle);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnVehicleExplode(SQInt32 vehicle) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
VehicleExplode.Emit(vehicle);
|
|
|
|
Reference< CVehicle >::Get(vehicle).VehicleExplode.Emit(vehicle);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::OnVehicleHealth(SQInt32 vehicle, SQFloat previous, SQFloat current) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
VehicleHealth.Emit(vehicle, previous, current);
|
|
|
|
Reference< CVehicle >::Get(vehicle).VehicleHealth.Emit(vehicle, previous, current);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnVehicleMove(SQInt32 vehicle, const Vector3 & previous, const Vector3 & current) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
VehicleMove.Emit(vehicle, previous, current);
|
|
|
|
Reference< CVehicle >::Get(vehicle).VehicleMove.Emit(vehicle, previous, current);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::OnPickupRespawn(SQInt32 pickup) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
PickupRespawn.Emit(pickup);
|
|
|
|
Reference< CPickup >::Get(pickup).PickupRespawn.Emit(pickup);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::OnPlayerKeyPress(SQInt32 player, SQInt32 keybind) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
KeybindKeyPress.Emit(player, keybind);
|
|
|
|
Reference< CKeybind >::Get(keybind).KeybindKeyPress.Emit(player, keybind);
|
|
|
|
Reference< CPlayer >::Get(player).KeybindKeyPress.Emit(player, keybind);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnPlayerKeyRelease(SQInt32 player, SQInt32 keybind) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
KeybindKeyRelease.Emit(player, keybind);
|
|
|
|
Reference< CKeybind >::Get(keybind).KeybindKeyRelease.Emit(player, keybind);
|
|
|
|
Reference< CPlayer >::Get(player).KeybindKeyRelease.Emit(player, keybind);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::OnPlayerEmbarking(SQInt32 player, SQInt32 vehicle, SQInt32 slot) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
VehicleEmbarking.Emit(player, vehicle, slot);
|
|
|
|
Reference< CVehicle >::Get(vehicle).VehicleEmbarking.Emit(player, vehicle, slot);
|
|
|
|
Reference< CPlayer >::Get(player).VehicleEmbarking.Emit(player, vehicle, slot);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnPlayerEmbarked(SQInt32 player, SQInt32 vehicle, SQInt32 slot) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
VehicleEmbarked.Emit(player, vehicle, slot);
|
|
|
|
Reference< CVehicle >::Get(vehicle).VehicleEmbarked.Emit(player, vehicle, slot);
|
|
|
|
Reference< CPlayer >::Get(player).VehicleEmbarked.Emit(player, vehicle, slot);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnPlayerDisembark(SQInt32 player, SQInt32 vehicle) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
VehicleDisembark.Emit(player, vehicle);
|
|
|
|
Reference< CVehicle >::Get(vehicle).VehicleDisembark.Emit(player, vehicle);
|
|
|
|
Reference< CPlayer >::Get(player).VehicleDisembark.Emit(player, vehicle);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnPickupClaimed(SQInt32 player, SQInt32 pickup) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
PickupClaimed.Emit(player, pickup);
|
|
|
|
Reference< CPickup >::Get(pickup).PickupClaimed.Emit(player, pickup);
|
|
|
|
Reference< CPlayer >::Get(player).PickupClaimed.Emit(player, pickup);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnPickupCollected(SQInt32 player, SQInt32 pickup) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
PickupClaimed.Emit(player, pickup);
|
|
|
|
Reference< CPickup >::Get(pickup).PickupClaimed.Emit(player, pickup);
|
|
|
|
Reference< CPlayer >::Get(player).PickupClaimed.Emit(player, pickup);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnObjectShot(SQInt32 player, SQInt32 object, SQInt32 weapon) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
ObjectShot.Emit(player, object, weapon);
|
|
|
|
Reference< CObject >::Get(object).ObjectShot.Emit(player, object, weapon);
|
|
|
|
Reference< CPlayer >::Get(player).ObjectShot.Emit(player, object, weapon);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnObjectBump(SQInt32 player, SQInt32 object) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
ObjectBump.Emit(player, object);
|
|
|
|
Reference< CObject >::Get(object).ObjectBump.Emit(player, object);
|
|
|
|
Reference< CPlayer >::Get(player).ObjectBump.Emit(player, object);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnCheckpointEntered(SQInt32 player, SQInt32 checkpoint) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
CheckpointEntered.Emit(player, checkpoint);
|
|
|
|
Reference< CCheckpoint >::Get(checkpoint).CheckpointEntered.Emit(player, checkpoint);
|
|
|
|
Reference< CPlayer >::Get(player).CheckpointEntered.Emit(player, checkpoint);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnCheckpointExited(SQInt32 player, SQInt32 checkpoint) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
CheckpointExited.Emit(player, checkpoint);
|
|
|
|
Reference< CCheckpoint >::Get(checkpoint).CheckpointExited.Emit(player, checkpoint);
|
|
|
|
Reference< CPlayer >::Get(player).CheckpointExited.Emit(player, checkpoint);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnSphereEntered(SQInt32 player, SQInt32 sphere) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
SphereEntered.Emit(player, sphere);
|
|
|
|
Reference< CSphere >::Get(sphere).SphereEntered.Emit(player, sphere);
|
|
|
|
Reference< CPlayer >::Get(player).SphereEntered.Emit(player, sphere);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnSphereExited(SQInt32 player, SQInt32 sphere) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
SphereExited.Emit(player, sphere);
|
|
|
|
Reference< CSphere >::Get(sphere).SphereExited.Emit(player, sphere);
|
|
|
|
Reference< CPlayer >::Get(player).SphereExited.Emit(player, sphere);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::OnServerFrame(SQFloat delta) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
ServerFrame.Emit(delta);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::OnServerStartup() noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
ServerStartup.Emit();
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnServerShutdown() noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
ServerShutdown.Emit();
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::OnInternalCommand(SQInt32 type, const SQChar * text) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
InternalCommand.Emit(type, text);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnLoginAttempt(const SQChar * name, const SQChar * passwd, const SQChar * ip) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
LoginAttempt.Emit(name, passwd, ip);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnCustomEvent(SQInt32 group, SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
CustomEvent.Emit(group, header, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnWorldOption(SQInt32 option, SqObj & value) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
WorldOption.Emit(option, value);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnWorldToggle(SQInt32 option, bool value) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
WorldToggle.Emit(option, value);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2015-10-11 23:26:14 +02:00
|
|
|
void Core::OnScriptReload(SQInt32 header, SqObj & payload) noexcept
|
2015-09-30 02:56:11 +02:00
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
ScriptReload.Emit(header, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::OnLogMessage(SQInt32 type, const SQChar * message) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
LogMessage.Emit(type, message);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::OnPlayerUpdate(SQInt32 player, SQInt32 type) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
Vector3 pos;
|
|
|
|
_Func->GetPlayerPos(player, &pos.x, &pos.y, &pos.z);
|
|
|
|
|
|
|
|
if (m_PlayerTrack[player].Fresh)
|
|
|
|
{
|
|
|
|
m_PlayerTrack[player].Position = pos;
|
|
|
|
m_PlayerTrack[player].Health = _Func->GetPlayerHealth(player);
|
|
|
|
m_PlayerTrack[player].Armour = _Func->GetPlayerArmour(player);
|
|
|
|
m_PlayerTrack[player].Weapon = _Func->GetPlayerWeapon(player);
|
|
|
|
m_PlayerTrack[player].Fresh = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pos != m_PlayerTrack[player].Position)
|
|
|
|
{
|
|
|
|
PlayerMove.Emit(player, m_PlayerTrack[player].Position, pos);
|
|
|
|
m_PlayerTrack[player].Position = pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
SQFloat health = _Func->GetPlayerHealth(player);
|
|
|
|
|
|
|
|
if (!EpsEq(health, m_PlayerTrack[player].Health))
|
|
|
|
{
|
|
|
|
PlayerHealth.Emit(player, m_PlayerTrack[player].Health, health);
|
|
|
|
m_PlayerTrack[player].Health = health;
|
|
|
|
}
|
|
|
|
|
|
|
|
SQFloat armour = _Func->GetPlayerArmour(player);
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
if (!EpsEq(armour, m_PlayerTrack[player].Armour))
|
|
|
|
{
|
|
|
|
PlayerArmour.Emit(player, m_PlayerTrack[player].Armour, armour);
|
|
|
|
m_PlayerTrack[player].Armour = armour;
|
|
|
|
}
|
|
|
|
|
|
|
|
SQInteger wep = _Func->GetPlayerWeapon(player);
|
|
|
|
|
|
|
|
if (wep != m_PlayerTrack[player].Weapon)
|
|
|
|
{
|
|
|
|
PlayerWeapon.Emit(player, m_PlayerTrack[player].Weapon, wep);
|
|
|
|
m_PlayerTrack[player].Weapon = wep;
|
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnVehicleUpdate(SQInt32 vehicle, SQInt32 type) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
Vector3 pos;
|
|
|
|
_Func->GetVehiclePos(vehicle, &pos.x, &pos.y, &pos.z);
|
|
|
|
|
|
|
|
if (m_VehicleTrack[vehicle].Fresh)
|
|
|
|
{
|
|
|
|
m_VehicleTrack[vehicle].Position = pos;
|
|
|
|
m_VehicleTrack[vehicle].Health = _Func->GetVehicleHealth(vehicle);
|
|
|
|
m_VehicleTrack[vehicle].Fresh = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pos != m_VehicleTrack[vehicle].Position)
|
|
|
|
{
|
|
|
|
VehicleMove.Emit(vehicle, m_VehicleTrack[vehicle].Position, pos);
|
|
|
|
m_VehicleTrack[vehicle].Position = pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
SQFloat health = _Func->GetVehicleHealth(vehicle);
|
2015-09-30 02:56:11 +02:00
|
|
|
|
2015-10-11 23:26:14 +02:00
|
|
|
if (!EpsEq(health, m_VehicleTrack[vehicle].Health))
|
|
|
|
{
|
|
|
|
VehicleHealth.Emit(vehicle, m_VehicleTrack[vehicle].Health, health);
|
|
|
|
m_VehicleTrack[vehicle].Health = health;
|
|
|
|
}
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Core::OnEntityPool(SQInt32 type, SQInt32 id, bool deleted) noexcept
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
static SqObj payload;
|
|
|
|
payload.Release();
|
2015-09-30 02:56:11 +02:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case SQMOD_ENTITY_POOL_VEHICLE:
|
|
|
|
if (deleted)
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
DestroyVehicle(id, SQMOD_DESTROY_POOL, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
else if (EntMan< CVehicle >::Activate(id, false))
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
OnVehicleCreated(id, SQMOD_CREATE_POOL, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SQMOD_ENTITY_POOL_OBJECT:
|
|
|
|
if (deleted)
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
DestroyObject(id, SQMOD_DESTROY_POOL, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
else if (EntMan< CObject >::Activate(id, false))
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
OnObjectCreated(id, SQMOD_CREATE_POOL, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SQMOD_ENTITY_POOL_PICKUP:
|
|
|
|
if (deleted)
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
DestroyPickup(id, SQMOD_DESTROY_POOL, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
else if (EntMan< CPickup >::Activate(id, false))
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
OnPickupCreated(id, SQMOD_CREATE_POOL, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SQMOD_ENTITY_POOL_RADIO:
|
|
|
|
// @TODO Implement...
|
|
|
|
break;
|
|
|
|
case SQMOD_ENTITY_POOL_SPRITE:
|
|
|
|
if (deleted)
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
DestroySprite(id, SQMOD_DESTROY_POOL, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
else if (EntMan< CSprite >::Activate(id, false, ""))
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
OnSpriteCreated(id, SQMOD_CREATE_POOL, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SQMOD_ENTITY_POOL_TEXTDRAW:
|
|
|
|
if (deleted)
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
DestroyTextdraw(id, SQMOD_DESTROY_POOL, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
else if (EntMan< CTextdraw >::Activate(id, false, ""))
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
OnTextdrawCreated(id, SQMOD_CREATE_POOL, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SQMOD_ENTITY_POOL_BLIP:
|
|
|
|
if (deleted)
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
DestroyBlip(id, SQMOD_DESTROY_POOL, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SQInt32 world, scale, sprite;
|
|
|
|
SQUint32 pcolor;
|
|
|
|
Vector3 pos;
|
|
|
|
Color4 color;
|
|
|
|
// Get the blip information from the server
|
|
|
|
_Func->GetCoordBlipInfo(id, &world, &pos.x, &pos.y, &pos.z, &scale, &pcolor, &sprite);
|
|
|
|
// Unpack the retrieved color
|
|
|
|
color.SetRGBA(pcolor);
|
|
|
|
|
|
|
|
if (EntMan< CBlip >::Activate(id, false, world, scale, sprite, pos, color))
|
|
|
|
{
|
2015-10-11 23:26:14 +02:00
|
|
|
OnBlipCreated(id, SQMOD_CREATE_POOL, payload);
|
2015-09-30 02:56:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
LogErr("Unknown change in the entity pool of type: %d", type);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // Namespace:: SqMod
|