@rbxts/humanoid-stat-manager 1.0.5 → 1.0.6
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/out/client.d.ts +4 -0
- package/out/client.luau +77 -0
- package/out/{index.d.ts → server.d.ts} +0 -1
- package/out/server.luau +90 -0
- package/out/shared.luau +2 -4
- package/package.json +3 -4
- package/out/init.luau +0 -180
package/out/client.d.ts
ADDED
package/out/client.luau
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local observeCharacters = TS.import(script, TS.getModule(script, "@rbxts", "roblox-observers").out["observe-characters"]).observeCharacters
|
|
4
|
+
local _shared = TS.import(script, script.Parent, "shared")
|
|
5
|
+
local calculateStat = _shared.calculateStat
|
|
6
|
+
local pruneExpiredModifiers = _shared.pruneExpiredModifiers
|
|
7
|
+
local createModifier = _shared.createModifier
|
|
8
|
+
local Players = game:GetService("Players")
|
|
9
|
+
local RunService = game:GetService("RunService")
|
|
10
|
+
local localPlayer = Players.LocalPlayer
|
|
11
|
+
local humanoid
|
|
12
|
+
local modifiers = {}
|
|
13
|
+
local REMOTE_NAME = "ServerToClient"
|
|
14
|
+
local remote = script.Parent:WaitForChild(REMOTE_NAME)
|
|
15
|
+
local function removeModifier(id)
|
|
16
|
+
-- ▼ ReadonlyArray.findIndex ▼
|
|
17
|
+
local _callback = function(modifier)
|
|
18
|
+
return modifier.id == id
|
|
19
|
+
end
|
|
20
|
+
local _result = -1
|
|
21
|
+
for _i, _v in modifiers do
|
|
22
|
+
if _callback(_v, _i - 1, modifiers) == true then
|
|
23
|
+
_result = _i - 1
|
|
24
|
+
break
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
-- ▲ ReadonlyArray.findIndex ▲
|
|
28
|
+
local index = _result
|
|
29
|
+
if index == -1 then
|
|
30
|
+
return nil
|
|
31
|
+
end
|
|
32
|
+
table.remove(modifiers, index + 1)
|
|
33
|
+
end
|
|
34
|
+
local function update()
|
|
35
|
+
pruneExpiredModifiers(modifiers)
|
|
36
|
+
if not humanoid then
|
|
37
|
+
return nil
|
|
38
|
+
end
|
|
39
|
+
humanoid.WalkSpeed = calculateStat("WalkSpeed", modifiers)
|
|
40
|
+
humanoid.JumpHeight = calculateStat("JumpHeight", modifiers)
|
|
41
|
+
end
|
|
42
|
+
observeCharacters(function(char, player)
|
|
43
|
+
if player ~= localPlayer then
|
|
44
|
+
return nil
|
|
45
|
+
end
|
|
46
|
+
table.clear(modifiers)
|
|
47
|
+
humanoid = char:WaitForChild("Humanoid")
|
|
48
|
+
return function()
|
|
49
|
+
humanoid = nil
|
|
50
|
+
end
|
|
51
|
+
end)
|
|
52
|
+
RunService.Heartbeat:Connect(update)
|
|
53
|
+
local HumanoidStatManager = {}
|
|
54
|
+
do
|
|
55
|
+
local _container = HumanoidStatManager
|
|
56
|
+
local function addModifier(modifier)
|
|
57
|
+
local internalModifier = createModifier(modifier)
|
|
58
|
+
table.insert(modifiers, internalModifier)
|
|
59
|
+
return function()
|
|
60
|
+
removeModifier(internalModifier.id)
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
_container.addModifier = addModifier
|
|
64
|
+
end
|
|
65
|
+
remote.OnClientEvent:Connect(function(action, ...)
|
|
66
|
+
local args = { ... }
|
|
67
|
+
if action == "Add" then
|
|
68
|
+
local modifier = args[1]
|
|
69
|
+
HumanoidStatManager.addModifier(modifier)
|
|
70
|
+
elseif action == "Remove" then
|
|
71
|
+
local id = args[1]
|
|
72
|
+
removeModifier(id)
|
|
73
|
+
end
|
|
74
|
+
end)
|
|
75
|
+
return {
|
|
76
|
+
HumanoidStatManager = HumanoidStatManager,
|
|
77
|
+
}
|
package/out/server.luau
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
-- Compiled with roblox-ts v3.0.0
|
|
2
|
+
local TS = _G[script]
|
|
3
|
+
local _shared = TS.import(script, script.Parent, "shared")
|
|
4
|
+
local createModifier = _shared.createModifier
|
|
5
|
+
local pruneExpiredModifiers = _shared.pruneExpiredModifiers
|
|
6
|
+
local calculateStat = _shared.calculateStat
|
|
7
|
+
local HttpService = game:GetService("HttpService")
|
|
8
|
+
local Players = game:GetService("Players")
|
|
9
|
+
local RunService = game:GetService("RunService")
|
|
10
|
+
local REMOTE_NAME = "ServerToClient"
|
|
11
|
+
local remote = Instance.new("RemoteEvent")
|
|
12
|
+
remote.Name = REMOTE_NAME
|
|
13
|
+
remote.Parent = script.Parent
|
|
14
|
+
local npcModifiers = {}
|
|
15
|
+
RunService.Heartbeat:Connect(function()
|
|
16
|
+
for char, modifiers in npcModifiers do
|
|
17
|
+
if not char.Parent then
|
|
18
|
+
npcModifiers[char] = nil
|
|
19
|
+
continue
|
|
20
|
+
end
|
|
21
|
+
pruneExpiredModifiers(modifiers)
|
|
22
|
+
if #modifiers == 0 then
|
|
23
|
+
npcModifiers[char] = nil
|
|
24
|
+
end
|
|
25
|
+
local humanoid = char:FindFirstChildOfClass("Humanoid")
|
|
26
|
+
if not humanoid then
|
|
27
|
+
continue
|
|
28
|
+
end
|
|
29
|
+
humanoid.WalkSpeed = calculateStat("WalkSpeed", modifiers)
|
|
30
|
+
humanoid.JumpHeight = calculateStat("JumpHeight", modifiers)
|
|
31
|
+
end
|
|
32
|
+
end)
|
|
33
|
+
local HumanoidStatManager = {}
|
|
34
|
+
do
|
|
35
|
+
local _container = HumanoidStatManager
|
|
36
|
+
local function addModifier(char, modifier)
|
|
37
|
+
local player = Players:GetPlayerFromCharacter(char)
|
|
38
|
+
local id = HttpService:GenerateGUID(false)
|
|
39
|
+
if player then
|
|
40
|
+
local _object = table.clone(modifier)
|
|
41
|
+
setmetatable(_object, nil)
|
|
42
|
+
_object.id = id
|
|
43
|
+
remote:FireClient(player, "Add", _object)
|
|
44
|
+
return function()
|
|
45
|
+
remote:FireClient(player, "Remove", id)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
local _char = char
|
|
49
|
+
local modifiers = npcModifiers[_char]
|
|
50
|
+
if not modifiers then
|
|
51
|
+
modifiers = {}
|
|
52
|
+
local _char_1 = char
|
|
53
|
+
local _modifiers = modifiers
|
|
54
|
+
npcModifiers[_char_1] = _modifiers
|
|
55
|
+
end
|
|
56
|
+
local _object = table.clone(modifier)
|
|
57
|
+
setmetatable(_object, nil)
|
|
58
|
+
_object.id = id
|
|
59
|
+
local internalMod = createModifier(_object)
|
|
60
|
+
table.insert(modifiers, internalMod)
|
|
61
|
+
return function()
|
|
62
|
+
local _char_1 = char
|
|
63
|
+
local currentMods = npcModifiers[_char_1]
|
|
64
|
+
if not currentMods then
|
|
65
|
+
return nil
|
|
66
|
+
end
|
|
67
|
+
-- ▼ ReadonlyArray.findIndex ▼
|
|
68
|
+
local _callback = function(m)
|
|
69
|
+
return m.id == id
|
|
70
|
+
end
|
|
71
|
+
local _result = -1
|
|
72
|
+
for _i, _v in currentMods do
|
|
73
|
+
if _callback(_v, _i - 1, currentMods) == true then
|
|
74
|
+
_result = _i - 1
|
|
75
|
+
break
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
-- ▲ ReadonlyArray.findIndex ▲
|
|
79
|
+
local index = _result
|
|
80
|
+
if index == -1 then
|
|
81
|
+
return nil
|
|
82
|
+
end
|
|
83
|
+
table.remove(currentMods, index + 1)
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
_container.addModifier = addModifier
|
|
87
|
+
end
|
|
88
|
+
return {
|
|
89
|
+
HumanoidStatManager = HumanoidStatManager,
|
|
90
|
+
}
|
package/out/shared.luau
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
-- Compiled with roblox-ts v3.0.0
|
|
2
|
-
local
|
|
3
|
-
local
|
|
4
|
-
local HttpService = _services.HttpService
|
|
5
|
-
local StarterPlayer = _services.StarterPlayer
|
|
2
|
+
local HttpService = game:GetService("HttpService")
|
|
3
|
+
local StarterPlayer = game:GetService("StarterPlayer")
|
|
6
4
|
--* @internal
|
|
7
5
|
local BASE_STATS = {
|
|
8
6
|
WalkSpeed = StarterPlayer.CharacterWalkSpeed,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rbxts/humanoid-stat-manager",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "out/init.lua",
|
|
6
6
|
"scripts": {
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"prepublishOnly": "npm run build"
|
|
10
10
|
},
|
|
11
11
|
"keywords": [],
|
|
12
|
-
"author": "",
|
|
12
|
+
"author": "CriShoux",
|
|
13
13
|
"license": "ISC",
|
|
14
14
|
"type": "commonjs",
|
|
15
15
|
"types": "out/index.d.ts",
|
|
@@ -27,7 +27,6 @@
|
|
|
27
27
|
"typescript": "^5.9.3"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@rbxts/roblox-observers": "^1.0.8"
|
|
31
|
-
"@rbxts/services": "^1.6.0"
|
|
30
|
+
"@rbxts/roblox-observers": "^1.0.8"
|
|
32
31
|
}
|
|
33
32
|
}
|
package/out/init.luau
DELETED
|
@@ -1,180 +0,0 @@
|
|
|
1
|
-
-- Compiled with roblox-ts v3.0.0
|
|
2
|
-
local TS = _G[script]
|
|
3
|
-
local _services = TS.import(script, TS.getModule(script, "@rbxts", "services"))
|
|
4
|
-
local HttpService = _services.HttpService
|
|
5
|
-
local Players = _services.Players
|
|
6
|
-
local RunService = _services.RunService
|
|
7
|
-
local observeCharacters = TS.import(script, TS.getModule(script, "@rbxts", "roblox-observers").out["observe-characters"]).observeCharacters
|
|
8
|
-
local _shared = TS.import(script, script, "shared")
|
|
9
|
-
local createModifier = _shared.createModifier
|
|
10
|
-
local pruneExpiredModifiers = _shared.pruneExpiredModifiers
|
|
11
|
-
local calculateStat = _shared.calculateStat
|
|
12
|
-
local REMOTE_NAME = "ServerToClient"
|
|
13
|
-
local IS_SERVER = RunService:IsServer()
|
|
14
|
-
local serverNpcModifiers = {}
|
|
15
|
-
local clientModifiers = {}
|
|
16
|
-
local clientHumanoid
|
|
17
|
-
local remote
|
|
18
|
-
local initialized = false
|
|
19
|
-
local clientAddInternal, clientRemoveInternal
|
|
20
|
-
local function _init()
|
|
21
|
-
if initialized then
|
|
22
|
-
return nil
|
|
23
|
-
end
|
|
24
|
-
initialized = true
|
|
25
|
-
if IS_SERVER then
|
|
26
|
-
remote = Instance.new("RemoteEvent")
|
|
27
|
-
remote.Name = REMOTE_NAME
|
|
28
|
-
remote.Parent = script
|
|
29
|
-
RunService.Heartbeat:Connect(function()
|
|
30
|
-
for char, modifiers in serverNpcModifiers do
|
|
31
|
-
if not char.Parent then
|
|
32
|
-
serverNpcModifiers[char] = nil
|
|
33
|
-
continue
|
|
34
|
-
end
|
|
35
|
-
pruneExpiredModifiers(modifiers)
|
|
36
|
-
if #modifiers == 0 then
|
|
37
|
-
serverNpcModifiers[char] = nil
|
|
38
|
-
end
|
|
39
|
-
local humanoid = char:FindFirstChildOfClass("Humanoid")
|
|
40
|
-
if humanoid then
|
|
41
|
-
humanoid.WalkSpeed = calculateStat("WalkSpeed", modifiers)
|
|
42
|
-
humanoid.JumpHeight = calculateStat("JumpHeight", modifiers)
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end)
|
|
46
|
-
else
|
|
47
|
-
remote = script:WaitForChild(REMOTE_NAME)
|
|
48
|
-
RunService.Heartbeat:Connect(function()
|
|
49
|
-
pruneExpiredModifiers(clientModifiers)
|
|
50
|
-
if not clientHumanoid then
|
|
51
|
-
return nil
|
|
52
|
-
end
|
|
53
|
-
clientHumanoid.WalkSpeed = calculateStat("WalkSpeed", clientModifiers)
|
|
54
|
-
clientHumanoid.JumpHeight = calculateStat("JumpHeight", clientModifiers)
|
|
55
|
-
end)
|
|
56
|
-
remote.OnClientEvent:Connect(function(action, ...)
|
|
57
|
-
local args = { ... }
|
|
58
|
-
if action == "Add" then
|
|
59
|
-
local modifier = args[1]
|
|
60
|
-
clientAddInternal(modifier)
|
|
61
|
-
elseif action == "Remove" then
|
|
62
|
-
local id = args[1]
|
|
63
|
-
clientRemoveInternal(id)
|
|
64
|
-
end
|
|
65
|
-
end)
|
|
66
|
-
observeCharacters(function(char, player)
|
|
67
|
-
if player ~= Players.LocalPlayer then
|
|
68
|
-
return nil
|
|
69
|
-
end
|
|
70
|
-
table.clear(clientModifiers)
|
|
71
|
-
clientHumanoid = char:WaitForChild("Humanoid")
|
|
72
|
-
return function()
|
|
73
|
-
clientHumanoid = nil
|
|
74
|
-
end
|
|
75
|
-
end)
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
function clientAddInternal(modifier)
|
|
79
|
-
local _modifier = modifier
|
|
80
|
-
table.insert(clientModifiers, _modifier)
|
|
81
|
-
end
|
|
82
|
-
function clientRemoveInternal(id)
|
|
83
|
-
-- ▼ ReadonlyArray.findIndex ▼
|
|
84
|
-
local _callback = function(m)
|
|
85
|
-
return m.id == id
|
|
86
|
-
end
|
|
87
|
-
local _result = -1
|
|
88
|
-
for _i, _v in clientModifiers do
|
|
89
|
-
if _callback(_v, _i - 1, clientModifiers) == true then
|
|
90
|
-
_result = _i - 1
|
|
91
|
-
break
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
-- ▲ ReadonlyArray.findIndex ▲
|
|
95
|
-
local index = _result
|
|
96
|
-
if index ~= -1 then
|
|
97
|
-
table.remove(clientModifiers, index + 1)
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
local addModifierServer, addModifierClient
|
|
101
|
-
local HumanoidStatManager = {}
|
|
102
|
-
do
|
|
103
|
-
local _container = HumanoidStatManager
|
|
104
|
-
local function init()
|
|
105
|
-
_init()
|
|
106
|
-
end
|
|
107
|
-
_container.init = init
|
|
108
|
-
local function addModifier(char, modifier)
|
|
109
|
-
init()
|
|
110
|
-
if IS_SERVER then
|
|
111
|
-
return addModifierServer(char, modifier)
|
|
112
|
-
end
|
|
113
|
-
return addModifierClient(char, modifier)
|
|
114
|
-
end
|
|
115
|
-
_container.addModifier = addModifier
|
|
116
|
-
end
|
|
117
|
-
function addModifierServer(char, modifier)
|
|
118
|
-
local player = Players:GetPlayerFromCharacter(char)
|
|
119
|
-
local id = HttpService:GenerateGUID(false)
|
|
120
|
-
if player then
|
|
121
|
-
local _remote = remote
|
|
122
|
-
local _object = table.clone(modifier)
|
|
123
|
-
setmetatable(_object, nil)
|
|
124
|
-
_object.id = id
|
|
125
|
-
_remote:FireClient(player, "Add", _object)
|
|
126
|
-
return function()
|
|
127
|
-
remote:FireClient(player, "Remove", id)
|
|
128
|
-
end
|
|
129
|
-
else
|
|
130
|
-
local _char = char
|
|
131
|
-
local modifiers = serverNpcModifiers[_char]
|
|
132
|
-
if not modifiers then
|
|
133
|
-
modifiers = {}
|
|
134
|
-
local _char_1 = char
|
|
135
|
-
local _modifiers = modifiers
|
|
136
|
-
serverNpcModifiers[_char_1] = _modifiers
|
|
137
|
-
end
|
|
138
|
-
local _object = table.clone(modifier)
|
|
139
|
-
setmetatable(_object, nil)
|
|
140
|
-
_object.id = id
|
|
141
|
-
local internalMod = createModifier(_object)
|
|
142
|
-
table.insert(modifiers, internalMod)
|
|
143
|
-
return function()
|
|
144
|
-
local _char_1 = char
|
|
145
|
-
local currentMods = serverNpcModifiers[_char_1]
|
|
146
|
-
if not currentMods then
|
|
147
|
-
return nil
|
|
148
|
-
end
|
|
149
|
-
-- ▼ ReadonlyArray.findIndex ▼
|
|
150
|
-
local _callback = function(m)
|
|
151
|
-
return m.id == id
|
|
152
|
-
end
|
|
153
|
-
local _result = -1
|
|
154
|
-
for _i, _v in currentMods do
|
|
155
|
-
if _callback(_v, _i - 1, currentMods) == true then
|
|
156
|
-
_result = _i - 1
|
|
157
|
-
break
|
|
158
|
-
end
|
|
159
|
-
end
|
|
160
|
-
-- ▲ ReadonlyArray.findIndex ▲
|
|
161
|
-
local index = _result
|
|
162
|
-
if index ~= -1 then
|
|
163
|
-
table.remove(currentMods, index + 1)
|
|
164
|
-
end
|
|
165
|
-
end
|
|
166
|
-
end
|
|
167
|
-
end
|
|
168
|
-
function addModifierClient(char, modifier)
|
|
169
|
-
if char ~= Players.LocalPlayer.Character then
|
|
170
|
-
error("HumanoidStatManager: Client can only modify the LocalPlayer\'s character.")
|
|
171
|
-
end
|
|
172
|
-
local internalMod = createModifier(modifier)
|
|
173
|
-
clientAddInternal(internalMod)
|
|
174
|
-
return function()
|
|
175
|
-
clientRemoveInternal(internalMod.id)
|
|
176
|
-
end
|
|
177
|
-
end
|
|
178
|
-
return {
|
|
179
|
-
HumanoidStatManager = HumanoidStatManager,
|
|
180
|
-
}
|