Skip to content

RegisterClientAssets

Jérôme Leclercq edited this page Dec 8, 2020 · 1 revision

API: RegisterClientAssets

Description:

Registers an asset that can then be used client-side.
When a player joins the server, they will download all assets they don't have, either from FastDL or from the server itself.

Prototype:

RegisterClientAssets(asset: string)

Parameters:

  1. asset: Path to the asset (relative to the resource directory).

Remarks:

  1. All calls to RegisterClientAssets should be done at initialization, before any player joins.
  2. Only server-registered assets can be used client-side. If a client script tries to use a non-registered asset it will not be found by the game (independently from the file existence on the dive).
    The server and map editor don't have this restriction.
  3. This function exists client-side only for convenience and does nothing when called, as it's commonly called in shared element scripts.

Example code

A simple shared.lua entity using a custom asset

-- Registers the script client-side
RegisterClientScript()
-- Registers box.png as a client-side asset
RegisterClientAssets("box.png")

if (CLIENT) then
	entity:On("init", function (self)
		self:AddSprite({
			-- Using the asset
			TexturePath = "box.png"
		})
	end)
end

Clone this wiki locally