Hi, I coded this really fast and I may don't see the error but somehow the DFrame is not showing up.
Serverside:
util.AddNetworkString("openRulesOnClient")
util.AddNetworkString("closeRulesOnClient")
-- Groups that can use the command
local allowedGroups = {
["superadmin"] = true
}
local function openRules(ply, text)
text = string.lower(text)
if not string.StartWith(text, "/") then return end
if text == "/openrules" then
if not allowedGroups[ply:GetUserGroup()] then ply:ChatPrint("Insufficient permission ") return end
local input = string.Explode(" ", text)
local target = input[1]
if target == player.GetAll() then
local time = input[2]
net.Start("openRulesOnClient")
net.Send(target)
net.WriteString("ply")
net.WriteString("time")
timer.Create("openRulesTime", time, 1, function ()
net.Start("closeRulesOnClient")
net.Send(target)
end)
end
end
end
hook.Add("PlayerSay", "checkForCommand", openRules)
Clientside:
net.Receive("openRulesOnClient", function ()
local ply = net.ReadString()
local time = net.ReadString()
notification.AddLegacy(ply.." opened the rules on you for "..time.. " seconds!", number Type, number Length)
rulesGUI = vgui.Create("DFrame")
rulesGUI:SetSize(ScrW() - 100, ScrH() - 100)
rulesGUI:Center()
rulesGUI:ShowCloseButton(false)
rulesGUI:SetDraggable(false)
rulesGUI:MakePopup()
rulesGUIHTML = vgui.Create("DHTML", "rulesGUI")
rulesGUIHTML:Dock(FILL)
rulesGUIHTML:OpenURL("https://google.de")
end)
net.Receive("closeRulesOnClient", function ()
rulesGUI:Close()
end)
In your server side code you are checking if a string is equal to a table. This obviously returns false so your net code is never executed. Also, you start your net message and send it before you write anything in the message.
To make your code execute, loop.through player.getall() and check if your target is equal to a players nick. For example,
for k, ply in pairs(player.GetAll()) do
if (target == ply:Nick()) then
-- execute your code on using ply, not target
end
end
Oh, how blind I'am.
You're still using target, which is still a string. String.explode returns a table of strings, so when you set target = pInput[2], target is a string not a player. Calling net.send() with a string is causing that error I believe. If you call it using v it should work because v is a player object
Sorry, you need to Log In to post a reply to this thread.