In-Game Shell Builder

A script by sModsk

No reviews yet.
In-Game Shell Builder main image

Full Description

In-Game Shell Building Script for FiveM

Features

This script allows players to create apartment shells or similar structures in-game, which can then be utilized in other scripts like apartment systems using exports.

  • Define the maximum shell width/depth and layers (Grid based system)
  • 8 Different Textures: With 30 color variations, offering diverse customization options.
  • Stairs: Include stairs within your shells to enhance vertical layout.
  • Interior Windows with Curtains: Add windows with curtains for a more realistic interior.
  • Doors: Place doors.
  • Railings: Place railings
  • Customizable Door Positions: Set front door and garage door positions using props.
Performance Optimization
  • Efficient Prop Combining: The script optimizes prop usage by combining smaller props into larger ones where possible. For example, in best scenario floor and ceiling props are combined from 16 props into 1, and wall props from 4 to 1, reducing the number of objects in the scene.
  • Data Storage and Organization: Data is saved in multiple rows based on layers and chunks. For example, one cell’s data might look like "9":[[0,1,0],[0,1,0],[1,1,0],[0,1,0],[1,8,25]].
  • Smaller Data Packages: To improve server performance, data is sent in smaller packages to clients, reducing the load on the server and improving overall efficiency.
Usage

This script is used by utilizing exports in other scripts. You can call the script’s functionality from your other scripts by using the provided export functions.

GitHub Resources:

  • shellBuilder_job: Players can create new shells as projects. Once a shell is finished, it can be published to the market for others to use.

  • ps-housing & ps-realtor: I was able to integrate shellBuilding with ps-housing and ps-realtor in a short time, making the created shells usable in these systems.

Credits: A huge thanks to the original creators of Project Sloth, ps-housing, and ps-realtor for their awesome work.

Exports

smodsk_shellBuilder - Exports

Client-Side Exports

Spawning a Shell

Asynchronous Method (Callback)

Spawns a shell at the given position and executes a callback when completed.

exports["smodsk_shellBuilder"]:SpawnShell(
    {
        id = id,
        position = position,

        --- Called when the door position changes.
        -- @param string door - Can be either `"door"` or `"garage"`.
        -- @param vector4 position - The new position of the door or garage.
        doorPositionChanged = function(door, position)
            -- Handle door position change
        end,

        -- By default false if not used
        canOpenMenu = function()
            return true
        end,
        -- By default false if not used
        canTogglePublic = function()
            return false
        end,
        -- By default false if not used
        canBuild = function()
            return true
        end,
        -- By default false if not used
        canPaint = function()
            return true
        end,
        -- By default true if not used
        canAddGarage = function()
            return true
        end,
        -- By default true if not used
        canAddFrontDoor = function()
            return true
        end,
    },

    --- Callback function when shell spawning is complete.
    -- @param boolean success - Whether the shell spawned successfully.
    -- @param vector4 doorPos - The position of the door.
    -- @param vector4 garagePos - The position of the garage.
    function(success, doorPos, garagePos)
        if success then  
            print("Shell spawned successfully!")
        else
            print("Shell spawn failed!")
        end  
    end
)

Synchronous Method (Return Values)

Waits for the function to return values instead of using a callback.

--- Spawns a shell and returns its success status along with door and garage positions.
-- @return boolean success - Whether the shell spawned successfully.
-- @return vector4 doorPos - The position of the door.
-- @return vector4 garagePos - The position of the garage door.
local success, doorPos, garagePos = exports["smodsk_shellBuilder"]:SpawnShell(
    {
        id = id,
        position = position,
        doorPositionChanged = function(door, position)
            --- Called when the door position changes.
            -- @param string door - Can be either `"door"` or `"garage"`.
            -- @param vector4 position - The new position of the door or garage.
            
            -- Handle door position change
        end,
        -- By default false if not used
        canOpenMenu = function()
            return true
        end,
        -- By default false if not used
        canTogglePublic = function()
            return false
        end,
        -- By default false if not used
        canBuild = function()
            return true
        end,
        -- By default false if not used
        canPaint = function()
            return true
        end,
        -- By default true if not used
        canAddGarage = function()
            return true
        end,
        -- By default true if not used
        canAddFrontDoor = function()
            return true
        end,
    })

Despawning a Shell

