-
Notifications
You must be signed in to change notification settings - Fork 2
Add Lua Scripts
Our R-Type game framework allows users to dynamically add their own scripts, written in Lua, to extend and customize game behavior. With Lua scripting, users can:
- Interact with R-Type's components.
- Add as many scripts as desired.
- Utilize Lua's base library for additional functionality.
To add a script, create a .lua
file in one of the following directories:
R-Type/R-TypeGame/Game/GameData/Scripts
R-Type/QuentinTheFarmerGame/Game/GameData/Scripts
Scripts placed in these folders will be dynamically loaded and executed. This enables adding or modifying code while the server or client is running, providing flexibility for real-time development.
The following Lua functions are provided to interact with game components, allowing users to get and set values for different data types: integer, float, string, and boolean.
-
getComponentsSize(componentType: string): int
Returns the number of components of the specified type.
-
getComponentIntArg(index: int, componentType: string, argument: string): int
Retrieves an integer value for a specified component argument. Returns nil if not found. -
setComponentIntArg(index: int, componentType: string, argument: string, value: int): bool
Sets an integer value for a specified component argument.
-
getComponentFloatArg(index: int, componentType: string, argument: string): float
Retrieves a float value for a specified component argument. Returns nil if not found. -
setComponentFloatArg(index: int, componentType: string, argument: string, value: float): bool
Sets a float value for a specified component argument.
-
getComponentStrArg(index: int, componentType: string, argument: string): string
Retrieves a string value for a specified component argument. Returns nil if not found. -
setComponentStrArg(index: int, componentType: string, argument: string, value: string): bool
Sets a string value for a specified component argument.
-
getComponentBoolArg(index: int, componentType: string, argument: string): bool
Retrieves a boolean value for a specified component argument. Returns nil if not found. -
setComponentBoolArg(index: int, componentType: string, argument: string, value: bool): bool
Sets a boolean value for a specified component argument.
These functions allow precise control and customization of game components through Lua scripting, supporting various data types for a more versatile and dynamic gameplay experience.
The following example demonstrates how to retrieve and modify RGB values of all "ColourComponent" instances, incrementing each color component by a different value.
for i = 0, getComponentsSize("ColourComponent") - 1 do
local r = getComponentIntArg(i, "ColourComponent", "r")
local g = getComponentIntArg(i, "ColourComponent", "g")
local b = getComponentIntArg(i, "ColourComponent", "b")
local a = getComponentIntArg(i, "ColourComponent", "a")
if r ~= nil and g ~= nil and b ~= nil and a ~= nil then
setComponentIntArg(i, "ColourComponent", "r", r + 1)
setComponentIntArg(i, "ColourComponent", "g", g + 2)
setComponentIntArg(i, "ColourComponent", "b", b + 3)
-- setComponentIntArg(i, "ColourComponent", "a", a + 1)
end
end