From cf697d52ef01ca915afc892ad5429a25cf040605 Mon Sep 17 00:00:00 2001 From: "Gabriel T. Nardy" Date: Sat, 2 Apr 2022 16:47:11 -0300 Subject: [PATCH] Fixed Tools calling server on client-side entities; Using new Health/Ammo events; Fixed Gravitating Sound keeping playing; --- Client/Index.lua | 55 +++++++++++++++++++------------------ Client/SpawnMenu.lua | 2 +- Client/Tools/Balloon.lua | 2 +- Client/Tools/Color.lua | 2 +- Client/Tools/PhysicsGun.lua | 4 +-- Client/Tools/Remover.lua | 2 +- Client/Tools/Resizer.lua | 2 +- Client/Tools/Rope.lua | 2 +- Client/Tools/Thruster.lua | 2 +- Client/Tools/Trail.lua | 2 +- Client/Tools/Weld.lua | 2 +- Package.toml | 2 +- Server/Index.lua | 3 +- 13 files changed, 42 insertions(+), 40 deletions(-) diff --git a/Client/Index.lua b/Client/Index.lua index f8341aa..9ac25ef 100644 --- a/Client/Index.lua +++ b/Client/Index.lua @@ -75,22 +75,14 @@ function UpdateLocalCharacter(character) UpdateHealth(character:GetHealth()) -- Sets on character an event to update the health's UI after it takes damage - character:Subscribe("TakeDamage", function(charac, damage, type, bone, from_direction, instigator, causer) - -- Plays a Hit Taken sound effect - Sound(Vector(), "nanos-world::A_HitTaken_Feedback", true) - - -- Updates the Health UI - UpdateHealth(math.max(charac:GetHealth() - damage, 0)) - end) - - -- Sets on character an event to update the health's UI after it dies - character:Subscribe("Death", function(charac) - UpdateHealth(0) - end) + character:Subscribe("HealthChanged", function(charac, old_health, new_health) + -- Plays a Hit Taken sound effect if took damage + if (new_health < old_health) then + Sound(Vector(), "nanos-world::A_HitTaken_Feedback", true) + end - -- Sets on character an event to update the health's UI after it respawns - character:Subscribe("Respawn", function(charac) - UpdateHealth(100) + -- Immediatelly Updates the Health UI + UpdateHealth(new_health) end) -- Try to get if the character is holding any weapon @@ -104,29 +96,28 @@ function UpdateLocalCharacter(character) -- Sets on character an event to update his grabbing weapon (to show ammo on UI) character:Subscribe("PickUp", function(charac, object) if (object:GetType() == "Weapon" and not object:GetValue("ToolGun")) then + -- Immediatelly Updates the Ammo UI UpdateAmmo(true, object:GetAmmoClip(), object:GetAmmoBag()) -- Trigger Weapon Hints AddNotification("AIM_DOWN_SIGHT", "you can use mouse wheel to aim down sight with your Weapon when you are in First Person Mode", 10000, 3000) AddNotification("HEADSHOTS", "headshots can cause more damage", 10000, 15000) - -- Sets on character an event to update the UI when he fires - character:Subscribe("Fire", function(charac, weapon) - UpdateAmmo(true, weapon:GetAmmoClip(), weapon:GetAmmoBag()) - end) - - -- Sets on character an event to update the UI when he reloads the weapon - character:Subscribe("Reload", function(charac, weapon, ammo_to_reload) - UpdateAmmo(true, weapon:GetAmmoClip(), weapon:GetAmmoBag()) - end) + -- Subscribes on the weapon when the Ammo changes + object:Subscribe("AmmoClipChanged", OnAmmoClipChanged) + object:Subscribe("AmmoBagChanged", OnAmmoBagChanged) end end) -- Sets on character an event to remove the ammo ui when he drops it's weapon character:Subscribe("Drop", function(charac, object) - UpdateAmmo(false) - character:Unsubscribe("Fire") - character:Unsubscribe("Reload") + -- Unsubscribes from events + if (object:GetType() == "Weapon") then + UpdateAmmo(false) + object:Unsubscribe("AmmoClipChanged", OnAmmoClipChanged) + object:Unsubscribe("AmmoBagChanged", OnAmmoBagChanged) + end + ToggleToolGunAiming(object, "", false) end) @@ -156,6 +147,16 @@ function UpdateHealth(health) MainHUD:CallEvent("UpdateHealth", health) end +-- Callback when Weapon Ammo Clip changes +function OnAmmoClipChanged(weapon, old_ammo_clip, new_ammo_clip) + UpdateAmmo(true, new_ammo_clip, weapon:GetAmmoBag()) +end + +-- Callback when Weapon Ammo Bag changes +function OnAmmoBagChanged(weapon, old_ammo_bag, new_ammo_bag) + UpdateAmmo(true, weapon:GetAmmoClip(), new_ammo_bag) +end + Input.Bind("NoClip", InputEvent.Pressed, function() Events.CallRemote("ToggleNoClip") end) diff --git a/Client/SpawnMenu.lua b/Client/SpawnMenu.lua index 262b203..f9c3f4b 100644 --- a/Client/SpawnMenu.lua +++ b/Client/SpawnMenu.lua @@ -249,7 +249,7 @@ Client.Subscribe("Tick", function(delta_time) if (not trace_result.Success) then return end - local color = trace_result.Entity and DrawDebugToolGun.ColorEntity or DrawDebugToolGun.ColorNoEntity + local color = trace_result.Entity and trace_result.Entity:IsNetworkDistributed() and DrawDebugToolGun.ColorEntity or DrawDebugToolGun.ColorNoEntity Client.DrawDebugCrosshairs(trace_result.Location, Rotator(), 25, color, 0, 2) end diff --git a/Client/Tools/Balloon.lua b/Client/Tools/Balloon.lua index d9d45e6..40fd897 100644 --- a/Client/Tools/Balloon.lua +++ b/Client/Tools/Balloon.lua @@ -7,7 +7,7 @@ function HandleBalloonTool(weapon) if (trace_result.Success) then local distance_trace_object = Vector() - if (trace_result.Entity) then + if (trace_result.Entity and trace_result.Entity:IsNetworkDistributed()) then -- If hit an entity, then calculates the offset distance from the Hit and the Object distance_trace_object = trace_result.Entity:GetLocation() - trace_result.Location end diff --git a/Client/Tools/Color.lua b/Client/Tools/Color.lua index 627189a..89d5362 100644 --- a/Client/Tools/Color.lua +++ b/Client/Tools/Color.lua @@ -6,7 +6,7 @@ function HandleColorTool(tool) local trace_result = TraceFor(10000, CollisionChannel.WorldStatic | CollisionChannel.WorldDynamic | CollisionChannel.PhysicsBody | CollisionChannel.Vehicle | CollisionChannel.Pawn) -- If hit an object, then get a random Color and call server to update the color for everyone - if (trace_result.Success and trace_result.Entity) then + if (trace_result.Success and trace_result.Entity and trace_result.Entity:IsNetworkDistributed()) then local color = Color.RandomPalette() Events.CallRemote("ColorObject", trace_result.Entity, trace_result.Location, trace_result.Normal, color) else diff --git a/Client/Tools/PhysicsGun.lua b/Client/Tools/PhysicsGun.lua index aa04cb6..fd2d5f0 100644 --- a/Client/Tools/PhysicsGun.lua +++ b/Client/Tools/PhysicsGun.lua @@ -108,7 +108,7 @@ function TryPickUpObject() local trace_result = Client.Trace(start_location, end_location, collision_trace, false, true) -- If hit something and hit an Entity - if (trace_result.Success and trace_result.Entity) then + if (trace_result.Success and trace_result.Entity and trace_result.Entity:IsNetworkDistributed()) then -- Cannot grab Characters (yet?), cannot grab attached entities or entities which are being grabbed if (NanosUtils.IsA(trace_result.Entity, Character) or trace_result.Entity:GetAttachedTo() or trace_result.Entity:GetValue("IsBeingGrabbed")) then return end_location @@ -119,7 +119,7 @@ function TryPickUpObject() -- Spawns a 'graviting' sound attached to the gravited object PhysicsGun.grabbed_sound = Sound(Vector(), "nanos-world::A_VR_Object_Grabbed_Loop", false, false, SoundType.SFX, 0.25) - PhysicsGun.grabbed_sound:AttachTo(PhysicsGun.picking_object) + PhysicsGun.grabbed_sound:AttachTo(PhysicsGun.picking_object, AttachmentRule.SnapToTarget, "", 0) -- Calculates the offset of the hit and the center of the object PhysicsGun.picking_object_relative_location = PhysicsGun.picking_object:GetRotation():RotateVector(PhysicsGun.picking_object:GetLocation() - trace_result.Location) diff --git a/Client/Tools/Remover.lua b/Client/Tools/Remover.lua index af66a9f..6ade4e3 100644 --- a/Client/Tools/Remover.lua +++ b/Client/Tools/Remover.lua @@ -5,7 +5,7 @@ function HandleRemoverTool(weapon) local trace_result = TraceFor(5000, CollisionChannel.WorldStatic | CollisionChannel.WorldDynamic | CollisionChannel.PhysicsBody | CollisionChannel.Vehicle) -- If hit an object, calls the server to destroy it - if (trace_result.Success and trace_result.Entity and not NanosUtils.IsA(trace_result.Entity, Character)) then + if (trace_result.Success and trace_result.Entity and not NanosUtils.IsA(trace_result.Entity, Character) and trace_result.Entity:IsNetworkDistributed()) then Events.CallRemote("DestroyItem", trace_result.Entity) else -- If didn't hit anything, plays a negative sound diff --git a/Client/Tools/Resizer.lua b/Client/Tools/Resizer.lua index e8b4665..fc775a8 100644 --- a/Client/Tools/Resizer.lua +++ b/Client/Tools/Resizer.lua @@ -26,7 +26,7 @@ function ResizerPullUse(weapon, shooter) local trace_result = TraceFor(10000, CollisionChannel.WorldStatic | CollisionChannel.WorldDynamic | CollisionChannel.PhysicsBody | CollisionChannel.Vehicle | CollisionChannel.Pawn) -- If hit an object, then sets this object to be the "resized" one - if (trace_result.Success and trace_result.Entity) then + if (trace_result.Success and trace_result.Entity and trace_result.Entity:IsNetworkDistributed()) then ResizerTool.resizing_object = trace_result.Entity ResizerTool.current_scale = ResizerTool.resizing_object:GetScale() ResizerTool.resizing_object:SetHighlightEnabled(true, 0) diff --git a/Client/Tools/Rope.lua b/Client/Tools/Rope.lua index a5587e5..7b0b558 100644 --- a/Client/Tools/Rope.lua +++ b/Client/Tools/Rope.lua @@ -30,7 +30,7 @@ function HandleRopeTool(tool) return -- If is not yet attached to start - elseif (trace_result.Entity) then + elseif (trace_result.Entity and trace_result.Entity:IsNetworkDistributed()) then RopeTool.attaching_start_to = trace_result.Entity RopeTool.attaching_start_location = trace_result.Location diff --git a/Client/Tools/Thruster.lua b/Client/Tools/Thruster.lua index 9a063c3..cdde7bb 100644 --- a/Client/Tools/Thruster.lua +++ b/Client/Tools/Thruster.lua @@ -6,7 +6,7 @@ function HandleThrusterTool(weapon) local trace_result = TraceFor(10000, CollisionChannel.WorldStatic | CollisionChannel.WorldDynamic | CollisionChannel.PhysicsBody | CollisionChannel.Vehicle) -- If hit some object, then spawns a thruster on attached it - if (trace_result.Success and trace_result.Entity and not NanosUtils.IsA(trace_result.Entity, Character)) then + if (trace_result.Success and trace_result.Entity and not NanosUtils.IsA(trace_result.Entity, Character) and trace_result.Entity:IsNetworkDistributed()) then Events.CallRemote("SpawnThruster", trace_result.Location, trace_result.Normal, trace_result.Entity) else -- If didn't hit anything, plays a negative sound diff --git a/Client/Tools/Trail.lua b/Client/Tools/Trail.lua index f69cba1..ad550e6 100644 --- a/Client/Tools/Trail.lua +++ b/Client/Tools/Trail.lua @@ -6,7 +6,7 @@ function HandleTrailTool(weapon) local trace_result = TraceFor(10000, CollisionChannel.WorldStatic | CollisionChannel.WorldDynamic | CollisionChannel.PhysicsBody | CollisionChannel.Vehicle | CollisionChannel.Pawn) -- If hit some object, then spawns a trail on attached it - if (trace_result.Success and trace_result.Entity) then + if (trace_result.Success and trace_result.Entity and trace_result.Entity:IsNetworkDistributed()) then Events.CallRemote("SpawnTrail", trace_result.Location, trace_result.Normal, trace_result.Entity) else -- If didn't hit anything, plays a negative sound diff --git a/Client/Tools/Weld.lua b/Client/Tools/Weld.lua index 396e9b9..3253dce 100644 --- a/Client/Tools/Weld.lua +++ b/Client/Tools/Weld.lua @@ -34,7 +34,7 @@ function HandleWeldTool(tool) return -- If is not yet attached to start - elseif (trace_result.Entity) then + elseif (trace_result.Entity and trace_result.Entity:IsNetworkDistributed()) then WeldTool.welding_start_to = trace_result.Entity -- Enable Highlighting on index 0 diff --git a/Package.toml b/Package.toml index 9d84c78..f4f61d6 100644 --- a/Package.toml +++ b/Package.toml @@ -5,7 +5,7 @@ # contributors author = "nanos™" # version - version = "2.10.1" + version = "2.10.2" # image URL image = "https://i.imgur.com/aoEa4N4.jpg" # package type: 'script' (normal package), 'game-mode' (unique package - can only load one at a time) or 'loading-screen' (special package loaded in loading screen) diff --git a/Server/Index.lua b/Server/Index.lua index d9053fc..de698fa 100644 --- a/Server/Index.lua +++ b/Server/Index.lua @@ -40,7 +40,8 @@ MALE_DEATH_SOUNDS = { "nanos-world::A_Male_03_Death", "nanos-world::A_Male_04_Death", "nanos-world::A_Male_05_Death", - "nanos-world::A_Male_06_Death" + "nanos-world::A_Male_06_Death", + "nanos-world::A_Wilhelm_Scream" } -- List of Pain Male voices