mirror of
				https://github.com/VCMP-SqMod/SqMod.git
				synced 2025-11-04 08:17:19 +01:00 
			
		
		
		
	Implement functions to import existing entity instances after loading is complete.
This commit is contained in:
		@@ -168,7 +168,7 @@ void Register_Constants(HSQUIRRELVM vm)
 | 
			
		||||
        .Const(_SC("Pool"),         SQMOD_CREATE_POOL)
 | 
			
		||||
        .Const(_SC("Automatic"),    SQMOD_CREATE_AUTOMATIC)
 | 
			
		||||
        .Const(_SC("Overwrite"),    SQMOD_CREATE_OVERWRITE)
 | 
			
		||||
        .Const(_SC("Resurect"),     SQMOD_CREATE_RESURECT)
 | 
			
		||||
        .Const(_SC("Import"),       SQMOD_CREATE_IMPORT)
 | 
			
		||||
    );
 | 
			
		||||
 | 
			
		||||
    ConstTable(vm).Enum(_SC("SqDestroy"), Enumeration(vm)
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										188
									
								
								source/Core.cpp
									
									
									
									
									
								
							
							
						
						
									
										188
									
								
								source/Core.cpp
									
									
									
									
									
								
							@@ -337,6 +337,19 @@ bool Core::Load()
 | 
			
		||||
        // At this point the script should be completely loaded
 | 
			
		||||
        LogScs("Successfully executed script: %s", itr->first.c_str());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // Import already existing entities
 | 
			
		||||
    ImportPlayers();
 | 
			
		||||
    ImportBlips();
 | 
			
		||||
    ImportCheckpoints();
 | 
			
		||||
    ImportForcefields();
 | 
			
		||||
    ImportKeybinds();
 | 
			
		||||
    ImportObjects();
 | 
			
		||||
    ImportPickups();
 | 
			
		||||
    ImportSprites();
 | 
			
		||||
    ImportTextdraws();
 | 
			
		||||
    ImportVehicles();
 | 
			
		||||
 | 
			
		||||
    // Successfully loaded
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
@@ -463,6 +476,181 @@ void Core::CompilerErrorHandler(HSQUIRRELVM /*vm*/, CSStr desc, CSStr src, SQInt
 | 
			
		||||
    LogFtl("Message: %s\n[\n=>Location: %s\n=>Line: %d\n=>Column: %d\n]", desc, src, line, column);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// --------------------------------------------------------------------------------------------
 | 
			
		||||
void Core::ImportBlips()
 | 
			
		||||
{
 | 
			
		||||
    for (Int32 i = 0; i < SQMOD_BLIP_POOL; ++i)
 | 
			
		||||
    {
 | 
			
		||||
        // 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;
 | 
			
		||||
        // See if this entity exists on the server
 | 
			
		||||
        if (!_Func->GetCoordBlipInfo(i, &world, &x, &y, &z, &scale, &color, &sprid))
 | 
			
		||||
        {
 | 
			
		||||
            continue; // Nothing to import!
 | 
			
		||||
        }
 | 
			
		||||
        // Make sure this entity was not allocated already
 | 
			
		||||
        else if (INVALID_ENTITY(m_Blips[i].mID))
 | 
			
		||||
        {
 | 
			
		||||
            AllocBlip(i, false, SQMOD_CREATE_IMPORT, NullObject());
 | 
			
		||||
            // Assign the instance values
 | 
			
		||||
            m_Blips[i].mWorld = world;
 | 
			
		||||
            m_Blips[i].mScale = scale;
 | 
			
		||||
            m_Blips[i].mSprID = sprid;
 | 
			
		||||
            m_Blips[i].mPosition.Set(x, y, z);
 | 
			
		||||
            m_Blips[i].mColor.SetRGBA(color);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Core::ImportCheckpoints()
 | 
			
		||||
{
 | 
			
		||||
    for (Int32 i = 0; i < SQMOD_CHECKPOINT_POOL; ++i)
 | 
			
		||||
    {
 | 
			
		||||
        // See if this entity exists on the server
 | 
			
		||||
        if (_Func->GetCheckpointWorld(i) < 0)
 | 
			
		||||
        {
 | 
			
		||||
            continue; // Nothing to import!
 | 
			
		||||
        }
 | 
			
		||||
        // Make sure this entity was not allocated already
 | 
			
		||||
        else if (INVALID_ENTITY(m_Checkpoints[i].mID))
 | 
			
		||||
        {
 | 
			
		||||
            AllocCheckpoint(i, false, SQMOD_CREATE_IMPORT, NullObject());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Core::ImportForcefields()
 | 
			
		||||
{
 | 
			
		||||
    for (Int32 i = 0; i < SQMOD_FORCEFIELD_POOL; ++i)
 | 
			
		||||
    {
 | 
			
		||||
        // See if this entity exists on the server
 | 
			
		||||
        if (_Func->GetSphereWorld(i) < 0)
 | 
			
		||||
        {
 | 
			
		||||
            continue; // Nothing to import!
 | 
			
		||||
        }
 | 
			
		||||
        // Make sure this entity was not allocated already
 | 
			
		||||
        else if (INVALID_ENTITY(m_Forcefields[i].mID))
 | 
			
		||||
        {
 | 
			
		||||
            AllocForcefield(i, false, SQMOD_CREATE_IMPORT, NullObject());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Core::ImportKeybinds()
 | 
			
		||||
{
 | 
			
		||||
    for (Int32 i = 0; i < SQMOD_KEYBIND_POOL; ++i)
 | 
			
		||||
    {
 | 
			
		||||
        Uint32 release = 0;
 | 
			
		||||
        Int32 first = -1, second = -1, third = -1;
 | 
			
		||||
        // See if this entity exists on the server
 | 
			
		||||
        if (!_Func->GetKeyBindData(i, &release, &first, &second, &third))
 | 
			
		||||
        {
 | 
			
		||||
            continue; // Nothing to import!
 | 
			
		||||
        }
 | 
			
		||||
        // Make sure this entity was not allocated already
 | 
			
		||||
        else if (INVALID_ENTITY(m_Keybinds[i].mID))
 | 
			
		||||
        {
 | 
			
		||||
            AllocKeybind(i, false, SQMOD_CREATE_IMPORT, NullObject());
 | 
			
		||||
            // Assign the instance values
 | 
			
		||||
            m_Keybinds[i].mFirst = first;
 | 
			
		||||
            m_Keybinds[i].mSecond = second;
 | 
			
		||||
            m_Keybinds[i].mThird = third;
 | 
			
		||||
            m_Keybinds[i].mRelease = static_cast< bool >(release);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Core::ImportObjects()
 | 
			
		||||
{
 | 
			
		||||
    for (Int32 i = 0; i < SQMOD_OBJECT_POOL; ++i)
 | 
			
		||||
    {
 | 
			
		||||
        // See if this entity exists on the server
 | 
			
		||||
        if (_Func->GetObjectModel(i) <= 0)
 | 
			
		||||
        {
 | 
			
		||||
            continue; // Nothing to import!
 | 
			
		||||
        }
 | 
			
		||||
        // Make sure this entity was not allocated already
 | 
			
		||||
        else if (INVALID_ENTITY(m_Objects[i].mID))
 | 
			
		||||
        {
 | 
			
		||||
            AllocObject(i, false, SQMOD_CREATE_IMPORT, NullObject());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Core::ImportPickups()
 | 
			
		||||
{
 | 
			
		||||
    for (Int32 i = 0; i < SQMOD_PICKUP_POOL; ++i)
 | 
			
		||||
    {
 | 
			
		||||
        // See if this entity exists on the server
 | 
			
		||||
        if (_Func->PickupGetModel(i) <= 0)
 | 
			
		||||
        {
 | 
			
		||||
            continue; // Nothing to import!
 | 
			
		||||
        }
 | 
			
		||||
        // Make sure this entity was not allocated already
 | 
			
		||||
        else if (INVALID_ENTITY(m_Pickups[i].mID))
 | 
			
		||||
        {
 | 
			
		||||
            AllocPickup(i, false, SQMOD_CREATE_IMPORT, NullObject());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Core::ImportPlayers()
 | 
			
		||||
{
 | 
			
		||||
    for (Int32 i = 0; i < SQMOD_PLAYER_POOL; ++i)
 | 
			
		||||
    {
 | 
			
		||||
        // See if this entity exists on the server
 | 
			
		||||
        if (!_Func->IsPlayerConnected(i))
 | 
			
		||||
        {
 | 
			
		||||
            continue; // Nothing to import!
 | 
			
		||||
        }
 | 
			
		||||
        // Make sure this entity was not allocated already
 | 
			
		||||
        else if (INVALID_ENTITY(m_Players[i].mID))
 | 
			
		||||
        {
 | 
			
		||||
            ConnectPlayer(i, SQMOD_CREATE_IMPORT, NullObject());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Core::ImportSprites()
 | 
			
		||||
{
 | 
			
		||||
    /*
 | 
			
		||||
    for (Int32 i = 0; i < SQMOD_SPRITE_POOL; ++i)
 | 
			
		||||
    {
 | 
			
		||||
        // Not possible to detect with current SDK
 | 
			
		||||
    }
 | 
			
		||||
    */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Core::ImportTextdraws()
 | 
			
		||||
{
 | 
			
		||||
    /*
 | 
			
		||||
    for (Int32 i = 0; i < SQMOD_TEXTDRAW_POOL; ++i)
 | 
			
		||||
    {
 | 
			
		||||
        // Not possible to detect with current SDK
 | 
			
		||||
    }
 | 
			
		||||
    */
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Core::ImportVehicles()
 | 
			
		||||
{
 | 
			
		||||
    for (Int32 i = 0; i < SQMOD_VEHICLE_POOL; ++i)
 | 
			
		||||
    {
 | 
			
		||||
        // See if this entity exists on the server
 | 
			
		||||
        if (_Func->GetVehicleModel(i) <= 0)
 | 
			
		||||
        {
 | 
			
		||||
            continue; // Nothing to import!
 | 
			
		||||
        }
 | 
			
		||||
        // Make sure this entity was not allocated already
 | 
			
		||||
        else if (INVALID_ENTITY(m_Vehicles[i].mID))
 | 
			
		||||
        {
 | 
			
		||||
            AllocVehicle(i, false, SQMOD_CREATE_IMPORT, NullObject());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
// --------------------------------------------------------------------------------------------
 | 
			
		||||
Object & Core::AllocBlip(Int32 id, bool owned, Int32 header, Object & payload)
 | 
			
		||||
{
 | 
			
		||||
 
 | 
			
		||||
@@ -532,6 +532,20 @@ protected:
 | 
			
		||||
    static void CompilerErrorHandler(HSQUIRRELVM vm, CSStr desc, CSStr src,
 | 
			
		||||
                                        SQInteger line, SQInteger column);
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Entity instance scaners.
 | 
			
		||||
    */
 | 
			
		||||
    void ImportBlips();
 | 
			
		||||
    void ImportCheckpoints();
 | 
			
		||||
    void ImportForcefields();
 | 
			
		||||
    void ImportKeybinds();
 | 
			
		||||
    void ImportObjects();
 | 
			
		||||
    void ImportPickups();
 | 
			
		||||
    void ImportPlayers();
 | 
			
		||||
    void ImportSprites();
 | 
			
		||||
    void ImportTextdraws();
 | 
			
		||||
    void ImportVehicles();
 | 
			
		||||
 | 
			
		||||
    /* --------------------------------------------------------------------------------------------
 | 
			
		||||
     * Instance allocators.
 | 
			
		||||
    */
 | 
			
		||||
 
 | 
			
		||||
@@ -748,7 +748,7 @@ enum CmdError
 | 
			
		||||
#define SQMOD_CREATE_POOL       -4
 | 
			
		||||
#define SQMOD_CREATE_AUTOMATIC  -5
 | 
			
		||||
#define SQMOD_CREATE_OVERWRITE  -6
 | 
			
		||||
#define SQMOD_CREATE_RESURECT   -7
 | 
			
		||||
#define SQMOD_CREATE_IMPORT     -7
 | 
			
		||||
 | 
			
		||||
#define SQMOD_DESTROY_DEFAULT   0
 | 
			
		||||
#define SQMOD_DESTROY_MANUAL    -3
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user