Actions¶
In Dyno terms, an action is something that admnistrators can trigger using the administrator panel. Each administrator has access to a list of actions within their permissions.
When creating an action, you can pass multiple options to configure the behavior and the appearance in the administration panel. The next sections will attempt to describe the different options and how to use them.
API¶
The function to create an action is member of the Dyno server module, and has two parameters.
Modules.Dyno.CreateAction(actionId, actionInfo)
The first is the action identifier (actionId
). It must be a string that is unique to each action. Internally, Dyno uses that to differentiate between each actions.
The second parameter is a table that has various fields, some which are optional. The following table list each possible field which are described in the next section.
field | type | default value |
---|---|---|
label | string | required |
execute | function | required |
permissions | list of string | {} |
shortLabel | string | same as label |
help | string | empty string |
form | Form | empty form |
formDefault | table | {} |
propagateToServers | boolean | true |
Required Information¶
Label¶
type: string
Execute¶
type: function
Options¶
The options described in this section are not required.
Permissions¶
type: list of strings
By default, no permissions are needed, so any administrator can run the action.
Short Label¶
type: string
Help¶
type: string
Form¶
type: table
For example, if you wanted to create an action that awards a certain amount of points to a player in the server, the administrator would need to specify the amount of points and the receiving player. For that, you would simply pass a value like the following example:
{
Player = 'playerId',
Points = 'positiveInteger',
}
Then, you'll get those values passed in to the first parameter of the provided execute
callback. Let's say one of the administrator encountered Builderman in your game and decided to award him 100 points. When the administrator will trigger the action, execute
will be called with this value:
{
Player = 156,
Points = 100,
}
To learn about all the different input kinds, visit the reference section about forms
Form Default¶
type: table
form
option. If you provided a form with a Bonus
input and would like to set it a default value of 50, you can do it like this: Modules.Dyno.CreateAction('some-id', {
label = 'Award Bonus',
execute = ...,
form = { Bonus = 'positiveInteger' }
formDefault = { Bonus = 50 }
})
Propagate To Server¶
By default, actions will run in all you game servers. You can override this behavior by settings the option propagateToServers
to false
when creating the action.
Modules.Dyno.CreateAction('some-id', {
label = 'My action',
execute = ...,
-- this will only run the action on the server where it is triggered
propagateToServers = false,
})
Code Example¶
Here is a quick little example of how to create an action that will let administrators (that have the 'lighting'
permission) change the daytime in all the game servers.
local Lighting = game:GetService('Lighting')
Modules.Dyno.CreateAction('action-id', {
label = 'Change Lighting Time',
execute = function(form)
Lighting.TimeOfDay = form.time
end,
-- below are the optional fields
permissions = { 'lighting' },
shortLabel = 'Change Time',
help = 'This action sets the TimeOfDay property of the Lighting service',
form = { time = 'string' },
formDefault = { time = '13:00:00' },
propagateToServers = true,
})