@rbxts/humanoid-stat-manager 1.0.0 → 1.0.1

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,4 +1,5 @@
1
1
  import { Modifier } from './shared';
2
+ export declare function init(): void;
2
3
  export declare namespace HumanoidStatManager {
3
4
  function addModifier(char: Model, modifier: Omit<Modifier, 'id' | 'startTime'>): () => void;
4
5
  }
package/out/init.luau CHANGED
@@ -15,58 +15,65 @@ local serverNpcModifiers = {}
15
15
  local clientModifiers = {}
16
16
  local clientHumanoid
17
17
  local remote
18
+ local initialized = false
18
19
  local clientAddInternal, clientRemoveInternal
19
- if IS_SERVER then
20
- remote = Instance.new("RemoteEvent")
21
- remote.Name = REMOTE_NAME
22
- remote.Parent = script
23
- RunService.Heartbeat:Connect(function()
24
- for char, modifiers in serverNpcModifiers do
25
- if not char.Parent then
26
- serverNpcModifiers[char] = nil
27
- continue
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
28
44
  end
29
- pruneExpiredModifiers(modifiers)
30
- if #modifiers == 0 then
31
- serverNpcModifiers[char] = nil
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
32
52
  end
33
- local humanoid = char:FindFirstChildOfClass("Humanoid")
34
- if humanoid then
35
- humanoid.WalkSpeed = calculateStat("WalkSpeed", modifiers)
36
- humanoid.JumpHeight = calculateStat("JumpHeight", modifiers)
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)
37
64
  end
38
- end
39
- end)
40
- else
41
- remote = script:WaitForChild(REMOTE_NAME)
42
- RunService.Heartbeat:Connect(function()
43
- pruneExpiredModifiers(clientModifiers)
44
- if not clientHumanoid then
45
- return nil
46
- end
47
- clientHumanoid.WalkSpeed = calculateStat("WalkSpeed", clientModifiers)
48
- clientHumanoid.JumpHeight = calculateStat("JumpHeight", clientModifiers)
49
- end)
50
- remote.OnClientEvent:Connect(function(action, ...)
51
- local args = { ... }
52
- if action == "Add" then
53
- local modifier = args[1]
54
- clientAddInternal(modifier)
55
- elseif action == "Remove" then
56
- local id = args[1]
57
- clientRemoveInternal(id)
58
- end
59
- end)
60
- observeCharacters(function(char, player)
61
- if player ~= Players.LocalPlayer then
62
- return nil
63
- end
64
- table.clear(clientModifiers)
65
- clientHumanoid = char:WaitForChild("Humanoid")
66
- return function()
67
- clientHumanoid = nil
68
- end
69
- 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
70
77
  end
71
78
  function clientAddInternal(modifier)
72
79
  local _modifier = modifier
@@ -95,6 +102,7 @@ local HumanoidStatManager = {}
95
102
  do
96
103
  local _container = HumanoidStatManager
97
104
  local function addModifier(char, modifier)
105
+ init()
98
106
  if IS_SERVER then
99
107
  return addModifierServer(char, modifier)
100
108
  end
@@ -164,5 +172,6 @@ function addModifierClient(char, modifier)
164
172
  end
165
173
  end
166
174
  return {
175
+ init = init,
167
176
  HumanoidStatManager = HumanoidStatManager,
168
177
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rbxts/humanoid-stat-manager",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "",
5
5
  "main": "out/init.lua",
6
6
  "scripts": {
@@ -1,5 +0,0 @@
1
- {
2
- "properties": {
3
- "RunContext": "Client"
4
- }
5
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,10 +0,0 @@
1
- -- Compiled with roblox-ts v3.0.0
2
- local _module = script.Parent
3
- if _module ~= nil then
4
- _module = _module.Parent
5
- end
6
- local module = _module
7
- local _arg0 = module and module:IsA("ModuleScript")
8
- local _arg1 = `Module not found`
9
- assert(_arg0, _arg1)
10
- require(module)
@@ -1,5 +0,0 @@
1
- {
2
- "properties": {
3
- "RunContext": "Server"
4
- }
5
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,10 +0,0 @@
1
- -- Compiled with roblox-ts v3.0.0
2
- local _module = script.Parent
3
- if _module ~= nil then
4
- _module = _module.Parent
5
- end
6
- local module = _module
7
- local _arg0 = module and module:IsA("ModuleScript")
8
- local _arg1 = `Module not found`
9
- assert(_arg0, _arg1)
10
- require(module)