首页 > 解决方案 > 当玩家加入服务器时,每个人都会弹出 Garry's Mod MOTD

问题描述

在按照教程在 Garry's Mod 中设置基本大厅屏幕后,我遇到了一个错误,每次玩家加入时,大厅屏幕都会在每个人的屏幕上弹出。

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

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("Start Game")

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

以上是我在视频形式中遇到的问题。

标签: luagarrys-mod

解决方案


你可以使用这样的东西:

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("Start Game")

    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)

推荐阅读