lua - 当玩家加入服务器时,每个人都会弹出 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
以上是我在视频形式中遇到的问题。
解决方案
你可以使用这样的东西:
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)
推荐阅读
- excel - 在 VBA 公式中不返回任何内容
- python-3.x - 如何从 LinearSVC 模型中检索训练历史?
- android - 当 View 只是一个 Simple View 使用“new TextView”时,如何改为“View inflate(int resource,ViewGroup root, boolean attachToRoot)”方法?
- oracle - PLSQL 在 For 循环中插入
- scikit-learn - 如果有多个具有相同分数的估计器,GridsearchCV 会选择什么?
- python - 从python数据框生成多对多字典关系列表
- html - 如何使按钮的 url 链接在移动设备和台式电脑上工作
- excel - 用于 Msgbox 的 Excel VBA IF 语句 (range1<>range2+range3) 然后
- django - 在 django 中提交动态创建的输入字段
- javascript - 如何在 JavaScript 中查找数组中某个项目的重复次数?