@rbxts/humanoid-stat-manager 1.0.8 → 1.0.9

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/index.d.ts CHANGED
@@ -1 +1,5 @@
1
- export {};
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
+ }
package/out/init.luau CHANGED
@@ -1,2 +1,180 @@
1
1
  -- Compiled with roblox-ts v3.0.0
2
- return nil
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
+ }
package/out/shared.luau CHANGED
@@ -1,6 +1,8 @@
1
1
  -- Compiled with roblox-ts v3.0.0
2
- local HttpService = game:GetService("HttpService")
3
- local StarterPlayer = game:GetService("StarterPlayer")
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
4
6
  --* @internal
5
7
  local BASE_STATS = {
6
8
  WalkSpeed = StarterPlayer.CharacterWalkSpeed,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rbxts/humanoid-stat-manager",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "",
5
5
  "main": "out/init.lua",
6
6
  "scripts": {
@@ -27,6 +27,7 @@
27
27
  "typescript": "^5.9.3"
28
28
  },
29
29
  "dependencies": {
30
- "@rbxts/roblox-observers": "^1.0.8"
30
+ "@rbxts/roblox-observers": "^1.0.8",
31
+ "@rbxts/services": "^1.6.0"
31
32
  }
32
33
  }
package/out/client.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import { Modifier } from './shared';
2
- export declare namespace HumanoidStatManager {
3
- function init(): void;
4
- function addModifier(modifier: Omit<Modifier, 'startTime'>): () => void;
5
- }
package/out/client.luau DELETED
@@ -1,80 +0,0 @@
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
- end
58
- _container.init = init
59
- local function addModifier(modifier)
60
- local internalModifier = createModifier(modifier)
61
- table.insert(modifiers, internalModifier)
62
- return function()
63
- removeModifier(internalModifier.id)
64
- end
65
- end
66
- _container.addModifier = addModifier
67
- end
68
- remote.OnClientEvent:Connect(function(action, ...)
69
- local args = { ... }
70
- if action == "Add" then
71
- local modifier = args[1]
72
- HumanoidStatManager.addModifier(modifier)
73
- elseif action == "Remove" then
74
- local id = args[1]
75
- removeModifier(id)
76
- end
77
- end)
78
- return {
79
- HumanoidStatManager = HumanoidStatManager,
80
- }
package/out/server.d.ts DELETED
@@ -1,5 +0,0 @@
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
- }
package/out/server.luau DELETED
@@ -1,93 +0,0 @@
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
- end
38
- _container.init = init
39
- local function addModifier(char, modifier)
40
- local player = Players:GetPlayerFromCharacter(char)
41
- local id = HttpService:GenerateGUID(false)
42
- if player then
43
- local _object = table.clone(modifier)
44
- setmetatable(_object, nil)
45
- _object.id = id
46
- remote:FireClient(player, "Add", _object)
47
- return function()
48
- remote:FireClient(player, "Remove", id)
49
- end
50
- end
51
- local _char = char
52
- local modifiers = npcModifiers[_char]
53
- if not modifiers then
54
- modifiers = {}
55
- local _char_1 = char
56
- local _modifiers = modifiers
57
- npcModifiers[_char_1] = _modifiers
58
- end
59
- local _object = table.clone(modifier)
60
- setmetatable(_object, nil)
61
- _object.id = id
62
- local internalMod = createModifier(_object)
63
- table.insert(modifiers, internalMod)
64
- return function()
65
- local _char_1 = char
66
- local currentMods = npcModifiers[_char_1]
67
- if not currentMods then
68
- return nil
69
- end
70
- -- ▼ ReadonlyArray.findIndex ▼
71
- local _callback = function(m)
72
- return m.id == id
73
- end
74
- local _result = -1
75
- for _i, _v in currentMods do
76
- if _callback(_v, _i - 1, currentMods) == true then
77
- _result = _i - 1
78
- break
79
- end
80
- end
81
- -- ▲ ReadonlyArray.findIndex ▲
82
- local index = _result
83
- if index == -1 then
84
- return nil
85
- end
86
- table.remove(currentMods, index + 1)
87
- end
88
- end
89
- _container.addModifier = addModifier
90
- end
91
- return {
92
- HumanoidStatManager = HumanoidStatManager,
93
- }