@quenty/characterutils 4.0.0-canary.236.5597d0a.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +49 -1
- package/README.md +11 -4
- package/package.json +6 -6
- package/src/Shared/CharacterPromiseUtils.lua +13 -33
- package/src/Shared/CharacterUtils.lua +60 -6
- package/src/Shared/RootPartUtils.lua +18 -4
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,55 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
-
# [4.0.0
|
|
6
|
+
# [4.0.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/characterutils@3.6.0...@quenty/characterutils@4.0.0) (2022-03-06)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @quenty/characterutils
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
# [3.6.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/characterutils@3.5.1...@quenty/characterutils@3.6.0) (2022-01-17)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @quenty/characterutils
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## [3.5.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/characterutils@3.5.0...@quenty/characterutils@3.5.1) (2022-01-16)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @quenty/characterutils
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
# [3.5.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/characterutils@3.4.0...@quenty/characterutils@3.5.0) (2022-01-07)
|
|
31
|
+
|
|
32
|
+
**Note:** Version bump only for package @quenty/characterutils
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# [3.4.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/characterutils@3.3.1...@quenty/characterutils@3.4.0) (2022-01-03)
|
|
39
|
+
|
|
40
|
+
**Note:** Version bump only for package @quenty/characterutils
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
## [3.3.1](https://github.com/Quenty/NevermoreEngine/compare/@quenty/characterutils@3.3.0...@quenty/characterutils@3.3.1) (2021-12-30)
|
|
47
|
+
|
|
48
|
+
**Note:** Version bump only for package @quenty/characterutils
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
# [3.3.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/characterutils@3.2.0...@quenty/characterutils@3.3.0) (2021-12-18)
|
|
7
55
|
|
|
8
56
|
**Note:** Version bump only for package @quenty/characterutils
|
|
9
57
|
|
package/README.md
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
## CharacterUtils
|
|
2
2
|
<div align="center">
|
|
3
|
-
<a href="http://quenty.github.io/
|
|
4
|
-
<img src="https://
|
|
3
|
+
<a href="http://quenty.github.io/NevermoreEngine/">
|
|
4
|
+
<img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/docs.yml/badge.svg" alt="Documentation status" />
|
|
5
5
|
</a>
|
|
6
6
|
<a href="https://discord.gg/mhtGUS8">
|
|
7
|
-
<img src="https://img.shields.io/
|
|
7
|
+
<img src="https://img.shields.io/discord/385151591524597761?color=5865F2&label=discord&logo=discord&logoColor=white" alt="Discord" />
|
|
8
8
|
</a>
|
|
9
9
|
<a href="https://github.com/Quenty/NevermoreEngine/actions">
|
|
10
10
|
<img src="https://github.com/Quenty/NevermoreEngine/actions/workflows/build.yml/badge.svg" alt="Build and release status" />
|
|
11
11
|
</a>
|
|
12
12
|
</div>
|
|
13
13
|
|
|
14
|
-
Provides utility functions for working with Roblox characters. These make some much-repeated actions much easier to access and operate.
|
|
14
|
+
Provides utility functions for working with Roblox characters. These make some much-repeated actions much easier to access and operate.
|
|
15
|
+
|
|
16
|
+
<div align="center"><a href="https://quenty.github.io/NevermoreEngine/api/CharacterUtils">View docs →</a></div>
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
```
|
|
20
|
+
npm install @quenty/characterutils --save
|
|
21
|
+
```
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/characterutils",
|
|
3
|
-
"version": "4.0.0
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "CharacterUtils",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
"Quenty"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@quenty/deferred": "2.0.
|
|
29
|
-
"@quenty/loader": "
|
|
30
|
-
"@quenty/maid": "2.0
|
|
31
|
-
"@quenty/promise": "4.0.0
|
|
28
|
+
"@quenty/deferred": "^2.0.2",
|
|
29
|
+
"@quenty/loader": "^4.0.0",
|
|
30
|
+
"@quenty/maid": "^2.1.0",
|
|
31
|
+
"@quenty/promise": "^4.0.0"
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "dd428cab58282c975a4c082957dc8f58e3186905"
|
|
37
37
|
}
|
|
@@ -1,42 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
--[=[
|
|
2
|
+
Utility for Roblox character objects that involve promises.
|
|
3
|
+
@class CharacterPromiseUtils
|
|
4
|
+
]=]
|
|
4
5
|
|
|
5
6
|
local require = require(script.Parent.loader).load(script)
|
|
6
7
|
|
|
7
|
-
local Promise = require("Promise")
|
|
8
8
|
local Maid = require("Maid")
|
|
9
|
+
local Promise = require("Promise")
|
|
9
10
|
|
|
10
|
-
local
|
|
11
|
-
|
|
12
|
-
--- Given a humanoid creates a promise that will resolve once the `Humanoid.RootPart` property
|
|
13
|
-
-- resolves properly.
|
|
14
|
-
-- @param humanoid The humanoid to resolve for the root part
|
|
15
|
-
function CharacterPromiseUtil.promiseRootPart(humanoid)
|
|
16
|
-
local promise = Promise.new()
|
|
17
|
-
|
|
18
|
-
if humanoid.RootPart then
|
|
19
|
-
promise:Resolve(humanoid.RootPart)
|
|
20
|
-
return promise
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
-- humanoid:GetPropertyChangedSignal("RootPart") does not fire
|
|
24
|
-
task.spawn(function()
|
|
25
|
-
local rootPart = humanoid.RootPart
|
|
26
|
-
while not rootPart and promise:IsPending() do
|
|
27
|
-
task.wait(0.05)
|
|
28
|
-
rootPart = humanoid.RootPart
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
if rootPart and promise:IsPending() then
|
|
32
|
-
promise:Resolve(rootPart)
|
|
33
|
-
end
|
|
34
|
-
end)
|
|
11
|
+
local CharacterPromiseUtils = {}
|
|
35
12
|
|
|
36
|
-
|
|
37
|
-
|
|
13
|
+
--[=[
|
|
14
|
+
Returns a promise that will resolve once a character exists.
|
|
38
15
|
|
|
39
|
-
|
|
16
|
+
@param player Player
|
|
17
|
+
@return Promise<Model>
|
|
18
|
+
]=]
|
|
19
|
+
function CharacterPromiseUtils.promiseCharacter(player)
|
|
40
20
|
assert(typeof(player) == "Instance", "Bad player")
|
|
41
21
|
|
|
42
22
|
local promise = Promise.new()
|
|
@@ -60,5 +40,5 @@ function CharacterPromiseUtil.promiseCharacter(player)
|
|
|
60
40
|
|
|
61
41
|
end
|
|
62
42
|
|
|
63
|
-
return
|
|
43
|
+
return CharacterPromiseUtils
|
|
64
44
|
|
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
--[=[
|
|
2
|
+
General character utility code.
|
|
3
|
+
@class CharacterUtils
|
|
4
|
+
]=]
|
|
3
5
|
|
|
4
6
|
local Players = game:GetService("Players")
|
|
5
7
|
|
|
6
8
|
local CharacterUtils = {}
|
|
7
9
|
|
|
10
|
+
--[=[
|
|
11
|
+
Gets a player's humanoid, if it exists
|
|
12
|
+
@param player Player
|
|
13
|
+
@return Humanoid? -- Nil if not found
|
|
14
|
+
]=]
|
|
8
15
|
function CharacterUtils.getPlayerHumanoid(player)
|
|
9
16
|
local character = player.Character
|
|
10
17
|
if not character then
|
|
@@ -14,6 +21,11 @@ function CharacterUtils.getPlayerHumanoid(player)
|
|
|
14
21
|
return character:FindFirstChildOfClass("Humanoid")
|
|
15
22
|
end
|
|
16
23
|
|
|
24
|
+
--[=[
|
|
25
|
+
Gets a player's humanoid, and ensures it is alive, otherwise returns nil
|
|
26
|
+
@param player Player
|
|
27
|
+
@return Humanoid? -- Nil if not found
|
|
28
|
+
]=]
|
|
17
29
|
function CharacterUtils.getAlivePlayerHumanoid(player)
|
|
18
30
|
local humanoid = CharacterUtils.getPlayerHumanoid(player)
|
|
19
31
|
if not humanoid or humanoid.Health <= 0 then
|
|
@@ -23,6 +35,12 @@ function CharacterUtils.getAlivePlayerHumanoid(player)
|
|
|
23
35
|
return humanoid
|
|
24
36
|
end
|
|
25
37
|
|
|
38
|
+
--[=[
|
|
39
|
+
Gets a player's humanoid's rootPart, and ensures the humanoid is alive, otherwise
|
|
40
|
+
returns nil
|
|
41
|
+
@param player Player
|
|
42
|
+
@return BasePart? -- Nil if not found
|
|
43
|
+
]=]
|
|
26
44
|
function CharacterUtils.getAlivePlayerRootPart(player)
|
|
27
45
|
local humanoid = CharacterUtils.getPlayerHumanoid(player)
|
|
28
46
|
if not humanoid or humanoid.Health <= 0 then
|
|
@@ -32,6 +50,11 @@ function CharacterUtils.getAlivePlayerRootPart(player)
|
|
|
32
50
|
return humanoid.RootPart
|
|
33
51
|
end
|
|
34
52
|
|
|
53
|
+
--[=[
|
|
54
|
+
Gets a player's humanoid's rootPart otherwise returns nil
|
|
55
|
+
@param player Player
|
|
56
|
+
@return BasePart? -- Nil if not found
|
|
57
|
+
]=]
|
|
35
58
|
function CharacterUtils.getPlayerRootPart(player)
|
|
36
59
|
local humanoid = CharacterUtils.getPlayerHumanoid(player)
|
|
37
60
|
if not humanoid then
|
|
@@ -41,6 +64,20 @@ function CharacterUtils.getPlayerRootPart(player)
|
|
|
41
64
|
return humanoid.RootPart
|
|
42
65
|
end
|
|
43
66
|
|
|
67
|
+
--[=[
|
|
68
|
+
Unequips all tools for a give player's humanomid, if the humanoid
|
|
69
|
+
exists
|
|
70
|
+
|
|
71
|
+
```lua
|
|
72
|
+
local Players = game:GetService("Players")
|
|
73
|
+
|
|
74
|
+
for _, player in pairs(Players:GetPlayers()) do
|
|
75
|
+
CharacterUtils.unequipTools(player)
|
|
76
|
+
end
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
@param player Player
|
|
80
|
+
]=]
|
|
44
81
|
function CharacterUtils.unequipTools(player)
|
|
45
82
|
local humanoid = CharacterUtils.getPlayerHumanoid(player)
|
|
46
83
|
if humanoid then
|
|
@@ -48,10 +85,27 @@ function CharacterUtils.unequipTools(player)
|
|
|
48
85
|
end
|
|
49
86
|
end
|
|
50
87
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
88
|
+
--[=[
|
|
89
|
+
Returns the player that a descendent is part of, if it is part of one.
|
|
90
|
+
|
|
91
|
+
```lua
|
|
92
|
+
script.Parent.Touched:Connect(function(inst)
|
|
93
|
+
local player = CharacterUtils.getPlayerFromCharacter(inst)
|
|
94
|
+
if player then
|
|
95
|
+
-- activate button!
|
|
96
|
+
end
|
|
97
|
+
end)
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
:::tip
|
|
101
|
+
This method is useful in a ton of different situations. For example, you can
|
|
102
|
+
use it on classes bound to a humanoid, to determine the player. You can also
|
|
103
|
+
use it to determine, upon touched events, if a part is part of a character.
|
|
104
|
+
:::
|
|
105
|
+
|
|
106
|
+
@param descendant Instance -- A child of the potential character.
|
|
107
|
+
@return Player? -- Nil if not found
|
|
108
|
+
]=]
|
|
55
109
|
function CharacterUtils.getPlayerFromCharacter(descendant)
|
|
56
110
|
local character = descendant
|
|
57
111
|
local player = Players:GetPlayerFromCharacter(character)
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
--[=[
|
|
2
|
+
Utility functions involving the root part
|
|
3
|
+
@class RootPartUtils
|
|
4
|
+
]=]
|
|
3
5
|
|
|
4
6
|
local require = require(script.Parent.loader).load(script)
|
|
5
7
|
|
|
@@ -10,6 +12,18 @@ local RootPartUtils = {}
|
|
|
10
12
|
|
|
11
13
|
local MAX_YIELD_TIME = 60
|
|
12
14
|
|
|
15
|
+
--[=[
|
|
16
|
+
Given a humanoid creates a promise that will resolve once the `Humanoid.RootPart` property
|
|
17
|
+
resolves properly.
|
|
18
|
+
|
|
19
|
+
:::info
|
|
20
|
+
This works around the fact that `humanoid:GetPropertyChangedSignal("RootPart")` does not fire
|
|
21
|
+
when the rootpart changes on a humanoid.
|
|
22
|
+
:::
|
|
23
|
+
|
|
24
|
+
@param humanoid Humanoid
|
|
25
|
+
@return Promise<BasePart>
|
|
26
|
+
]=]
|
|
13
27
|
function RootPartUtils.promiseRootPart(humanoid)
|
|
14
28
|
if humanoid.RootPart then
|
|
15
29
|
return Promise.resolved(humanoid.RootPart)
|
|
@@ -20,7 +34,7 @@ function RootPartUtils.promiseRootPart(humanoid)
|
|
|
20
34
|
local maid = Maid.new()
|
|
21
35
|
local promise = Promise.new()
|
|
22
36
|
|
|
23
|
-
spawn(function()
|
|
37
|
+
task.spawn(function()
|
|
24
38
|
while not humanoid.RootPart and promise:IsPending() do
|
|
25
39
|
task.wait(0.05)
|
|
26
40
|
end
|
|
@@ -31,7 +45,7 @@ function RootPartUtils.promiseRootPart(humanoid)
|
|
|
31
45
|
end
|
|
32
46
|
end)
|
|
33
47
|
|
|
34
|
-
delay(MAX_YIELD_TIME, function()
|
|
48
|
+
task.delay(MAX_YIELD_TIME, function()
|
|
35
49
|
if promise:IsPending() then
|
|
36
50
|
warn("[RootPartUtils.promiseRootPart] - TImed out on root part", debug.traceback())
|
|
37
51
|
promise:Reject("Timed out")
|