Override
It is generally advisable to useObserve whenever possible, and only use Override when absolutely necessary
Override is a built-in CET function allowing developers to rewrite a game's class method. It must be registered using the Override() function inside the onInit event, in the init.lua file.
The provided callback is always filled as follows:
The first argument is the current object that execute the method. This argument is not present when function/method is static.
Others arguments passed to the targeted method, if any.
The last argument is the original callable method.
Definition
Override(className, method, callback)--
-- Override()
--
-- @param string className The parent class name
-- @param string method The method name to target
-- @param function callback The callback function
--
Override('className', 'method', function(self [, arg1, arg2, ...], wrappedMethod)
-- rewrite method()
end)Representation
Considering the following class and method:
When applying Override(), the callback would be filled with the following arguments:
Using Wrapped Method
The last argument of the Override() function, wrappedMethod, contains the original method as a callable function. We can use it to execute the original code and/or retrieve its result (if it returns something).
It is highly recommended to know the overriden method return statement to avoid breaking the script, and use wrappedMethod accordingly.
Method -> Void
Any method declared void doesn't return a value. Overriding it follow the same logic:
Method -> Bool / Int / Float etc...
The same logic is applied to methods with a specific return statement. Overriding it must return a compatible type:
Usage Example
Do not allow the player to crouch:
Advanced Example
Do not allow the player to crouch if in ADS:
Last updated