Skip to content

RegisterServerEvent

Record a server-side event that is triggerable by the server and also by the client.
The event have the AddEventHandler already loaded

Argument Data Type Needed Default Description
EventName string - The name of the event
Function function - The code executed when the event was triggered
Auto-Prepare boolean true If setted to false don't auto-prepare the event for works with ESX (don't load the esx basic variable)
Other difference

It also auto-prepare the event to work with esx, so it auto load the xPlayer and _source variable

Don't need to be called every frame


Example
RegisterServerEvent("utility_libs:ILoveYou", function()
    print(GetPlayerName().." love the utility_libs, how to blame it?")
end)
Old method
RegisterServerEvent("utility_libs:ILoveYou")
AddEventHandler("utility_libs:ILoveYou", function()
    local _source = source
    local xPlayer = ESX.GetPlayerFromId(_source)

    print(GetPlayerName(PlayerId()).." love the utility_libs, how to blame it?")
end)
Using old native

although i don't recommend it, you can use the old native via old_RegisterServerEvent


Last update: April 12, 2022
Created: June 27, 2021