2016-05-22 05:20:38 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#include "Core.hpp"
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
#include "Entity/Blip.hpp"
|
|
|
|
#include "Entity/Checkpoint.hpp"
|
|
|
|
#include "Entity/Keybind.hpp"
|
|
|
|
#include "Entity/Object.hpp"
|
|
|
|
#include "Entity/Pickup.hpp"
|
|
|
|
#include "Entity/Player.hpp"
|
|
|
|
#include "Entity/Vehicle.hpp"
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
namespace SqMod {
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
|
|
|
void Core::ImportBlips()
|
|
|
|
{
|
|
|
|
// Information about the blip entity
|
|
|
|
Int32 world = -1, scale = -1, sprid = -1;
|
|
|
|
Uint32 color = 0;
|
|
|
|
Float32 x = 0.0, y = 0.0, z = 0.0;
|
|
|
|
|
|
|
|
for (Int32 i = 0; i < SQMOD_BLIP_POOL; ++i)
|
|
|
|
{
|
|
|
|
// See if this entity exists on the server and whether was not allocated already
|
|
|
|
if (_Func->CheckEntityExists(vcmpEntityPoolBlip, i) && INVALID_ENTITY(m_Blips[i].mID))
|
|
|
|
{
|
|
|
|
_Func->GetCoordBlipInfo(i, &world, &x, &y, &z, &scale, &color, &sprid);
|
|
|
|
// Make the properties available before triggering the event
|
|
|
|
m_Blips[i].mWorld = world;
|
|
|
|
m_Blips[i].mScale = scale;
|
|
|
|
m_Blips[i].mSprID = sprid;
|
2016-07-24 23:10:46 +02:00
|
|
|
m_Blips[i].mPosition.SetVector3Ex(x, y, z);
|
2016-05-22 05:20:38 +02:00
|
|
|
m_Blips[i].mColor.SetRGBA(color);
|
|
|
|
// Attempt to allocate the instance
|
2017-02-21 20:24:59 +01:00
|
|
|
AllocBlip(i, false, SQMOD_CREATE_IMPORT, NullLightObj());
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::ImportCheckpoints()
|
|
|
|
{
|
|
|
|
for (Int32 i = 0; i < SQMOD_CHECKPOINT_POOL; ++i)
|
|
|
|
{
|
|
|
|
// See if this entity exists on the server and whether was not allocated already
|
|
|
|
if (_Func->CheckEntityExists(vcmpEntityPoolCheckPoint, i) && INVALID_ENTITY(m_Checkpoints[i].mID))
|
|
|
|
{
|
2017-02-21 20:24:59 +01:00
|
|
|
AllocCheckpoint(i, false, SQMOD_CREATE_IMPORT, NullLightObj());
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::ImportKeybinds()
|
|
|
|
{
|
2017-02-21 20:24:59 +01:00
|
|
|
/* @NOTE This function is disabled because VC:MP server seems bugged
|
|
|
|
* and does not return vcmpErrorNoSuchEntity when the keybind does not exist.
|
|
|
|
* Therefore causing incorrect behavior in the plugin.
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// Information about the key-bind entity
|
|
|
|
Uint8 release = 0;
|
|
|
|
Int32 first = -1, second = -1, third = -1;
|
|
|
|
|
|
|
|
for (Int32 i = 0; i < SQMOD_KEYBIND_POOL; ++i)
|
|
|
|
{
|
|
|
|
// See if this entity exists on the server and whether was not allocated already
|
|
|
|
if ((_Func->GetKeyBindData(i, &release, &first, &second, &third) != vcmpErrorNoSuchEntity)
|
|
|
|
&& (INVALID_ENTITY(m_Keybinds[i].mID)))
|
|
|
|
{
|
|
|
|
// Make the properties available before triggering the event
|
|
|
|
m_Keybinds[i].mFirst = first;
|
|
|
|
m_Keybinds[i].mSecond = second;
|
|
|
|
m_Keybinds[i].mThird = third;
|
|
|
|
m_Keybinds[i].mRelease = release;
|
|
|
|
// Attempt to allocate the instance
|
2017-02-21 20:24:59 +01:00
|
|
|
AllocKeybind(i, false, SQMOD_CREATE_IMPORT, NullLightObj());
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::ImportObjects()
|
|
|
|
{
|
|
|
|
for (Int32 i = 0; i < SQMOD_OBJECT_POOL; ++i)
|
|
|
|
{
|
|
|
|
// See if this entity exists on the server and whether was not allocated already
|
|
|
|
if (_Func->CheckEntityExists(vcmpEntityPoolObject, i) && INVALID_ENTITY(m_Objects[i].mID))
|
|
|
|
{
|
2017-02-21 20:24:59 +01:00
|
|
|
AllocObject(i, false, SQMOD_CREATE_IMPORT, NullLightObj());
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::ImportPickups()
|
|
|
|
{
|
|
|
|
for (Int32 i = 0; i < SQMOD_PICKUP_POOL; ++i)
|
|
|
|
{
|
|
|
|
// See if this entity exists on the server and whether was not allocated already
|
|
|
|
if (_Func->CheckEntityExists(vcmpEntityPoolPickup, i) && (INVALID_ENTITY(m_Pickups[i].mID)))
|
|
|
|
{
|
2017-02-21 20:24:59 +01:00
|
|
|
AllocPickup(i, false, SQMOD_CREATE_IMPORT, NullLightObj());
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::ImportPlayers()
|
|
|
|
{
|
|
|
|
for (Int32 i = 0; i < SQMOD_PLAYER_POOL; ++i)
|
|
|
|
{
|
|
|
|
// See if this entity exists on the server and whether was not allocated already
|
|
|
|
if (_Func->IsPlayerConnected(i) && (INVALID_ENTITY(m_Players[i].mID)))
|
|
|
|
{
|
2017-02-21 20:24:59 +01:00
|
|
|
ConnectPlayer(i, SQMOD_CREATE_IMPORT, NullLightObj());
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
|
|
|
void Core::ImportVehicles()
|
|
|
|
{
|
|
|
|
for (Int32 i = 0; i < SQMOD_VEHICLE_POOL; ++i)
|
|
|
|
{
|
|
|
|
// See if this entity exists on the server and whether was not allocated already
|
|
|
|
if (_Func->CheckEntityExists(vcmpEntityPoolVehicle, i) && INVALID_ENTITY(m_Vehicles[i].mID))
|
|
|
|
{
|
2017-02-21 20:24:59 +01:00
|
|
|
AllocVehicle(i, false, SQMOD_CREATE_IMPORT, NullLightObj());
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
Core::BlipInst & Core::AllocBlip(Int32 id, bool owned, Int32 header, LightObj & payload)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
|
|
|
// Make sure that the specified entity identifier is valid
|
|
|
|
if (INVALID_ENTITYEX(id, SQMOD_BLIP_POOL))
|
|
|
|
{
|
|
|
|
STHROWF("Cannot allocate blip with invalid identifier: %d", id);
|
|
|
|
}
|
|
|
|
// Retrieve the specified entity instance
|
|
|
|
BlipInst & inst = m_Blips[id];
|
|
|
|
// Make sure that the instance isn't already allocated
|
|
|
|
if (VALID_ENTITY(inst.mID))
|
|
|
|
{
|
2016-06-26 14:47:27 +02:00
|
|
|
return inst; // Return the existing instance
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
// Instantiate the entity manager
|
2017-02-21 20:24:59 +01:00
|
|
|
DeleteGuard< CBlip > dg(new CBlip(id));
|
2016-05-22 05:20:38 +02:00
|
|
|
// Create the script object
|
2017-02-21 20:24:59 +01:00
|
|
|
inst.mObj = LightObj(inst.mInst, m_VM);
|
|
|
|
// Store the manager instance itself
|
|
|
|
inst.mInst = dg.Get();
|
|
|
|
// The instance is now managed by the script
|
|
|
|
dg.Release();
|
2016-05-22 05:20:38 +02:00
|
|
|
// Make sure that both the instance and script object could be created
|
|
|
|
if (!inst.mInst || inst.mObj.IsNull())
|
|
|
|
{
|
2017-02-21 20:24:59 +01:00
|
|
|
inst.ResetInstance();
|
2016-06-26 14:47:27 +02:00
|
|
|
// Now we can throw the error
|
2016-05-22 05:20:38 +02:00
|
|
|
STHROWF("Unable to create a blip instance for: %d", id);
|
|
|
|
}
|
|
|
|
// Assign the specified entity identifier
|
|
|
|
inst.mID = id;
|
|
|
|
// Specify whether the entity is owned by this plug-in
|
|
|
|
if (owned)
|
|
|
|
{
|
|
|
|
inst.mFlags |= ENF_OWNED;
|
|
|
|
}
|
|
|
|
else if (inst.mFlags & ENF_OWNED)
|
|
|
|
{
|
|
|
|
inst.mFlags ^= ENF_OWNED;
|
|
|
|
}
|
2017-02-21 20:24:59 +01:00
|
|
|
// Initialize the instance events
|
|
|
|
inst.InitEvents();
|
2016-05-22 05:20:38 +02:00
|
|
|
// Let the script callbacks know about this entity
|
|
|
|
EmitBlipCreated(id, header, payload);
|
2016-06-26 14:47:27 +02:00
|
|
|
// Return the allocated instance
|
|
|
|
return inst;
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
Core::CheckpointInst & Core::AllocCheckpoint(Int32 id, bool owned, Int32 header, LightObj & payload)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
|
|
|
// Make sure that the specified entity identifier is valid
|
|
|
|
if (INVALID_ENTITYEX(id, SQMOD_CHECKPOINT_POOL))
|
|
|
|
{
|
|
|
|
STHROWF("Cannot allocate checkpoint with invalid identifier: %d", id);
|
|
|
|
}
|
|
|
|
// Retrieve the specified entity instance
|
|
|
|
CheckpointInst & inst = m_Checkpoints[id];
|
|
|
|
// Make sure that the instance isn't already allocated
|
|
|
|
if (VALID_ENTITY(inst.mID))
|
|
|
|
{
|
2016-06-26 14:47:27 +02:00
|
|
|
return inst; // Return the existing instance
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
// Instantiate the entity manager
|
2017-02-21 20:24:59 +01:00
|
|
|
DeleteGuard< CCheckpoint > dg(new CCheckpoint(id));
|
2016-05-22 05:20:38 +02:00
|
|
|
// Create the script object
|
2017-02-21 20:24:59 +01:00
|
|
|
inst.mObj = LightObj(inst.mInst, m_VM);
|
|
|
|
// Store the manager instance itself
|
|
|
|
inst.mInst = dg.Get();
|
|
|
|
// The instance is now managed by the script
|
|
|
|
dg.Release();
|
2016-05-22 05:20:38 +02:00
|
|
|
// Make sure that both the instance and script object could be created
|
|
|
|
if (!inst.mInst || inst.mObj.IsNull())
|
|
|
|
{
|
2017-02-21 20:24:59 +01:00
|
|
|
inst.ResetInstance();
|
2016-06-26 14:47:27 +02:00
|
|
|
// Now we can throw the error
|
2016-05-22 05:20:38 +02:00
|
|
|
STHROWF("Unable to create a checkpoint instance for: %d", id);
|
|
|
|
}
|
|
|
|
// Assign the specified entity identifier
|
|
|
|
inst.mID = id;
|
|
|
|
// Specify whether the entity is owned by this plug-in
|
|
|
|
if (owned)
|
|
|
|
{
|
|
|
|
inst.mFlags |= ENF_OWNED;
|
|
|
|
}
|
|
|
|
else if (inst.mFlags & ENF_OWNED)
|
|
|
|
{
|
|
|
|
inst.mFlags ^= ENF_OWNED;
|
|
|
|
}
|
2017-02-21 20:24:59 +01:00
|
|
|
// Initialize the instance events
|
|
|
|
inst.InitEvents();
|
2016-05-22 05:20:38 +02:00
|
|
|
// Let the script callbacks know about this entity
|
|
|
|
EmitCheckpointCreated(id, header, payload);
|
2016-06-26 14:47:27 +02:00
|
|
|
// Return the allocated instance
|
|
|
|
return inst;
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
Core::KeybindInst & Core::AllocKeybind(Int32 id, bool owned, Int32 header, LightObj & payload)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
|
|
|
// Make sure that the specified entity identifier is valid
|
|
|
|
if (INVALID_ENTITYEX(id, SQMOD_KEYBIND_POOL))
|
|
|
|
{
|
|
|
|
STHROWF("Cannot allocate keybind with invalid identifier: %d", id);
|
|
|
|
}
|
|
|
|
// Retrieve the specified entity instance
|
|
|
|
KeybindInst & inst = m_Keybinds[id];
|
|
|
|
// Make sure that the instance isn't already allocated
|
|
|
|
if (VALID_ENTITY(inst.mID))
|
|
|
|
{
|
2016-06-26 14:47:27 +02:00
|
|
|
return inst; // Return the existing instance
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
// Instantiate the entity manager
|
2017-02-21 20:24:59 +01:00
|
|
|
DeleteGuard< CKeybind > dg(new CKeybind(id));
|
2016-05-22 05:20:38 +02:00
|
|
|
// Create the script object
|
2017-02-21 20:24:59 +01:00
|
|
|
inst.mObj = LightObj(inst.mInst, m_VM);
|
|
|
|
// Store the manager instance itself
|
|
|
|
inst.mInst = dg.Get();
|
|
|
|
// The instance is now managed by the script
|
|
|
|
dg.Release();
|
2016-05-22 05:20:38 +02:00
|
|
|
// Make sure that both the instance and script object could be created
|
|
|
|
if (!inst.mInst || inst.mObj.IsNull())
|
|
|
|
{
|
2017-02-21 20:24:59 +01:00
|
|
|
inst.ResetInstance();
|
2016-06-26 14:47:27 +02:00
|
|
|
// Now we can throw the error
|
2016-05-22 05:20:38 +02:00
|
|
|
STHROWF("Unable to create a keybind instance for: %d", id);
|
|
|
|
}
|
|
|
|
// Assign the specified entity identifier
|
|
|
|
inst.mID = id;
|
|
|
|
// Specify whether the entity is owned by this plug-in
|
|
|
|
if (owned)
|
|
|
|
{
|
|
|
|
inst.mFlags |= ENF_OWNED;
|
|
|
|
}
|
|
|
|
else if (inst.mFlags & ENF_OWNED)
|
|
|
|
{
|
|
|
|
inst.mFlags ^= ENF_OWNED;
|
|
|
|
}
|
2017-02-21 20:24:59 +01:00
|
|
|
// Initialize the instance events
|
|
|
|
inst.InitEvents();
|
2016-05-22 05:20:38 +02:00
|
|
|
// Let the script callbacks know about this entity
|
|
|
|
EmitKeybindCreated(id, header, payload);
|
2016-06-26 14:47:27 +02:00
|
|
|
// Return the allocated instance
|
|
|
|
return inst;
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
Core::ObjectInst & Core::AllocObject(Int32 id, bool owned, Int32 header, LightObj & payload)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
|
|
|
// Make sure that the specified entity identifier is valid
|
|
|
|
if (INVALID_ENTITYEX(id, SQMOD_OBJECT_POOL))
|
|
|
|
{
|
|
|
|
STHROWF("Cannot allocate object with invalid identifier: %d", id);
|
|
|
|
}
|
|
|
|
// Retrieve the specified entity instance
|
|
|
|
ObjectInst & inst = m_Objects[id];
|
|
|
|
// Make sure that the instance isn't already allocated
|
|
|
|
if (VALID_ENTITY(inst.mID))
|
|
|
|
{
|
2016-06-26 14:47:27 +02:00
|
|
|
return inst; // Return the existing instance
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
// Instantiate the entity manager
|
2017-02-21 20:24:59 +01:00
|
|
|
DeleteGuard< CObject > dg(new CObject(id));
|
2016-05-22 05:20:38 +02:00
|
|
|
// Create the script object
|
2017-02-21 20:24:59 +01:00
|
|
|
inst.mObj = LightObj(inst.mInst, m_VM);
|
|
|
|
// Store the manager instance itself
|
|
|
|
inst.mInst = dg.Get();
|
|
|
|
// The instance is now managed by the script
|
|
|
|
dg.Release();
|
2016-05-22 05:20:38 +02:00
|
|
|
// Make sure that both the instance and script object could be created
|
|
|
|
if (!inst.mInst || inst.mObj.IsNull())
|
|
|
|
{
|
2017-02-21 20:24:59 +01:00
|
|
|
inst.ResetInstance();
|
2016-06-26 14:47:27 +02:00
|
|
|
// Now we can throw the error
|
2016-05-22 05:20:38 +02:00
|
|
|
STHROWF("Unable to create a object instance for: %d", id);
|
|
|
|
}
|
|
|
|
// Assign the specified entity identifier
|
|
|
|
inst.mID = id;
|
|
|
|
// Specify whether the entity is owned by this plug-in
|
|
|
|
if (owned)
|
|
|
|
{
|
|
|
|
inst.mFlags |= ENF_OWNED;
|
|
|
|
}
|
|
|
|
else if (inst.mFlags & ENF_OWNED)
|
|
|
|
{
|
|
|
|
inst.mFlags ^= ENF_OWNED;
|
|
|
|
}
|
2017-02-21 20:24:59 +01:00
|
|
|
// Initialize the instance events
|
|
|
|
inst.InitEvents();
|
2016-05-22 05:20:38 +02:00
|
|
|
// Let the script callbacks know about this entity
|
|
|
|
EmitObjectCreated(id, header, payload);
|
2016-06-26 14:47:27 +02:00
|
|
|
// Return the allocated instance
|
|
|
|
return inst;
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
Core::PickupInst & Core::AllocPickup(Int32 id, bool owned, Int32 header, LightObj & payload)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
|
|
|
// Make sure that the specified entity identifier is valid
|
|
|
|
if (INVALID_ENTITYEX(id, SQMOD_PICKUP_POOL))
|
|
|
|
{
|
|
|
|
STHROWF("Cannot allocate pickup with invalid identifier: %d", id);
|
|
|
|
}
|
|
|
|
// Retrieve the specified entity instance
|
|
|
|
PickupInst & inst = m_Pickups[id];
|
|
|
|
// Make sure that the instance isn't already allocated
|
|
|
|
if (VALID_ENTITY(inst.mID))
|
|
|
|
{
|
2016-06-26 14:47:27 +02:00
|
|
|
return inst; // Return the existing instance
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
// Instantiate the entity manager
|
2017-02-21 20:24:59 +01:00
|
|
|
DeleteGuard< CPickup > dg(new CPickup(id));
|
2016-05-22 05:20:38 +02:00
|
|
|
// Create the script object
|
2017-02-21 20:24:59 +01:00
|
|
|
inst.mObj = LightObj(inst.mInst, m_VM);
|
|
|
|
// Store the manager instance itself
|
|
|
|
inst.mInst = dg.Get();
|
|
|
|
// The instance is now managed by the script
|
|
|
|
dg.Release();
|
2016-05-22 05:20:38 +02:00
|
|
|
// Make sure that both the instance and script object could be created
|
|
|
|
if (!inst.mInst || inst.mObj.IsNull())
|
|
|
|
{
|
2017-02-21 20:24:59 +01:00
|
|
|
inst.ResetInstance();
|
2016-06-26 14:47:27 +02:00
|
|
|
// Now we can throw the error
|
2016-05-22 05:20:38 +02:00
|
|
|
STHROWF("Unable to create a pickup instance for: %d", id);
|
|
|
|
}
|
|
|
|
// Assign the specified entity identifier
|
|
|
|
inst.mID = id;
|
|
|
|
// Specify whether the entity is owned by this plug-in
|
|
|
|
if (owned)
|
|
|
|
{
|
|
|
|
inst.mFlags |= ENF_OWNED;
|
|
|
|
}
|
|
|
|
else if (inst.mFlags & ENF_OWNED)
|
|
|
|
{
|
|
|
|
inst.mFlags ^= ENF_OWNED;
|
|
|
|
}
|
2017-02-21 20:24:59 +01:00
|
|
|
// Initialize the instance events
|
|
|
|
inst.InitEvents();
|
2016-05-22 05:20:38 +02:00
|
|
|
// Let the script callbacks know about this entity
|
|
|
|
EmitPickupCreated(id, header, payload);
|
2016-06-26 14:47:27 +02:00
|
|
|
// Return the allocated instance
|
|
|
|
return inst;
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
Core::VehicleInst & Core::AllocVehicle(Int32 id, bool owned, Int32 header, LightObj & payload)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
|
|
|
// Make sure that the specified entity identifier is valid
|
|
|
|
if (INVALID_ENTITYEX(id, SQMOD_VEHICLE_POOL))
|
|
|
|
{
|
|
|
|
STHROWF("Cannot allocate vehicle with invalid identifier: %d", id);
|
|
|
|
}
|
|
|
|
// Retrieve the specified entity instance
|
|
|
|
VehicleInst & inst = m_Vehicles[id];
|
|
|
|
// Make sure that the instance isn't already allocated
|
|
|
|
if (VALID_ENTITY(inst.mID))
|
|
|
|
{
|
2016-06-26 14:47:27 +02:00
|
|
|
return inst; // Return the existing instance
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
// Instantiate the entity manager
|
2017-02-21 20:24:59 +01:00
|
|
|
DeleteGuard< CVehicle > dg(new CVehicle(id));
|
2016-05-22 05:20:38 +02:00
|
|
|
// Create the script object
|
2017-02-21 20:24:59 +01:00
|
|
|
inst.mObj = LightObj(inst.mInst, m_VM);
|
|
|
|
// Store the manager instance itself
|
|
|
|
inst.mInst = dg.Get();
|
|
|
|
// The instance is now managed by the script
|
|
|
|
dg.Release();
|
2016-05-22 05:20:38 +02:00
|
|
|
// Make sure that both the instance and script object could be created
|
|
|
|
if (!inst.mInst || inst.mObj.IsNull())
|
|
|
|
{
|
2017-02-21 20:24:59 +01:00
|
|
|
inst.ResetInstance();
|
2016-06-26 14:47:27 +02:00
|
|
|
// Now we can throw the error
|
2016-05-22 05:20:38 +02:00
|
|
|
STHROWF("Unable to create a vehicle instance for: %d", id);
|
|
|
|
}
|
|
|
|
// Assign the specified entity identifier
|
|
|
|
inst.mID = id;
|
|
|
|
// Specify whether the entity is owned by this plug-in
|
|
|
|
if (owned)
|
|
|
|
{
|
|
|
|
inst.mFlags |= ENF_OWNED;
|
|
|
|
}
|
|
|
|
else if (inst.mFlags & ENF_OWNED)
|
|
|
|
{
|
|
|
|
inst.mFlags ^= ENF_OWNED;
|
|
|
|
}
|
2017-02-21 20:24:59 +01:00
|
|
|
// Initialize the instance events
|
|
|
|
inst.InitEvents();
|
2016-05-22 05:20:38 +02:00
|
|
|
// Let the script callbacks know about this entity
|
|
|
|
EmitVehicleCreated(id, header, payload);
|
2016-06-26 14:47:27 +02:00
|
|
|
// Return the allocated instance
|
|
|
|
return inst;
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
void Core::DeallocBlip(Int32 id, bool destroy, Int32 header, LightObj & payload)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
|
|
|
// Make sure that the specified entity identifier is valid
|
|
|
|
if (INVALID_ENTITYEX(id, SQMOD_BLIP_POOL))
|
|
|
|
{
|
|
|
|
STHROWF("Cannot deallocate blip with invalid identifier: %d", id);
|
|
|
|
}
|
|
|
|
// Retrieve the specified entity instance
|
|
|
|
BlipInst & inst = m_Blips[id];
|
2016-07-16 18:39:51 +02:00
|
|
|
// Make sure that the instance is even allocated and we are allowed to destroy it
|
|
|
|
if (VALID_ENTITY(inst.mID) && !(inst.mFlags & ENF_LOCKED))
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
2016-07-16 18:39:51 +02:00
|
|
|
inst.Destroy(destroy, header, payload); // Now attempt to destroy the entity from the server
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
void Core::DeallocCheckpoint(Int32 id, bool destroy, Int32 header, LightObj & payload)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
|
|
|
// Make sure that the specified entity identifier is valid
|
|
|
|
if (INVALID_ENTITYEX(id, SQMOD_CHECKPOINT_POOL))
|
|
|
|
{
|
|
|
|
STHROWF("Cannot deallocate checkpoint with invalid identifier: %d", id);
|
|
|
|
}
|
|
|
|
// Retrieve the specified entity instance
|
|
|
|
CheckpointInst & inst = m_Checkpoints[id];
|
2016-07-16 18:39:51 +02:00
|
|
|
// Make sure that the instance is even allocated and we are allowed to destroy it
|
|
|
|
if (VALID_ENTITY(inst.mID) && !(inst.mFlags & ENF_LOCKED))
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
2016-07-16 18:39:51 +02:00
|
|
|
inst.Destroy(destroy, header, payload); // Now attempt to destroy the entity from the server
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
void Core::DeallocKeybind(Int32 id, bool destroy, Int32 header, LightObj & payload)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
|
|
|
// Make sure that the specified entity identifier is valid
|
|
|
|
if (INVALID_ENTITYEX(id, SQMOD_KEYBIND_POOL))
|
|
|
|
{
|
|
|
|
STHROWF("Cannot deallocate keybind with invalid identifier: %d", id);
|
|
|
|
}
|
|
|
|
// Retrieve the specified entity instance
|
|
|
|
KeybindInst & inst = m_Keybinds[id];
|
2016-07-16 18:39:51 +02:00
|
|
|
// Make sure that the instance is even allocated and we are allowed to destroy it
|
|
|
|
if (VALID_ENTITY(inst.mID) && !(inst.mFlags & ENF_LOCKED))
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
2016-07-16 18:39:51 +02:00
|
|
|
inst.Destroy(destroy, header, payload); // Now attempt to destroy the entity from the server
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
void Core::DeallocObject(Int32 id, bool destroy, Int32 header, LightObj & payload)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
|
|
|
// Make sure that the specified entity identifier is valid
|
|
|
|
if (INVALID_ENTITYEX(id, SQMOD_OBJECT_POOL))
|
|
|
|
{
|
|
|
|
STHROWF("Cannot deallocate object with invalid identifier: %d", id);
|
|
|
|
}
|
|
|
|
// Retrieve the specified entity instance
|
|
|
|
ObjectInst & inst = m_Objects[id];
|
2016-07-16 18:39:51 +02:00
|
|
|
// Make sure that the instance is even allocated and we are allowed to destroy it
|
|
|
|
if (VALID_ENTITY(inst.mID) && !(inst.mFlags & ENF_LOCKED))
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
2016-07-16 18:39:51 +02:00
|
|
|
inst.Destroy(destroy, header, payload); // Now attempt to destroy the entity from the server
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
void Core::DeallocPickup(Int32 id, bool destroy, Int32 header, LightObj & payload)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
|
|
|
// Make sure that the specified entity identifier is valid
|
|
|
|
if (INVALID_ENTITYEX(id, SQMOD_PICKUP_POOL))
|
|
|
|
{
|
|
|
|
STHROWF("Cannot deallocate pickup with invalid identifier: %d", id);
|
|
|
|
}
|
|
|
|
// Retrieve the specified entity instance
|
|
|
|
PickupInst & inst = m_Pickups[id];
|
2016-07-16 18:39:51 +02:00
|
|
|
// Make sure that the instance is even allocated and we are allowed to destroy it
|
|
|
|
if (VALID_ENTITY(inst.mID) && !(inst.mFlags & ENF_LOCKED))
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
2016-07-16 18:39:51 +02:00
|
|
|
inst.Destroy(destroy, header, payload); // Now attempt to destroy the entity from the server
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
void Core::DeallocVehicle(Int32 id, bool destroy, Int32 header, LightObj & payload)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
|
|
|
// Make sure that the specified entity identifier is valid
|
|
|
|
if (INVALID_ENTITYEX(id, SQMOD_VEHICLE_POOL))
|
|
|
|
{
|
|
|
|
STHROWF("Cannot deallocate vehicle with invalid identifier: %d", id);
|
|
|
|
}
|
|
|
|
// Retrieve the specified entity instance
|
|
|
|
VehicleInst & inst = m_Vehicles[id];
|
2016-07-16 18:39:51 +02:00
|
|
|
// Make sure that the instance is even allocated and we are allowed to destroy it
|
|
|
|
if (VALID_ENTITY(inst.mID) && !(inst.mFlags & ENF_LOCKED))
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
2016-07-16 18:39:51 +02:00
|
|
|
inst.Destroy(destroy, header, payload); // Now attempt to destroy the entity from the server
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
LightObj & Core::NewBlip(Int32 index, Int32 world, Float32 x, Float32 y, Float32 z,
|
2016-05-22 05:20:38 +02:00
|
|
|
Int32 scale, Uint32 color, Int32 sprid,
|
2017-02-21 20:24:59 +01:00
|
|
|
Int32 header, LightObj & payload)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
|
|
|
// Request the server to create this entity
|
|
|
|
const Int32 id = _Func->CreateCoordBlip(index, world, x, y, z, scale, color, sprid);
|
|
|
|
// See if the entity creation failed on the server
|
|
|
|
if (_Func->GetLastError() == vcmpErrorPoolExhausted)
|
|
|
|
{
|
|
|
|
STHROWF("Blip pool was exhausted: %d", id);
|
|
|
|
}
|
|
|
|
// Validate the identifier returned by the server
|
|
|
|
else if (INVALID_ENTITYEX(id, SQMOD_BLIP_POOL))
|
|
|
|
{
|
|
|
|
STHROWF("Server returned invalid blip: %d", id);
|
|
|
|
}
|
2016-06-26 14:47:27 +02:00
|
|
|
// Attempt to allocate this entity and grab the reference to the instance
|
|
|
|
BlipInst & inst = AllocBlip(id, true, header, payload);
|
|
|
|
// Just in case it was created during the notification for changes in entity pool
|
|
|
|
if (VALID_ENTITY(inst.mID))
|
|
|
|
{
|
|
|
|
inst.mFlags |= ENF_OWNED;
|
|
|
|
}
|
|
|
|
// Now we can return the script object
|
|
|
|
return inst.mObj;
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
LightObj & Core::NewCheckpoint(Int32 player, Int32 world, bool sphere, Float32 x, Float32 y, Float32 z,
|
2016-05-22 05:20:38 +02:00
|
|
|
Uint8 r, Uint8 g, Uint8 b, Uint8 a, Float32 radius,
|
2017-02-21 20:24:59 +01:00
|
|
|
Int32 header, LightObj & payload)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
|
|
|
// Request the server to create this entity
|
|
|
|
const Int32 id = _Func->CreateCheckPoint(player, world, sphere, x, y, z, r, g, b, a, radius);
|
|
|
|
// See if the entity creation failed on the server
|
|
|
|
if (_Func->GetLastError() == vcmpErrorNoSuchEntity)
|
|
|
|
{
|
|
|
|
STHROWF("Invalid player reference: %d", player);
|
|
|
|
}
|
|
|
|
else if (_Func->GetLastError() == vcmpErrorPoolExhausted)
|
|
|
|
{
|
|
|
|
STHROWF("Checkpoint pool was exhausted: %d", id);
|
|
|
|
}
|
|
|
|
// Validate the identifier returned by the server
|
|
|
|
else if (INVALID_ENTITYEX(id, SQMOD_CHECKPOINT_POOL))
|
|
|
|
{
|
|
|
|
STHROWF("Server returned invalid checkpoint: %d", id);
|
|
|
|
}
|
2016-06-26 14:47:27 +02:00
|
|
|
// Attempt to allocate this entity and grab the reference to the instance
|
|
|
|
CheckpointInst & inst = AllocCheckpoint(id, true, header, payload);
|
|
|
|
// Just in case it was created during the notification for changes in entity pool
|
|
|
|
if (VALID_ENTITY(inst.mID))
|
|
|
|
{
|
|
|
|
inst.mFlags |= ENF_OWNED;
|
|
|
|
}
|
|
|
|
// Now we can return the script object
|
|
|
|
return inst.mObj;
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
LightObj & Core::NewKeybind(Int32 slot, bool release, Int32 primary, Int32 secondary, Int32 alternative,
|
|
|
|
Int32 header, LightObj & payload)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
2016-06-20 07:02:30 +02:00
|
|
|
// Should we obtain a new keybind slot automatically?
|
|
|
|
if (slot < 0)
|
|
|
|
{
|
|
|
|
slot = _Func->GetKeyBindUnusedSlot();
|
|
|
|
}
|
2016-06-20 08:02:13 +02:00
|
|
|
// Validate the keybind slot returned by the server
|
|
|
|
if (INVALID_ENTITYEX(slot, SQMOD_KEYBIND_POOL))
|
2016-06-20 07:02:30 +02:00
|
|
|
{
|
2016-06-20 08:02:13 +02:00
|
|
|
STHROWF("Server returned invalid keybind slot: %d", slot);
|
2016-06-20 07:02:30 +02:00
|
|
|
}
|
2016-05-22 05:20:38 +02:00
|
|
|
// Request the server to create this entity
|
2016-06-20 08:02:13 +02:00
|
|
|
const vcmpError result = _Func->RegisterKeyBind(slot, release, primary, secondary, alternative);
|
2016-05-22 05:20:38 +02:00
|
|
|
// See if the entity creation failed on the server
|
2016-06-20 08:02:13 +02:00
|
|
|
if (result == vcmpErrorArgumentOutOfBounds)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
2016-06-20 08:02:13 +02:00
|
|
|
STHROWF("Out of bounds keybind argument: %d", slot);
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
2016-06-26 14:47:27 +02:00
|
|
|
// Attempt to allocate this entity and grab the reference to the instance
|
|
|
|
KeybindInst & inst = AllocKeybind(slot, true, header, payload);
|
|
|
|
// Just in case it was created during the notification for changes in entity pool
|
|
|
|
if (VALID_ENTITY(inst.mID))
|
|
|
|
{
|
|
|
|
inst.mFlags |= ENF_OWNED;
|
|
|
|
}
|
|
|
|
// Now we can return the script object
|
|
|
|
return inst.mObj;
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
LightObj & Core::NewObject(Int32 model, Int32 world, Float32 x, Float32 y, Float32 z, Int32 alpha,
|
|
|
|
Int32 header, LightObj & payload)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
|
|
|
// Request the server to create this entity
|
|
|
|
const Int32 id = _Func->CreateObject(model, world, x, y, z, alpha);
|
|
|
|
// See if the entity creation failed on the server
|
|
|
|
if (_Func->GetLastError() == vcmpErrorPoolExhausted)
|
|
|
|
{
|
|
|
|
STHROWF("Object pool was exhausted: %d", id);
|
|
|
|
}
|
|
|
|
// Validate the identifier returned by the server
|
|
|
|
else if (INVALID_ENTITYEX(id, SQMOD_OBJECT_POOL))
|
|
|
|
{
|
|
|
|
STHROWF("Server returned invalid object: %d", id);
|
|
|
|
}
|
2016-06-26 14:47:27 +02:00
|
|
|
// Attempt to allocate this entity and grab the reference to the instance
|
|
|
|
ObjectInst & inst = AllocObject(id, true, header, payload);
|
|
|
|
// Just in case it was created during the notification for changes in entity pool
|
|
|
|
if (VALID_ENTITY(inst.mID))
|
|
|
|
{
|
|
|
|
inst.mFlags |= ENF_OWNED;
|
|
|
|
}
|
|
|
|
// Now we can return the script object
|
|
|
|
return inst.mObj;
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
LightObj & Core::NewPickup(Int32 model, Int32 world, Int32 quantity,
|
2016-05-22 05:20:38 +02:00
|
|
|
Float32 x, Float32 y, Float32 z, Int32 alpha, bool automatic,
|
2017-02-21 20:24:59 +01:00
|
|
|
Int32 header, LightObj & payload)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
|
|
|
// Request the server to create this entity
|
|
|
|
const Int32 id = _Func->CreatePickup(model, world, quantity, x, y, z, alpha, automatic);
|
|
|
|
// See if the entity creation failed on the server
|
|
|
|
if (_Func->GetLastError() == vcmpErrorPoolExhausted)
|
|
|
|
{
|
|
|
|
STHROWF("Pickup pool was exhausted: %d", id);
|
|
|
|
}
|
|
|
|
// Validate the identifier returned by the server
|
|
|
|
else if (INVALID_ENTITYEX(id, SQMOD_PICKUP_POOL))
|
|
|
|
{
|
|
|
|
STHROWF("Server returned invalid pickup: %d", id);
|
|
|
|
}
|
2016-06-26 14:47:27 +02:00
|
|
|
// Attempt to allocate this entity and grab the reference to the instance
|
|
|
|
PickupInst & inst = AllocPickup(id, true, header, payload);
|
|
|
|
// Just in case it was created during the notification for changes in entity pool
|
|
|
|
if (VALID_ENTITY(inst.mID))
|
|
|
|
{
|
|
|
|
inst.mFlags |= ENF_OWNED;
|
|
|
|
}
|
|
|
|
// Now we can return the script object
|
|
|
|
return inst.mObj;
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
LightObj & Core::NewVehicle(Int32 model, Int32 world, Float32 x, Float32 y, Float32 z,
|
2016-05-22 05:20:38 +02:00
|
|
|
Float32 angle, Int32 primary, Int32 secondary,
|
2017-02-21 20:24:59 +01:00
|
|
|
Int32 header, LightObj & payload)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
2016-06-26 14:47:27 +02:00
|
|
|
|
2016-05-22 05:20:38 +02:00
|
|
|
// Request the server to create this entity
|
|
|
|
const Int32 id = _Func->CreateVehicle(model, world, x, y, z, angle, primary, secondary);
|
|
|
|
// See if the entity creation failed on the server
|
|
|
|
if (_Func->GetLastError() == vcmpErrorArgumentOutOfBounds)
|
|
|
|
{
|
|
|
|
STHROWF("Out of bounds vehicle argument: %d", id);
|
|
|
|
}
|
|
|
|
else if (_Func->GetLastError() == vcmpErrorPoolExhausted)
|
|
|
|
{
|
|
|
|
STHROWF("Vehicle pool was exhausted: %d", id);
|
|
|
|
}
|
|
|
|
// Validate the identifier returned by the server
|
|
|
|
else if (INVALID_ENTITYEX(id, SQMOD_VEHICLE_POOL))
|
|
|
|
{
|
|
|
|
STHROWF("Server returned invalid vehicle: %d", id);
|
|
|
|
}
|
2016-06-26 14:47:27 +02:00
|
|
|
// Attempt to allocate this entity and grab the reference to the instance
|
|
|
|
VehicleInst & inst = AllocVehicle(id, true, header, payload);
|
|
|
|
// Just in case it was created during the notification for changes in entity pool
|
|
|
|
if (VALID_ENTITY(inst.mID))
|
|
|
|
{
|
|
|
|
inst.mFlags |= ENF_OWNED;
|
|
|
|
}
|
|
|
|
// Now we can return the script object
|
|
|
|
return inst.mObj;
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
bool Core::DelBlip(Int32 id, Int32 header, LightObj & payload)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
|
|
|
// Attempt to destroy and deallocate the specified entity instance
|
|
|
|
DeallocBlip(id, true, header, payload);
|
|
|
|
// The entity could be destroyed
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
bool Core::DelCheckpoint(Int32 id, Int32 header, LightObj & payload)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
|
|
|
// Attempt to destroy and deallocate the specified entity instance
|
|
|
|
DeallocCheckpoint(id, true, header, payload);
|
|
|
|
// The entity could be destroyed
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
bool Core::DelKeybind(Int32 id, Int32 header, LightObj & payload)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
|
|
|
// Attempt to destroy and deallocate the specified entity instance
|
|
|
|
DeallocKeybind(id, true, header, payload);
|
|
|
|
// The entity could be destroyed
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
bool Core::DelObject(Int32 id, Int32 header, LightObj & payload)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
|
|
|
// Attempt to destroy and deallocate the specified entity instance
|
|
|
|
DeallocObject(id, true, header, payload);
|
|
|
|
// The entity could be destroyed
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
bool Core::DelPickup(Int32 id, Int32 header, LightObj & payload)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
|
|
|
// Attempt to destroy and deallocate the specified entity instance
|
|
|
|
DeallocPickup(id, true, header, payload);
|
|
|
|
// The entity could be destroyed
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ------------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
bool Core::DelVehicle(Int32 id, Int32 header, LightObj & payload)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
|
|
|
// Attempt to destroy and deallocate the specified entity instance
|
|
|
|
DeallocVehicle(id, true, header, payload);
|
|
|
|
// The entity could be destroyed
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-07-16 18:39:51 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
void Core::ConnectPlayer(Int32 id, Int32 header, LightObj & payload)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
|
|
|
// Make sure that the specified entity identifier is valid
|
|
|
|
if (INVALID_ENTITYEX(id, SQMOD_PLAYER_POOL))
|
|
|
|
{
|
|
|
|
STHROWF("Cannot allocate player with invalid identifier: %d", id);
|
|
|
|
}
|
|
|
|
// Retrieve the specified entity instance
|
|
|
|
PlayerInst & inst = m_Players[id];
|
|
|
|
// Make sure that the instance isn't already allocated
|
|
|
|
if (VALID_ENTITY(inst.mID))
|
|
|
|
{
|
|
|
|
return; // Nothing to allocate!
|
|
|
|
}
|
|
|
|
// Instantiate the entity manager
|
|
|
|
inst.mInst = new CPlayer(id);
|
|
|
|
// Create the script object
|
2017-02-21 20:24:59 +01:00
|
|
|
inst.mObj = LightObj(inst.mInst, m_VM);
|
2016-05-22 05:20:38 +02:00
|
|
|
// Make sure that both the instance and script object could be created
|
|
|
|
if (!inst.mInst || inst.mObj.IsNull())
|
|
|
|
{
|
2017-02-21 20:24:59 +01:00
|
|
|
inst.ResetInstance();
|
2016-05-22 05:20:38 +02:00
|
|
|
STHROWF("Unable to create a player instance for: %d", id);
|
|
|
|
}
|
|
|
|
// Assign the specified entity identifier
|
|
|
|
inst.mID = id;
|
|
|
|
// Initialize the position
|
|
|
|
_Func->GetPlayerPosition(id, &inst.mLastPosition.x, &inst.mLastPosition.y, &inst.mLastPosition.z);
|
|
|
|
// Initialize the remaining attributes
|
|
|
|
inst.mLastWeapon = _Func->GetPlayerWeapon(id);
|
|
|
|
inst.mLastHealth = _Func->GetPlayerHealth(id);
|
|
|
|
inst.mLastArmour = _Func->GetPlayerArmour(id);
|
|
|
|
inst.mLastHeading = _Func->GetPlayerHeading(id);
|
|
|
|
// Let the script callbacks know about this entity
|
|
|
|
EmitPlayerCreated(id, header, payload);
|
|
|
|
}
|
|
|
|
|
2016-07-16 18:39:51 +02:00
|
|
|
// ------------------------------------------------------------------------------------------------
|
2017-02-21 20:24:59 +01:00
|
|
|
void Core::DisconnectPlayer(Int32 id, Int32 header, LightObj & payload)
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
|
|
|
// Make sure that the specified entity identifier is valid
|
|
|
|
if (INVALID_ENTITYEX(id, SQMOD_PLAYER_POOL))
|
|
|
|
{
|
|
|
|
STHROWF("Cannot deallocate player with invalid identifier: %d", id);
|
|
|
|
}
|
|
|
|
// Retrieve the specified entity instance
|
|
|
|
PlayerInst & inst = m_Players[id];
|
2016-07-16 18:39:51 +02:00
|
|
|
// Make sure that the instance is even allocated and we are allowed to destroy it
|
|
|
|
if (VALID_ENTITY(inst.mID) && !(inst.mFlags & ENF_LOCKED))
|
2016-05-22 05:20:38 +02:00
|
|
|
{
|
2016-07-16 18:39:51 +02:00
|
|
|
inst.Destroy(false, header, payload); // Now attempt to destroy the entity from the server
|
2016-05-22 05:20:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // Namespace:: SqMod
|