Skip to content

Commit

Permalink
Fixed client remaining time;
Browse files Browse the repository at this point in the history
Set default weapons to Default;
Auto destroys weapon when die;
  • Loading branch information
gtnardy committed Jun 16, 2021
1 parent 33d2cfb commit 080dc19
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
4 changes: 2 additions & 2 deletions Client/Index.lua
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ end)
-- Receives from server the current match_state and remaining_time
Events:Subscribe("UpdateMatchState", function(match_state, remaining_time)
Deathmatch.match_state = match_state
Deathmatch.remaining_time = remaining_time - 3
Deathmatch.remaining_time = remaining_time - 1

local label = ""

Expand All @@ -185,7 +185,7 @@ Events:Subscribe("UpdateMatchState", function(match_state, remaining_time)
end

-- Calls UI to display the current match status and current remaining_time
MainHUD:CallEvent("UpdateMatchStatus", { label, remaining_time })
MainHUD:CallEvent("UpdateMatchStatus", { label, Deathmatch.remaining_time })
end)

-- Helpers for spawning sounds
Expand Down
33 changes: 21 additions & 12 deletions Server/Index.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ DeathmatchSettings = {
match_time = 300,
post_time = 15,
multikill_time = 4,
multikill_time_multiplier = 0.5,
multikill_time_multiplier = 1,
spawn_locations = {
Vector(-100, -100, 100)
},
weapons_to_use = "Quaternius" -- "Default"
weapons_to_use = "Default" -- "Default"
}

-- Deathmatch Data
Expand Down Expand Up @@ -265,6 +265,13 @@ Character:Subscribe("Death", function(character, last_damage_taken, last_bone_da
-- Adds a death to count
AddDeath(dead_player, instigator)

-- Immediately destroys the wepaon
local weapon = dead_player:GetValue("Weapon")

if (weapon and weapon:IsValid()) then
weapon:Destroy()
end

-- Respawns after 5 seconds
Timer:SetTimeout(5000, function(_player)
if (Deathmatch.match_state ~= MATCH_STATES.POST_TIME) then
Expand Down Expand Up @@ -427,9 +434,9 @@ function RespawnPlayer(player)
if (character) then

-- If has a weapon, destroys it
local weapon = character:GetValue("Weapon")
local weapon = player:GetValue("Weapon")

if (weapon) then
if (weapon and weapon:IsValid()) then
weapon:Destroy()
end

Expand All @@ -447,7 +454,7 @@ function RespawnPlayer(player)
local weapon = SpawnWeapon()
weapon:SetAmmoBag(weapon:GetAmmoClip() * 3)

character:SetValue("Weapon", weapon)
player:SetValue("Weapon", weapon)
character:PickUp(weapon)

-- Sets the character invulnerable for 3 seconds
Expand All @@ -468,17 +475,19 @@ end

-- Helper for spawning weapons
function SpawnWeapon()
if (DeathmatchSettings.weapons_to_use == "Default") then
local weapon_func = DefaultWeapons[math.random(#DefaultWeapons)]
return weapon_func()
end

-- Custom spawn for Quaternius weapons
if (DeathmatchSettings.weapons_to_use == "Quaternius") then
local weapon_name = QuaterniusWeapons[math.random(#QuaterniusWeapons)]
local weapon = Package:Call("QuaterniusTools", weapon_name, {})
return weapon
local weapon = Package:Call("QuaterniusTools", weapon_name, {}, false)

if (weapon) then
return weapon
end
end

-- If custom weapons didn't work or the default weapon is NanosWorldDefault weapons, spawns it
local weapon_func = DefaultWeapons[math.random(#DefaultWeapons)]
return weapon_func()
end

-- Helper for spawning a Power Up
Expand Down

0 comments on commit 080dc19

Please sign in to comment.