@rbxts/humanoid-stat-manager 1.0.9 → 1.0.11

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.
@@ -0,0 +1,5 @@
1
+ import { Modifier } from './shared';
2
+ export declare namespace HumanoidStatManager {
3
+ function init(): void;
4
+ function addModifier(modifier: Omit<Modifier, 'startTime'>): () => void;
5
+ }
@@ -0,0 +1,81 @@
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 init()
57
+ -- This only exists to suggest/enforce initial requiring of the module.
58
+ end
59
+ _container.init = init
60
+ local function addModifier(modifier)
61
+ local internalModifier = createModifier(modifier)
62
+ table.insert(modifiers, internalModifier)
63
+ return function()
64
+ removeModifier(internalModifier.id)
65
+ end
66
+ end
67
+ _container.addModifier = addModifier
68
+ end
69
+ remote.OnClientEvent:Connect(function(action, ...)
70
+ local args = { ... }
71
+ if action == "Add" then
72
+ local modifier = args[1]
73
+ HumanoidStatManager.addModifier(modifier)
74
+ elseif action == "Remove" then
75
+ local id = args[1]
76
+ removeModifier(id)
77
+ end
78
+ end)
79
+ return {
80
+ HumanoidStatManager = HumanoidStatManager,
81
+ }
package/out/index.d.ts CHANGED
@@ -1,5 +1 @@
1
- import { Modifier } from './shared';
2
- export declare namespace HumanoidStatManager {
3
- function init(): void;
4
- function addModifier(char: Model, modifier: Omit<Modifier, 'id' | 'startTime'>): () => void;
5
- }
1
+ export {};
package/out/init.luau CHANGED
@@ -1,180 +1,2 @@
1
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
- }
2
+ return nil
@@ -0,0 +1,5 @@
1
+ import { Modifier } from './shared';
2
+ export declare namespace HumanoidStatManager {
3
+ function init(): void;
4
+ function addModifier(char: Model, modifier: Omit<Modifier, 'id' | 'startTime'>): () => void;
5
+ }
@@ -0,0 +1,94 @@
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 init()
37
+ -- This only exists to suggest/enforce initial requiring of the module.
38
+ end
39
+ _container.init = init
40
+ local function addModifier(char, modifier)
41
+ local player = Players:GetPlayerFromCharacter(char)
42
+ local id = HttpService:GenerateGUID(false)
43
+ if player then
44
+ local _object = table.clone(modifier)
45
+ setmetatable(_object, nil)
46
+ _object.id = id
47
+ remote:FireClient(player, "Add", _object)
48
+ return function()
49
+ remote:FireClient(player, "Remove", id)
50
+ end
51
+ end
52
+ local _char = char
53
+ local modifiers = npcModifiers[_char]
54
+ if not modifiers then
55
+ modifiers = {}
56
+ local _char_1 = char
57
+ local _modifiers = modifiers
58
+ npcModifiers[_char_1] = _modifiers
59
+ end
60
+ local _object = table.clone(modifier)
61
+ setmetatable(_object, nil)
62
+ _object.id = id
63
+ local internalMod = createModifier(_object)
64
+ table.insert(modifiers, internalMod)
65
+ return function()
66
+ local _char_1 = char
67
+ local currentMods = npcModifiers[_char_1]
68
+ if not currentMods then
69
+ return nil
70
+ end
71
+ -- ▼ ReadonlyArray.findIndex ▼
72
+ local _callback = function(m)
73
+ return m.id == id
74
+ end
75
+ local _result = -1
76
+ for _i, _v in currentMods do
77
+ if _callback(_v, _i - 1, currentMods) == true then
78
+ _result = _i - 1
79
+ break
80
+ end
81
+ end
82
+ -- ▲ ReadonlyArray.findIndex ▲
83
+ local index = _result
84
+ if index == -1 then
85
+ return nil
86
+ end
87
+ table.remove(currentMods, index + 1)
88
+ end
89
+ end
90
+ _container.addModifier = addModifier
91
+ end
92
+ return {
93
+ HumanoidStatManager = HumanoidStatManager,
94
+ }
package/out/shared.luau CHANGED
@@ -1,8 +1,6 @@
1
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 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.9",
3
+ "version": "1.0.11",
4
4
  "description": "",
5
5
  "main": "out/init.lua",
6
6
  "scripts": {
@@ -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
  }