diff --git a/lua/mapvote/client/modules/map_vote.lua b/lua/mapvote/client/modules/map_vote.lua index f7b0c78..34c252e 100644 --- a/lua/mapvote/client/modules/map_vote.lua +++ b/lua/mapvote/client/modules/map_vote.lua @@ -10,10 +10,21 @@ function MapVote.CancelVote() hook.Run( "MapVote_VoteCancelled" ) end +---@param ply Player +---@param mapIndex number +---@param voteMult number function MapVote.ChangeVote( ply, mapIndex, voteMult ) if not IsValid( ply ) then return end if not IsValid( MapVote.Panel ) then return end - MapVote.Panel.voteArea:SetVote( ply, mapIndex, voteMult ) + + ---@type string|Player + local identifier = ply:SteamID64() + if ply:IsBot() then + -- dont use steamid object for bots to allow testing UI locally + identifier = ply + end + + MapVote.Panel.voteArea:SetVote( identifier, mapIndex, voteMult ) end function MapVote.StartVote( maps, endTime ) @@ -115,8 +126,12 @@ hook.Add( "Tick", "MapVote_RequestState", function() end ) gameevent.Listen( "player_disconnect" ) -hook.Add( "player_disconnect", "MapVote_RemoveVote", function() +hook.Add( "player_disconnect", "MapVote_RemoveVote", function( data ) if not IsValid( MapVote.Panel ) then return end - MapVote.Panel.voteArea:RemoveInvalidVotes() + if data.networkid == "BOT" then + MapVote.Panel.voteArea:RemoveInvalidVotes() + else + MapVote.Panel.voteArea:RemoveVote( data.networkid ) + end end ) diff --git a/lua/mapvote/client/vgui/mapvote_panel.lua b/lua/mapvote/client/vgui/mapvote_panel.lua index e69089e..673415e 100644 --- a/lua/mapvote/client/vgui/mapvote_panel.lua +++ b/lua/mapvote/client/vgui/mapvote_panel.lua @@ -54,13 +54,22 @@ end function PANEL:RemoveInvalidVotes() for identifier, vote in pairs( self.votes ) do - if not identifier or not IsValid( identifier ) then + local invalidPlayer = (type( identifier ) == "Player") and not IsValid( identifier ) + if not identifier or invalidPlayer then self:removeVote( vote ) self.votes[identifier] = nil end end end +function PANEL:RemoveVote( identifier ) + local vote = self.votes[identifier] + if not vote then return end + + self:removeVote( vote ) + self.votes[identifier] = nil +end + function PANEL:removeVote( oldVote, removePanel ) if removePanel == nil then removePanel = true @@ -173,7 +182,7 @@ function PANEL:GetPositionRelativeToSelf( mapPanel ) end ---@param identifier string|Player ----@return Player +---@return Player|nil ---@private function PANEL:GetPlayerFromIdentifier( identifier ) if type( identifier ) == "string" then @@ -181,7 +190,7 @@ function PANEL:GetPlayerFromIdentifier( identifier ) elseif type( identifier ) == "Player" then return identifier end - return identifier + return nil end local createdFonts = {}