当玩家加入服务器时,Garry's Mod MOTD弹出所有人的屏幕

在按照Garry's Mod中设置基本等候室屏幕的教程时,我遇到了一个bug,使得每当玩家加入时,等候室屏幕都会弹出在所有人的屏幕上。

我是编程新手,我不确定该尝试什么。

function openLobby()
    local frame = vgui.Create("DFrame")
    frame:SetSize(ScrW(),ScrH())
    frame:Center()
    frame:SetVisible(true)
    frame:ShowCloseButton(false)
    frame:SetDraggable(false)
    frame:SetTitle("")
    frame.Paint = function(s, w, h)

    draw.RoundedBox(0,0,0,w,h,Color(0,0,0,255))

end

frame:MakePopup()

local startBut = vgui.Create("DButton", frame)
startBut:SetSize(200,75)
startBut:SetPos(ScrW()/2 - 100,ScrH()/2 - (75/2))
startBut:SetText("开始游戏")

startBut.DoClick = function()
    net.Start("start_game")
    net.SendToServer()

    frame:Close()
end

end

net.Receive("open_lobby",openLobby)

我期望在加入时弹出“开始游戏”屏幕,并且除非玩家重新加入,否则永远不会再次弹出,但实际上它每次玩家加入时都会弹出。

https://www.youtube.com/watch?v=K9OIcalHbqQ&feature=youtu.be

上面的问题以视频形式存在。

点赞
用户16234509
用户16234509

您可以使用以下代码:

function openLobby()
    local frame = vgui.Create("DFrame")
    frame:SetSize(ScrW(), ScrH())
    frame:Center()
    frame:SetVisible(true)
    frame:ShowCloseButton(false)
    frame:SetDraggable(false)
    frame:SetTitle("")

    frame.Paint = function(s, w, h)
        draw.RoundedBox(0, 0, 0, w, h, Color(0, 0, 0, 255))
    end

    frame:MakePopup()
    local startBut = vgui.Create("DButton", frame)
    startBut:SetSize(200, 75)
    startBut:SetPos(ScrW() / 2 - 100, ScrH() / 2 - (75 / 2))
    startBut:SetText("开始游戏")

    startBut.DoClick = function()
        net.Start("start_game")
        net.SendToServer()
        frame:Close()
    end
end

hook.Add("InitPostEntity", "onJoinStartGameWindow", function()
    timer.Simple(5, function()
        openLobby()
    end)
end)
2021-11-17 21:46:39