Skip to content

Commit

Permalink
Ordened List of Spawn Menu;
Browse files Browse the repository at this point in the history
Added Lamp tool;
Added Trail tool;
Added Resizer sound and reset key;
Fixed some UI errors and bugs;
Replaced SpawnParticle by Particle spawn directly;
  • Loading branch information
gtnardy committed Jun 6, 2021
1 parent a6f05e9 commit 2622d50
Show file tree
Hide file tree
Showing 18 changed files with 217 additions and 45 deletions.
17 changes: 10 additions & 7 deletions Client/SpawnMenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ main_hud:Subscribe("Ready", function()
-- Loads all StaticMeshes as Props
local props = Assets:GetStaticMeshes(asset_pack.Path)
for i, prop in pairs(props) do
-- Adds to the list all Props, we use as pattern the images located at a Thumbnails/ folder inside the Asset Pack
SpawnMenuItems[asset_pack.Path].props[prop] = {
table.insert(SpawnMenuItems[asset_pack.Path].props, {
id = prop,
name = prop,
image = "assets///" .. asset_pack.Path .. "/Thumbnails/" .. prop .. ".jpg"
}
})
end

main_hud:CallEvent("AddAssetPack", {asset_pack.Path, JSON.stringify(SpawnMenuItems[asset_pack.Path])})
Expand Down Expand Up @@ -157,10 +157,11 @@ function AddSpawnMenuItem(asset_pack, category, id, name, image)
SpawnMenuItems[asset_pack][category] = {}
end

SpawnMenuItems[asset_pack][category][id] = {
table.insert(SpawnMenuItems[asset_pack][category], {
id = id,
name = name,
image = image
}
})
end

-- Exposes this to other packages
Expand All @@ -169,12 +170,14 @@ Package:Export("AddSpawnMenuItem", AddSpawnMenuItem)
-- Requires all Tools
Package:Require("Tools/Balloon.lua")
Package:Require("Tools/Color.lua")
Package:Require("Tools/Lamp.lua")
Package:Require("Tools/Light.lua")
Package:Require("Tools/PhysicsGun.lua")
Package:Require("Tools/Remover.lua")
Package:Require("Tools/Resizer.lua")
Package:Require("Tools/Rope.lua")
Package:Require("Tools/Thruster.lua")
Package:Require("Tools/Trail.lua")
Package:Require("Tools/Weld.lua")

-- Adds the default NanosWorld items
Expand All @@ -183,12 +186,12 @@ AddSpawnMenuItem("NanosWorld", "weapons", "AK47", "AK47", "assets///NanosWorld/T
AddSpawnMenuItem("NanosWorld", "weapons", "AK74U", "AK74U", "assets///NanosWorld/Thumbnails/SK_AK74U.jpg")
AddSpawnMenuItem("NanosWorld", "weapons", "AP5", "AP5", "assets///NanosWorld/Thumbnails/SK_AP5.jpg")
AddSpawnMenuItem("NanosWorld", "weapons", "AR4", "AR4", "assets///NanosWorld/Thumbnails/SK_AR4.jpg")
AddSpawnMenuItem("NanosWorld", "weapons", "ASVal", "ASVal", "assets///NanosWorld/Thumbnails/SK_ASVal.jpg")
AddSpawnMenuItem("NanosWorld", "weapons", "DesertEagle", "DesertEagle", "assets///NanosWorld/Thumbnails/SK_DesertEagle.jpg")
AddSpawnMenuItem("NanosWorld", "weapons", "GE36", "GE36", "assets///NanosWorld/Thumbnails/SK_GE36.jpg")
AddSpawnMenuItem("NanosWorld", "weapons", "Glock", "Glock", "assets///NanosWorld/Thumbnails/SK_Glock.jpg")
AddSpawnMenuItem("NanosWorld", "weapons", "DesertEagle", "DesertEagle", "assets///NanosWorld/Thumbnails/SK_DesertEagle.jpg")
AddSpawnMenuItem("NanosWorld", "weapons", "Moss500", "Moss500", "assets///NanosWorld/Thumbnails/SK_Moss500.jpg")
AddSpawnMenuItem("NanosWorld", "weapons", "SMG11", "SMG11", "assets///NanosWorld/Thumbnails/SK_SMG11.jpg")
AddSpawnMenuItem("NanosWorld", "weapons", "ASVal", "ASVal", "assets///NanosWorld/Thumbnails/SK_ASVal.jpg")
AddSpawnMenuItem("NanosWorld", "weapons", "Grenade", "Grenade", "assets///NanosWorld/Thumbnails/SK_G67.jpg")

-- Default Vehicles
Expand Down
33 changes: 33 additions & 0 deletions Client/Tools/Lamp.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
-- Method to handle when Player picks up the Tool
function HandleLampTool(weapon)
-- Subscribe when the player fires with this weapon
weapon:Subscribe("Fire", function(weapon, shooter)
-- Makes a trace 10000 units ahead
local trace_result = TraceFor(10000, CollisionChannel.WorldStatic | CollisionChannel.WorldDynamic | CollisionChannel.PhysicsBody | CollisionChannel.Vehicle | CollisionChannel.Pawn)

if (trace_result.Success) then
local distance_trace_object = Vector()
if (trace_result.Entity) 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

-- Calls remote to spawn the Lamp
Events:CallRemote("SpawnLamp", {trace_result.Location, trace_result.Normal, trace_result.Entity, distance_trace_object})
else
-- If didn't hit anything, plays a negative sound
Sound(Vector(), "NanosWorld::A_Invalid_Action", true, true, SoundType.SFX, 1)
end
end)
end

Events:Subscribe("PickUpToolGun_LampTool", function(tool)
HandleLampTool(tool)
end)

Events:Subscribe("DropToolGun_LampTool", function(tool)
tool:Unsubscribe("Fire")
end)

-- Adds this tool to the Sandbox Spawn Menu
AddSpawnMenuItem("NanosWorld", "tools", "LampTool", "Lamps", "assets///NanosWorld/Thumbnails/SK_Blaster.jpg")
13 changes: 11 additions & 2 deletions Client/Tools/Resizer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Client:Subscribe("MouseUp", function(key_name)
if (key_name == "MouseScrollUp") then
if (ResizerTool.resizing_object) then
ResizerTool.current_scale = ResizerTool.current_scale + 0.1
Events:CallRemote("ResizeObject", {ResizerTool.resizing_object, ResizerTool.current_scale})
Events:CallRemote("ResizeObject", {ResizerTool.resizing_object, ResizerTool.current_scale, true})
end
return
end
Expand All @@ -71,12 +71,21 @@ Client:Subscribe("MouseUp", function(key_name)
ResizerTool.current_scale = Vector(0.1)
end

Events:CallRemote("ResizeObject", {ResizerTool.resizing_object, ResizerTool.current_scale})
Events:CallRemote("ResizeObject", {ResizerTool.resizing_object, ResizerTool.current_scale, false})
end
return
end
end)

Client:Subscribe("KeyPress", function(key_name)
if (not ResizerTool.weapon or not ResizerTool.resizing_object) then return end

if (key_name == "R") then
ResizerTool.current_scale = Vector(1, 1, 1)
Events:CallRemote("ResizeObject", {ResizerTool.resizing_object, Vector(1, 1, 1), true})
end
end)

Events:Subscribe("PickUpToolGun_ResizerTool", function(tool, character)
HandleResizerTool(tool, character)
end)
Expand Down
3 changes: 1 addition & 2 deletions Client/Tools/Thruster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ function HandleThrusterTool(weapon)

-- If hit some object, then spawns a thruster on attached it
if (trace_result.Success and trace_result.Entity) then
local distance_trace_object = trace_result.Entity:GetLocation() - trace_result.Location
Events:CallRemote("SpawnThruster", {trace_result.Location, trace_result.Normal, trace_result.Entity, distance_trace_object})
Events:CallRemote("SpawnThruster", {trace_result.Location, trace_result.Normal, trace_result.Entity})
else
-- If didn't hit anything, plays a negative sound
Sound(Vector(), "NanosWorld::A_Invalid_Action", true, true, SoundType.SFX, 1)
Expand Down
27 changes: 27 additions & 0 deletions Client/Tools/Trail.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
-- Method to handle when Player picks up the Tool
function HandleTrailTool(weapon)
-- Subscribe when the player fires with this weapon
weapon:Subscribe("Fire", function(weapon, shooter)
-- Makes a trace 10000 units ahead to spawn the balloon
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
Events:CallRemote("SpawnTrail", {trace_result.Location, trace_result.Normal, trace_result.Entity})
else
-- If didn't hit anything, plays a negative sound
Sound(Vector(), "NanosWorld::A_Invalid_Action", true, true, SoundType.SFX, 1)
end
end)
end

Events:Subscribe("PickUpToolGun_TrailTool", function(tool, character)
HandleTrailTool(tool)
end)

Events:Subscribe("DropToolGun_TrailTool", function(tool, character)
tool:Unsubscribe("Fire")
end)

-- Adds this tool to the Sandbox Spawn Menu
AddSpawnMenuItem("NanosWorld", "tools", "TrailTool", "Trail", "assets///NanosWorld/Thumbnails/SK_Blaster.jpg")
8 changes: 7 additions & 1 deletion Client/UI/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ Events.Subscribe("ToggleVoice", function(name, enable) {

document.querySelector("#voice_chats").prepend(span);
} else {
if (!existing_span)
return;

existing_span.remove();
}
});
Expand Down Expand Up @@ -90,6 +93,9 @@ Events.Subscribe("UpdatePlayer", function(id, active, name, ping) {

document.querySelector("#scoreboard_tbody").prepend(scoreboard_entry_tr);
} else {
if (!existing_scoreboard_entry)
return;

existing_scoreboard_entry.remove();
}
});
Expand Down Expand Up @@ -185,7 +191,7 @@ function RefreshAssets() {
for (let asset_pack in assets) {
for (let asset_pack_item in assets[asset_pack][current_tab]) {
let item = assets[asset_pack][current_tab][asset_pack_item];
DisplayAsset(asset_pack, asset_pack_item, item.name, item.image);
DisplayAsset(asset_pack, item.id, item.name, item.image);
}
}

Expand Down
1 change: 0 additions & 1 deletion Client/UI/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ body {
font-size: 14px;
margin: 0px;
padding: 0px;
margin-bottom: 20px;
color: #ffffffe6;
user-select: none;
}
Expand Down
6 changes: 5 additions & 1 deletion Server/Index.lua
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,11 @@ function SpawnPlayer(player, location, rotation)
-- Sets a callback to automatically respawn the character, 10 seconds after he dies
new_char:Subscribe("Death", function(chara, last_damage_taken, last_bone_damaged, damage_reason, hit_from, instigator)
if (instigator) then
Server:BroadcastChatMessage("<cyan>" .. instigator:GetName() .. "</> killed <cyan>" .. player:GetName() .. "</>")
if (instigator == player) then
Server:BroadcastChatMessage("<cyan>" .. instigator:GetName() .. "</> committed suicide")
else
Server:BroadcastChatMessage("<cyan>" .. instigator:GetName() .. "</> killed <cyan>" .. player:GetName() .. "</>")
end
else
Server:BroadcastChatMessage("<cyan>" .. player:GetName() .. "</> died")
end
Expand Down
30 changes: 17 additions & 13 deletions Server/SpawnMenu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -161,21 +161,23 @@ function DestroyItem(item)

-- If this item has a Particle, destroys it as well
local particle = item:GetValue("Particle")
if (particle) then
particle:Destroy()
end

-- If this item has a Cable, destroys it as well
local cable = item:GetValue("Cable")
if (cable) then
cable:Destroy()
end
if (particle) then particle:Destroy() end

-- If this item has a Light, destroys it as well
local light = item:GetValue("Light")
if (light) then
light:Destroy()
end
if (light) then light:Destroy() end

-- If this item has a Light, destroys it as well
local bulb = item:GetValue("Bulb")
if (bulb) then bulb:Destroy() end

-- If this item has a Thruster attached, destroys it as well
local thruster = item:GetValue("Thruster")
if (thruster) then thruster:Destroy() end

-- If this item has a Trail attached, destroys it as well
local trail = item:GetValue("Trail")
if (trail) then trail:Destroy() end

-- Destroys the item itself
item:Destroy()
Expand All @@ -185,7 +187,7 @@ end
Events:Subscribe("DestroyItem", function(player, item)
-- Spawns some sounds and particles
Events:BroadcastRemote("SpawnSound", {item:GetLocation(), "NanosWorld::A_Player_Eject", false, 0.3, 1})
Events:BroadcastRemote("SpawnParticle", {item:GetLocation() + Vector(0, 0, 30), Rotator(), "NanosWorld::P_OmnidirectionalBurst"})
Particle(item:GetLocation() + Vector(0, 0, 30), Rotator(), "NanosWorld::P_OmnidirectionalBurst")

DestroyItem(item)
end)
Expand Down Expand Up @@ -245,10 +247,12 @@ AddSpawnMenuItem("NanosWorld", "tools", "RemoverTool", function() return SpawnGe
-- Requires all the Tools
Package:Require("Tools/Balloon.lua")
Package:Require("Tools/Color.lua")
Package:Require("Tools/Lamp.lua")
Package:Require("Tools/Light.lua")
Package:Require("Tools/PhysicsGun.lua")
Package:Require("Tools/Resizer.lua")
Package:Require("Tools/Rope.lua")
Package:Require("Tools/Thruster.lua")
Package:Require("Tools/Torch.lua")
Package:Require("Tools/Trail.lua")
Package:Require("Tools/Weld.lua")
6 changes: 2 additions & 4 deletions Server/Tools/Balloon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ Events:Subscribe("SpawnBalloon", function(player, spawn_location, rotation, forc

-- Sets some values to be used later on (such as Balloon color to be used on popping Particles and the Cable itself to be able to destroy it properly)
balloon:SetValue("Color", color, true)
balloon:SetValue("Cable", cable)
balloon:SetValue("Balloon", true)

-- Attaches the Cable to the Balloon
Expand All @@ -57,15 +56,14 @@ Events:Subscribe("SpawnBalloon", function(player, spawn_location, rotation, forc

-- Calls the Client to spawn ballons spawning sounds
Events:BroadcastRemote("SpawnSound", {spawn_location, "NanosWorld::A_Balloon_Inflate", false, 0.75, 1})
Events:BroadcastRemote("SpawnParticle", {spawn_location, rotation, "NanosWorld::P_DirectionalBurst", color})
Particle(spawn_location, rotation, "NanosWorld::P_DirectionalBurst"):SetParameterColor("Color", color)
end)

-- Helper to destroy and pop properly the balloon
function DestroyBalloon(balloon)
Events:BroadcastRemote("SpawnSound", {balloon:GetLocation(), "NanosWorld::A_Balloon_Pop", false, 1, 1})
Events:BroadcastRemote("SpawnParticle", {balloon:GetLocation() + Vector(0, 0, 30), Rotator(), "NanosWorld::P_OmnidirectionalBurst", balloon:GetValue("Color")})
Particle(balloon:GetLocation() + Vector(0, 0, 30), Rotator(), "NanosWorld::P_OmnidirectionalBurst"):SetParameterColor("Color", balloon:GetValue("Color"))

balloon:GetValue("Cable"):Destroy()
balloon:Destroy()
end

Expand Down
3 changes: 2 additions & 1 deletion Server/Tools/Color.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
-- Painting can only affect meshes which materials has the Color Parameter 'Tint'
Events:Subscribe("ColorObject", function(player, entity, hit_location, direction, color)
entity:SetMaterialColorParameter("Tint", color)
Events:BroadcastRemote("SpawnParticle", {hit_location, direction:Rotation(), "NanosWorld::P_DirectionalBurst", color})

Particle(hit_location, direction:Rotation(), "NanosWorld::P_DirectionalBurst"):SetParameterColor("Color", color)
end)

-- Adds this tool to the Sandbox Spawn Menu
Expand Down
46 changes: 46 additions & 0 deletions Server/Tools/Lamp.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
-- Event when Client calls to spawn a Lamp
Events:Subscribe("SpawnLamp", function(player, spawn_location, direction, entity, distance_trace_object)
local rotation = direction:Rotation() + Rotator(-90, 0, 0)

-- Spawns a Lamp Bulb prop
local prop_lamp = Prop(spawn_location, Rotator(), "NanosWorld::SM_TeaPot_Interior")

-- Sets the player to be the network authority immediately of this Prop
prop_lamp:SetNetworkAuthority(player)

-- Sets the prop mesh emissive color to a random color
local color = Color(1, 0.6, 0.4)

local prop_lamp_bulb = Prop(spawn_location, Rotator(), "NanosWorld::SM_Sphere", CollisionType.NoCollision, true, false)
prop_lamp_bulb:AttachTo(prop_lamp)
prop_lamp_bulb:SetScale(Vector(0.175, 0.175, 0.175))
prop_lamp_bulb:SetRelativeLocation(Vector(-1.5, 0, 17.5))
prop_lamp_bulb:SetMaterialColorParameter("Emissive", color * 50)
prop_lamp:SetValue("Bulb", prop_lamp_bulb)

-- Spawns a Point Light, with the color
local intensity = 100
local light = Light(Vector(), Rotator(), color, LightType.Spot, intensity, 1000, 25, 0.975, 2000, false)

-- Attaches the lamp to the prop, offseting 25 downwards
light:AttachTo(prop_lamp)
light:SetRelativeLocation(Vector(0, 0, 30))
light:SetRelativeRotation(Rotator(90, 0, 0))

-- If to attach to an entity, otherwise creates and attaches to a fixed invisible mesh
if (entity) then
prop_lamp:AttachTo(entity, AttachmentRule.KeepWorld)
prop_lamp:SetGrabbable(false)
end

prop_lamp:SetValue("Light", light)
prop_lamp:SetRotation(rotation)

-- Calls the client to add it to his spawn history
Events:CallRemote("SpawnedItem", player, {prop_lamp})

Particle(spawn_location, direction:Rotation(), "NanosWorld::P_DirectionalBurst"):SetParameterColor("Color", color)
end)

-- Adds this tool to the Sandbox Spawn Menu
AddSpawnMenuItem("NanosWorld", "tools", "LampTool", function() return SpawnGenericToolGun(Vector(), Rotator(), Color.YELLOW) end)
Loading

0 comments on commit 2622d50

Please sign in to comment.