Removes the currently active shell instance from the world and clears relevant data.

exports["smodsk_shellBuilder"]:DespawnShell()

Retrieving Public Shell IDs

Returns the identifiers of all shells marked as public.

--- Retrieves a list of public shell IDs and their corresponding names.
-- @return table data - A list of public shells, where each entry contains:
--   - `id` (number): The shell's unique identifier.
--   - `name` (string): The shell's display name.
local data = exports["smodsk_shellBuilder"]:GetPublicIds()

Build Menu

-- Opens the build menu if the player is eligible to access it.
exports["smodsk_shellBuilder"]:OpenBuildMenu()

Server-Side Exports

Creating a New Shell

Creates a new shell and returns whether the operation was successful.

Synchronous Method

--- Creates a new shell.
-- @param string|nil id - The shell's unique ID. If `nil`, it is created automatically.
-- @param table|nil size - The shell's size, defined as `{width, layers}`. If `nil`, a default size is used.
-- @param string name - The name of the shell.
-- @return boolean success - Whether the shell was successfully created.
-- @return string shellId - The unique ID of the created shell.
local success, shellId = exports["smodsk_shellBuilder"]:CreateNewShell(id, size, name)

Asynchronous Method

--- Creates a new shell.
-- @param string|nil id - The shell's unique ID. If `nil`, it is created automatically.
-- @param table|nil size - The shell's size, defined as `{width, layers}`. If `nil`, a default size is used.
-- @param string name - The name of the shell.
-- @param function callback - A function called upon completion.
--   - @param boolean success - Whether the shell was successfully created.
exports["smodsk_shellBuilder"]:CreateNewShell(id, size, name, function(success)
    if success then
        print("Shell created successfully!")
    else
        print("Shell creation failed!")
    end
end)


Deleting a Shell

Deletes an existing shell.

--- Deletes an existing shell.
-- @param string id - The unique identifier of the shell to be deleted.
exports["smodsk_shellBuilder"]:DeleteShell(id)


Duplicating a Shell

Duplicates an existing shell with a new identifier.

Synchronous Method

--- Duplicates an existing shell with a new identifier.
-- If `newId` is `nil`, it will be automatically created.
-- @param string id - The unique identifier of the shell to duplicate.
-- @param string|nil newId - The unique identifier for the duplicated shell. If `nil`, a new ID is created automatically.
-- @return boolean success - Whether the duplication was successful.
-- @return string id - The unique identifier of the duplicated shell.
local success, id = exports["smodsk_shellBuilder"]:DuplicateShell(id, newId)

Asynchronous Method

--- Duplicates an existing shell with a new identifier asynchronously.
-- If `newId` is `nil`, it will be automatically created.
-- @param string id - The unique identifier of the shell to duplicate.
-- @param string|nil newId - The unique identifier for the duplicated shell. If `nil`, a new ID is created automatically.
-- @param function callback - A function that will be called once the duplication is complete.
--   - @param boolean success - Whether the duplication was successful.
--   - @param string id - The unique identifier of the duplicated shell.
exports["smodsk_shellBuilder"]:DuplicateShell(id, newId, function(success, id)
    if success then
        print("Shell duplicated successfully!")
    else
        print("Shell duplication failed!")
    end
end)

--- Adds or removes a shell from the public listing.
-- @param string id - The unique identifier of the shell.
-- @param boolean bool - A boolean value where `true` adds the shell to the public listing, and `false` removes it.
exports["smodsk_shellBuilder"]:SetPublic(id, bool)

Gifs

Screen capture - 68a33c2d5f521c6490e67c6946b4c3da - Gyazo
Screen capture - 22a6a6291fc42f1222ed44547b9279b6 - Gyazo
Screen capture - 3d85476f2e5a64872cdc332fff431552 - Gyazo

Future plans
  • More props
  • Texture replacement for more variations
  • It would be great to be able to integrate this into more apartment scripts
Code is accessible Partly
Subscription-based Yes & No
Lines (approximately) +12000
Requirements oxmysql
Support Yes

3d Models and textures approx 8mb

Assets are accessible Yes/No
Subscription-based Yes & No
Polygons (model and LOD) 10 - +100 depending on model
Texture size and amount 1024x1024 (+40 textures)
Requirements smodsk_shellBuilder
Support Yes

Other products