Loading function...

Please make sure JavaScript is enabled. Otherwise you will be unable to see the function documentation.

Registers a new NativeScriptLoaded event handler, meaning Callback will be called when a base game script is loaded. The script's name and environment is passed to the function so it can apply changes and patches to the script, as well as give it modified versions of normal functions as a way of changing the script's behavior. Keep in mind that the name given is a full name, so you may need to print what it says when you expect a script to start in order to get the right name for it.

Arguments

Results

None.

Versions

DSL4 This function is now just for legacy support, and does the same thing calling RegisterLocalEventHandler with NativeScriptLoaded would.

Example

Change store prices to be free and stop the boy's dorm script from despawning little kids.

function F_ShopAddItem(...)
	arg[5] = 0
	return ShopAddItem(unpack(arg))
end
function F_Nothing()
end
AddScriptLoaderCallback(function(name, env)
	if name == "SStores.lua" then
		-- change SStores.lua's ShopAddItem to be our custom version so we can change prices
		env.ShopAddItem = F_ShopAddItem
	elseif name == "AreaScripts/Bdorm.lua" then
		-- change a function the bdorm script to stop little kids from being despawned
		env.F_KillAllLittleKids = F_Nothing
	end
	print("loaded "..name)
end)

Registers a new local event handler. The Callback function is called when the event is activated. The returned Event handler object is registered with the current script, meaning it will be removed when the script dies. If there is no current DSL script to register with, it will exist until removed manually with RemoveEventHandler.

An event Type is just a string. Although there are a few events built-in and listed below, you are free to define your own for any purpose. Just make sure the name is unique enough that it won't clash with what other developers are likely to use. This is a good way to allow your script's behavior to be influenced by scripts from other developers.

Arguments

Results

Events (client)

Type Description
DSL6CameraFaded(seconds, fadein) The camera is fading in or out. The arguments are the same as what is given to CameraFade.
DSL5ControllersUpdated() All controllers have been updated. This is a good time to call SetStickValue.
DSL5ControllerUpdating(id) A specific controller is being updated. This is a good time to call SetButtonPressed.
DSL5GameBeingPaused() The game will pause unless an event handler returns true.
DSL4NativeScriptLoaded(name, env) A base game script has been loaded and run, but not yet updated (meaning its main function hasn't run).
DSL5PedBeingCreated() A ped is about to be created. You can count peds with AllPeds to determine if you should delete a ped to prevent a crash.
DSL5PedStatOverriding(ped, stat, value) A ped's stat is being changed unless an event handler returns true. Beware setting the stat yourself will still activate the event.
DSL5PlayerSleepCheck() The game wants to check if the player should fall asleep, but will skip the check if an event handler returns true.
DSL5SaveGameLoading() A save game is going to be loaded unless an event handler returns true.
DSL5ServerConnected(address) A server has been fully connected to.
DSL5ServerConnecting(address) A server connection has begun.
DSL5ServerDisconnected(address) A server has been disconnected from. Always comes after a ServerConnecting event (unless the game is quit).
DSL5ServerDownloading() The server we're connecting to is downloading.
DSL5ServerKicked() The server has issued a kick.
DSL5ServerListing(address, listing) A server has provided listing information. The listing table contains name, info, mode, icon, players, and max_players.
DSL5WindowGoingFullscreen() The game will enter exclusive fullscreen mode unless an event handler returns true.
DSL5WindowMinimizing() The game's window will be minimized unless an event handler returns true.
DSL5WindowUpdating(window) The game's window can be customly styled if any event handler returns true. The window table contains fields describing the window.

Events (server)

Type Description
DSL5PlayerConnected(player) A player has fully connected and can be used safely with any networking functions.
DSL5PlayerConnecting(player) A player is connecting and can only be used with some functions. Kick them to prevent them from being connected.
DSL5PlayerDropped(player) A player has been dropped and all references to them should be removed. Will always come after a PlayerConnecting event.
DSL5PlayerListing(player, listing) A player requested listing information for the server. You can modify the listing table's info and mode. The player is only valid for the duration of this event.

Events (shared)

Type Description
DSL5ScriptPrinted(text, type) One of the print functions have been called. This is mainly designed to help forward console output into a server chat.

Remove an event handler created with RegisterLocalEventHandler.

Arguments

Results

None.

Activate an event of Type, passing any Arguments you want. Keep in mind that tables in Lua are passed by reference, so a decent strategy for allowing other scripts to respond to your event is by passing some sort of table. The Result is false unless at least one of the callbacks return true. This can be used as a way of letting certain events be cancelled, or for any other arbitrary use.

Arguments

Results