mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 22:11:38 +00:00
rules
This commit is contained in:
parent
a9b4f8e83b
commit
e6efc04756
8494 changed files with 495610 additions and 0 deletions
|
|
@ -0,0 +1,34 @@
|
|||
---
|
||||
title: include
|
||||
---
|
||||
|
||||
The following Luau code sample demonstrates how to, after a player equips a fishing pole, listen for user input (in this case, the <kbd>E</kbd> key) and call additional functions:
|
||||
|
||||
```lua
|
||||
local ContextActionService = game:GetService("ContextActionService")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
|
||||
-- Get a module script from ReplicatedStorage that returns a single function
|
||||
local performSomeAction = require(ReplicatedStorage.performSomeAction)
|
||||
|
||||
-- Assumes that this script is a child of the fishing pole
|
||||
local fishingPole = script.Parent
|
||||
local ACTION_CAST = "Cast"
|
||||
|
||||
-- Check that the key is down, then call another function
|
||||
local function castLine(_actionName, inputState, _inputObject)
|
||||
if inputState == Enum.UserInputState.Begin then
|
||||
performSomeAction()
|
||||
end
|
||||
end
|
||||
|
||||
-- Only enable the action when the player equips the fishing pole
|
||||
fishingPole.Equipped:Connect(function()
|
||||
ContextActionService:BindAction(ACTION_CAST, castLine, true, Enum.KeyCode.E)
|
||||
end)
|
||||
|
||||
-- Disable the action when the player unequips the fishing pole
|
||||
fishingPole.Unequipped:Connect(function()
|
||||
ContextActionService:UnbindAction(ACTION_CAST)
|
||||
end)
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue