I have a small popup ad in the corner of the screen before each round to help pay for my server. It works pretty well but for the first three seconds of the preround nobody can move because the cursor focus is on the DFrame. Is there anyway the focus can stay on the game, but players can still move around? [CODE]function Advert(ply)
for k,v in pairs(player:GetAll()) do
if ply:IsUserGroup("moderator", "user", "regular") then
local window = vgui.Create( "DFrame" )
window:SetPos(0, 0)
window:SetSize(ScrW() * 0.2, ScrH() * 0.2)
window:SetTitle("Advert")
window:SetDraggable(false)
window:ShowCloseButton(false)
window:SetVisible( true )
window:MakePopup()
local html = vgui.Create("HTML", window)
html:Dock(FILL)
html:OpenURL("http://www.linkbucks.com/eLwr")
timer.Simple( 3, function() window:Close() end)
end
end
end
hook.Add("TTTPrepareRound", "Advert", Advert(LocalPlayer()))[/CODE]
Pretty sure all you need to do is remove [URL="http://wiki.garrysmod.com/page/Panel/MakePopup"][B]window:MakePopup()[/B][/URL].
[QUOTE=phimatt;49614591]I have a small popup ad in the corner of the screen before each round to help pay for my server. It works pretty well but for the first three seconds of the preround nobody can move because the cursor focus is on the DFrame. Is there anyway the focus can stay on the game, but players can still move around? [CODE]function Advert(ply)
for k,v in pairs(player:GetAll()) do
if ply:IsUserGroup("moderator", "user", "regular") then
local window = vgui.Create( "DFrame" )
window:SetPos(0, 0)
window:SetSize(ScrW() * 0.2, ScrH() * 0.2)
window:SetTitle("Advert")
window:SetDraggable(false)
window:ShowCloseButton(false)
window:SetVisible( true )
window:MakePopup()
local html = vgui.Create("HTML", window)
html:Dock(FILL)
html:OpenURL("http://www.linkbucks.com/eLwr")
timer.Simple( 3, function() window:Close() end)
end
end
end
hook.Add("TTTPrepareRound", "Advert", Advert(LocalPlayer()))[/CODE][/QUOTE]
I'm a little confused as to why you are looping through all the players when you are passing in a ply to advertise on anyways? You seem to be creating that box however many times there are players online.
[QUOTE=john55223;49615007]I'm a little confused as to why you are looping through all the players when you are passing in a ply to advertise on anyways? You seem to be creating that box however many times there are players online.[/QUOTE]
I'm a lua novice. What would you recommend the code be changed to?
[QUOTE=phimatt;49615433]I'm a lua novice. What would you recommend the code be changed to?[/QUOTE]
Just remove the loop altogether?
[CODE]
local function Advert(ply)
if ply:IsUserGroup("moderator") or ply:IsUserGroup("user") or ply:IsUserGroup("regular") then
local window = vgui.Create( "DFrame" )
window:SetPos(0, 0)
window:SetSize(ScrW() * 0.2, ScrH() * 0.2)
window:SetTitle("Advert")
window:SetDraggable(false)
window:ShowCloseButton(false)
window:SetVisible( true )
local html = vgui.Create("HTML", window)
html:Dock(FILL)
html:OpenURL("http://www.linkbucks.com/eLwr")
timer.Simple( 3, function() window:Close() end)
end
end
hook.Add("TTTPrepareRound", "Advert", function()
Advert(LocalPlayer())
end)
[/CODE]
[editline]27th January 2016[/editline]
Also, another way to remove focus would just be [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Panel/KillFocus]Panel:KillFocus[/url], but that probably wouldn't be very useful in this case since you created it as a popup
The last part of "hook.Add("TTTPrepareRound", "Advert", Advert(LocalPlayer()))" wouldn't work anyway, since you're running the function when lua gets to that line, due to the "()"
Yeah, replace it with something like this:
[CODE]
hook.Add("TTTPrepareRound", "Advert", function()
Advert(LocalPlayer())
end)
[/CODE]
And it should work
[editline]27th January 2016[/editline]
Also, please make that Advert function local! It could be overwritten by another script or something accidentally if you don't!
[QUOTE=MPan1;49615529]Just remove the loop altogether?
[CODE]
local function Advert(ply)
if ply:IsUserGroup("moderator", "user", "regular") then
local window = vgui.Create( "DFrame" )
window:SetPos(0, 0)
window:SetSize(ScrW() * 0.2, ScrH() * 0.2)
window:SetTitle("Advert")
window:SetDraggable(false)
window:ShowCloseButton(false)
window:SetVisible( true )
local html = vgui.Create("HTML", window)
html:Dock(FILL)
html:OpenURL("http://www.linkbucks.com/eLwr")
timer.Simple( 3, function() window:Close() end)
end
end
hook.Add("TTTPrepareRound", "Advert", function()
Advert(LocalPlayer())
end)
[/CODE]
[editline]27th January 2016[/editline]
Also, another way to remove focus would just be [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Panel/KillFocus]Panel:KillFocus[/url], but that probably wouldn't be very useful in this case since you created it as a popup[/QUOTE]
I tried this and it only works if the 'if' statement is commented out
I'm not familiar with the TTT codebase, so correct me if they've modified this function, but [URL="http://wiki.garrysmod.com/page/Player/IsUserGroup"]PLAYER:IsUserGroup()[/URL] only takes a single argument, not varags.
I.e., ply:IsUserGroup("moderator", "user", "regular") doesn't work because it only checks if the user is a [B]moderator[/B] and disregards the rest of the arguments.
You'd need to check their user group individually for each group. Something like:
[code]if ply:IsUserGroup("moderator") or ply:IsUserGroup("user") or ply:IsUserGroup("regular") then[/code]
[QUOTE=Mista Tea;49620704]I'm not familiar with the TTT codebase, so correct me if they've modified this function, but [URL="http://wiki.garrysmod.com/page/Player/IsUserGroup"]PLAYER:IsUserGroup()[/URL] only takes a single argument, not varags.
I.e., ply:IsUserGroup("moderator", "user", "regular") doesn't work because it only checks if the user is a [B]moderator[/B] and disregards the rest of the arguments.
You'd need to check their user group individually for each group. Something like:
[code]if ply:IsUserGroup("moderator") or ply:IsUserGroup("user") or ply:IsUserGroup("regular") then[/code][/QUOTE]
A faster way to do this would be to create a table: (would also be very easy to add ranks this way)
[CODE]local allowedRanks = {
[ "user" ] = true,
[ "regular ] = true,
[ "moderator" ] = true,
}[/CODE]
Then you would check if they were in the group:
[CODE]if allowedRanks[ ply:GetUserGroup() ] then[/CODE]
Then you would put in the rest of your code.
[QUOTE=Promptitude;49623335]A faster way to do this would be to create a table: (would also be very easy to add ranks this way)[/QUOTE]
u wanna fite m8??
[lua]if ({user=true,moderator=true})[ply:GetUserGroup()] then
-- code
end[/lua]
Sorry, you need to Log In to post a reply to this thread.