ReplaceFunction
This function was added in DSL 6
Description
Replace a base game C function with a given name
with a replacement
function.
If no replacement is given (or nil
), then any existing replacement will be removed. The replacement function is passed the original function and all the arguments that the function was called with. An exclusive
replacement should only be used when absolutely needed by your mod, as it will cause subsequent attempts to replace the function to fail.
Function replacements are tied to the current script, and will be automatically removed when the script is terminated.
Function replacements do not interfere with hooks, both can exist at the same time.
function ReplaceFunction(name, replacement, exclusive) --[[ ... ]] end
Parameters
name
:string
- The name of the function to replace.replacement?
:fun(originalFunc: function, ...: any): unknown
- (Optional) A function that will be called with the original function and all the arguments passed to the replaced function. Ifnil
, any existing replacement will be removed.exclusive
:boolean?
- (Optional) Iftrue
, this replacement will prevent any other replacements from being made to the same function. Defaults tofalse
.
Return Values
successful
:boolean
-true
if the replacement was successful,false
if the function does not exist or if an exclusive replacement was already made by another script.
Versions
- DSL5 - This function was introduced, but was not working properly.
- DSL6 - This function now works as intended.
Example
Make all created peds random.
ReplaceFunction("PedCreatePoint", function(original, model, point, index)
return original(4, point, index)
end)