Skip to content

Commit

Permalink
Updated deprecated methods, made it work again
Browse files Browse the repository at this point in the history
  • Loading branch information
gtnardy committed Aug 16, 2023
1 parent 1a8528b commit 6e91081
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 40 deletions.
20 changes: 10 additions & 10 deletions Client/Index.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ MainHUD = WebUI("Deathmatch HUD", "file:///UI/index.html")
ScoreboardToggled = false

-- Spawns a Sun at 9:30 AM
World.SpawnDefaultSun()
World.SetTime(9, 30)
World.SetSunSpeed(0)
Sky.Spawn()
Sky.SetTimeOfDay(9, 30)
Sky.SetAnimateTimeOfDay(false)

-- Deathmatch data
Deathmatch = {
Expand Down Expand Up @@ -113,13 +113,13 @@ function UpdateLocalCharacter(character)
local current_picked_item = character:GetPicked()

-- If so, update the UI
if (current_picked_item and current_picked_item:GetType() == "Weapon" and not current_picked_item:GetValue("ToolGun")) then
if (current_picked_item and current_picked_item:IsA(Weapon) and not current_picked_item:GetValue("ToolGun")) then
UpdateAmmo(true, current_picked_item:GetAmmoClip(), current_picked_item:GetAmmoBag())
end

-- 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
if (object:IsA(Weapon) and not object:GetValue("ToolGun")) then
UpdateAmmo(true, object:GetAmmoClip(), object:GetAmmoBag())

-- Sets on character an event to update the UI when he fires
Expand Down Expand Up @@ -163,7 +163,7 @@ Player.Subscribe("Destroy", function(player)
end)

-- Receives from server the current match_state and remaining_time
Events.Subscribe("UpdateMatchState", function(match_state, remaining_time)
Events.SubscribeRemote("UpdateMatchState", function(match_state, remaining_time)
Deathmatch.match_state = match_state
Deathmatch.remaining_time = remaining_time - 1

Expand Down Expand Up @@ -193,24 +193,24 @@ Events.Subscribe("UpdateMatchState", function(match_state, remaining_time)
end)

-- Helpers for spawning sounds
Events.Subscribe("SpawnSound", function(location, sound_asset, is_2D, volume, pitch)
Events.SubscribeRemote("SpawnSound", function(location, sound_asset, is_2D, volume, pitch)
Sound(location, sound_asset, is_2D, true, SoundType.SFX, volume, pitch)
end)

Events.Subscribe("SpawnActionSound", function(location, sound_asset)
Events.SubscribeRemote("SpawnActionSound", function(location, sound_asset)
Sound(location, sound_asset, false, true, SoundType.SFX, 1, 1, 400, 10000, AttenuationFunction.LogReverse)
end)

-- When local Picks Up a Power Up, forces it to update the health and ammo
Events.Subscribe("PickedUpPowerUp", function()
Events.SubscribeRemote("PickedUpPowerUp", function()
Sound(Vector(), "nanos-world::A_VR_Open", true, true, SoundType.SFX, 1, 1)

local character = Client.GetLocalPlayer():GetControlledCharacter()
if (character) then
UpdateHealth(character:GetHealth())

local weapon = character:GetPicked()
if (weapon and NanosUtils.IsA(weapon, Weapon)) then
if (weapon and weapon:IsA(Weapon)) then
UpdateAmmo(true, weapon:GetAmmoClip(), weapon:GetAmmoBag())
end
end
Expand Down
2 changes: 1 addition & 1 deletion Client/UI/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ Events.Subscribe("UpdateMatchStatus", function(label, remaining_time) {
setInterval(function() {
if (current_time > 0) {
current_time--;

const mins = ("00" + Math.floor(current_time / 60)).slice(-2);
const seconds = ("00" + (current_time % 60)).slice(-2);

Expand Down
8 changes: 4 additions & 4 deletions Package.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# contributors
author = "nanos™"
# version
version = "1.5.0"
version = "1.6.0"

# game-mode configurations
[game_mode]
Expand All @@ -16,18 +16,18 @@
# whether to load all level entities on client - only enable it if your package needs to use level static meshes entities
load_level_entities = false
# the game version (major.minor) at the time this package was created, for granting compatibility between breaking changes
compatibility_version = "1.45"
compatibility_version = "1.58"
# packages requirements
packages_requirements = [

"default-weapons",
]
# asset packs requirements
assets_requirements = [
"unreal-tournament-announcer",
]
# compatible maps - maps to be highlighted when starting a new game through main menu
compatible_maps = [

]

# game-mode custom settings configurations
Expand Down
48 changes: 23 additions & 25 deletions Server/Index.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
Package.RequirePackage("nanos-world-weapons")

-- List of the Default Weapons
DefaultWeapons = {
NanosWorldWeapons.AK47,
Expand Down Expand Up @@ -320,7 +318,7 @@ function AddKill(player, location)
if (kill_streak >= 5) then
local label, sound_asset, score = GetKillStreakLabel(kill_streak)

Server.BroadcastChatMessage("<cyan>" .. player:GetName() .. "</> is on a <red>" .. kill_streak .. "</> kill streak!")
Chat.BroadcastMessage("<cyan>" .. player:GetName() .. "</> is on a <red>" .. kill_streak .. "</> kill streak!")

if (label) then
-- Adds a score for kill streak
Expand All @@ -342,7 +340,7 @@ function AddKill(player, location)

local label, sound_asset, score = GetMultiKillLabel(multikill_count)

Server.BroadcastChatMessage("<cyan>" .. player:GetName() .. "</> made a <red>" .. label .. "</>")
Chat.BroadcastMessage("<cyan>" .. player:GetName() .. "</> made a <red>" .. label .. "</>")

-- Adds a score for multi kill
if (DeathmatchSettings.mode == GAME_MODE.DEATHMATCH) then
Expand Down Expand Up @@ -413,7 +411,7 @@ function AddDeath(player, instigator)
AddScore(instigator, 50, "killstreak_ended", "KILLSTREAK ENDED")
end

Server.BroadcastChatMessage("<cyan>" .. instigator:GetName() .. "</> ended <cyan>" .. player:GetName() .. "'s</> <red>" .. kill_streak .. "</> streak!")
Chat.BroadcastMessage("<cyan>" .. instigator:GetName() .. "</> ended <cyan>" .. player:GetName() .. "'s</> <red>" .. kill_streak .. "</> streak!")
end
end

Expand Down Expand Up @@ -522,7 +520,7 @@ function UpdateMatchState(new_state)
Deathmatch.remaining_time = DeathmatchSettings.warmup_time

Console.Log("[Deathmatch] Warm-up!")
Server.BroadcastChatMessage("<grey>Warm-up!</>")
Chat.BroadcastMessage("<grey>Warm-up!</>")

CleanUp()

Expand All @@ -532,13 +530,13 @@ function UpdateMatchState(new_state)
Events.BroadcastRemote("SpawnSound", Vector(), "unreal-tournament-announcer::A_Prepare", true, 1, 1)

Console.Log("[Deathmatch] Preparing!")
Server.BroadcastChatMessage("<grey>Preparing!</>")
Chat.BroadcastMessage("<grey>Preparing!</>")

CleanUp()

-- Freeze all characters
for k, character in pairs(Character.GetAll()) do
character:SetMovementEnabled(false)
character:SetInputEnabled(false)
character:SetFlyingMode(true)
end

Expand All @@ -549,11 +547,11 @@ function UpdateMatchState(new_state)
Events.BroadcastRemote("SpawnSound", Vector(), "unreal-tournament-announcer::A_Proceed", true, 1, 1)

Console.Log("[Deathmatch] Round started!")
Server.BroadcastChatMessage("<grey>Round Started!</>")
Chat.BroadcastMessage("<grey>Round Started!</>")

-- Unfreeze all characters
for k, character in pairs(Character.GetAll()) do
character:SetMovementEnabled(true)
character:SetInputEnabled(true)
character:SetFlyingMode(false)
end

Expand All @@ -562,13 +560,13 @@ function UpdateMatchState(new_state)

-- Freeze all characters
for k, character in pairs(Character.GetAll()) do
character:SetMovementEnabled(false)
character:SetInputEnabled(false)
character:SetFlyingMode(true)
end

-- Match summary
Server.BroadcastChatMessage("<green>End of match!</> Scoreboard:")
Server.BroadcastChatMessage("<grey>=============================</>")
Chat.BroadcastMessage("<green>End of match!</> Scoreboard:")
Chat.BroadcastMessage("<grey>=============================</>")

local player_rank = {}

Expand All @@ -586,13 +584,13 @@ function UpdateMatchState(new_state)
Events.CallRemote("SpawnSound", player, Vector(), "unreal-tournament-announcer::A_LastPlace", true, 1, 1)
end

Server.BroadcastChatMessage(tostring(rank) .. "# <cyan>" .. player:GetName() .. "</>: " .. tostring(player:GetValue("Score") or 0))
Chat.BroadcastMessage(tostring(rank) .. "# <cyan>" .. player:GetName() .. "</>: " .. tostring(player:GetValue("Score") or 0))
end

Server.BroadcastChatMessage("<grey>=============================</>")
Chat.BroadcastMessage("<grey>=============================</>")

Console.Log("[Deathmatch] Post time!")
Server.BroadcastChatMessage("<grey>Post time!</>")
Chat.BroadcastMessage("<grey>Post time!</>")
end

-- Sends to the player the new match state
Expand All @@ -608,15 +606,15 @@ Events.Subscribe("PlayerReady", function(player)

-- If is preparing, freeze him
if (Deathmatch.match_state == MATCH_STATES.PREPARING) then
character:SetMovementEnabled(false)
character:SetInputEnabled(false)
character:SetFlyingMode(true)
end
end

-- Sends him the match state
UpdatePlayerMatchState(player)

Server.BroadcastChatMessage("<cyan>" .. player:GetName() .. "</> has joined the server")
Chat.BroadcastMessage("<cyan>" .. player:GetName() .. "</> has joined the server")
end)

-- When Player leaves the server
Expand All @@ -627,7 +625,7 @@ Player.Subscribe("Destroy", function(player)
character:Destroy()
end

Server.BroadcastChatMessage("<cyan>" .. player:GetName() .. "</> has left the server")
Chat.BroadcastMessage("<cyan>" .. player:GetName() .. "</> has left the server")
end)

-- Helper for cleaning up deathmatch data from player
Expand Down Expand Up @@ -681,7 +679,7 @@ function RespawnPlayer(player)
end

if (Deathmatch.match_state == MATCH_STATES.PREPARING) then
character:SetMovementEnabled(false)
character:SetInputEnabled(false)
end

-- Spawns a new weapon
Expand Down Expand Up @@ -735,7 +733,7 @@ function SpawnWeapon(player)
weapon:SetAmmoBag(weapon:GetAmmoClip() * 3)

if (DeathmatchSettings.weapons_to_use == "default") then
weapon:SetMaterialTextureParameter("PatternTexture", "assets///nanos-world/Textures/Pattern/" .. PatternList[math.random(#PatternList)])
weapon:SetMaterialTextureParameter("PatternTexture", "assets://nanos-world/Textures/Pattern/" .. PatternList[math.random(#PatternList)])
weapon:SetMaterialScalarParameter("PatternBlend", 1)
weapon:SetMaterialScalarParameter("PatternTiling", 2)
weapon:SetMaterialScalarParameter("PatternRoughness", 0.3)
Expand All @@ -751,11 +749,11 @@ function SpawnPowerUp(location)
-- Spawns 2 props for making a cross
local powerup_01 = Prop(new_location, Rotator(), "nanos-world::SM_Cube", CollisionType.NoCollision, false, false)
powerup_01:SetScale(Vector(0.75, 0.25, 0.25))
powerup_01:SetMaterialColorParameter("Emissive", Color.GREEN * 100)
powerup_01:SetMaterialColorParameter("Emissive", Color.GREEN * 10)

local powerup_02 = Prop(new_location, Rotator(), "nanos-world::SM_Cube", CollisionType.NoCollision, false, false)
powerup_02:SetScale(Vector(0.25, 0.25, 0.75))
powerup_02:SetMaterialColorParameter("Emissive", Color.GREEN * 100)
powerup_02:SetMaterialColorParameter("Emissive", Color.GREEN * 10)

-- Spawns a trigger to activate the power up in a character
local trigger = Trigger(new_location, Rotator(), Vector(100), TriggerType.Sphere, false)
Expand All @@ -766,13 +764,13 @@ function SpawnPowerUp(location)

-- If a character overlaps it, he gets the power up
trigger:Subscribe("BeginOverlap", function(self, object)
if (NanosUtils.IsA(object, Character) and object:GetHealth() > 0) then
if (object:IsA(Character) and object:GetHealth() > 0) then
-- Gives Health
object:SetHealth(math.min(object:GetHealth() + 50, 120))

-- Gives Ammo
local weapon = object:GetPicked()
if (weapon and NanosUtils.IsA(weapon, Weapon)) then
if (weapon and weapon:IsA(Weapon)) then
weapon:SetAmmoBag(math.min(weapon:GetAmmoBag() + 50, 100))
end

Expand Down

0 comments on commit 6e91081

Please sign in to comment.