I know maybe Blacklists arnt the way to go since ULX and such have Bans.. But i'd prefer to keep some people off of any server I run for other reasons.. But when I started to make it, it was super sloppy and half-assed.. Now i'm trying to make a cleaner one and it wont display properly. Any help would be great :)
[CODE][ERROR] lua/autorun/server/blacklist.lua:105: attempt to index global 'getSteamID' (a function value)
1. v - lua/autorun/server/blacklist.lua:105
2. unknown - lua/includes/modules/hook.lua:84[/CODE]
From this code: (The error from getSteamID is in the hook)
[CODE]local BadSteamID = {
{"STEAMID_HERE", "REASON_HERE"},
}
function getSteamID()
return BadSteamID[1]
end
function getReason()
return BadSteamID[2]
end
hook.Add("CheckPassword", "Blacklist", function(SteamID)
if getSteamID[util.SteamIDFrom64(SteamID)] then return false, getReason end
end)[/CODE]
[QUOTE=Jaaay;52481091]I know maybe Blacklists arnt the way to go since ULX and such have Bans.. But i'd prefer to keep some people off of any server I run for other reasons.. But when I started to make it, it was super sloppy and half-assed.. Now i'm trying to make a cleaner one and it wont display properly. Any help would be great :)
[CODE][ERROR] lua/autorun/server/blacklist.lua:105: attempt to index global 'getSteamID' (a function value)
1. v - lua/autorun/server/blacklist.lua:105
2. unknown - lua/includes/modules/hook.lua:84[/CODE]
From this code: (The error from getSteamID is in the hook)
[CODE]local BadSteamID = {
{"STEAMID_HERE", "REASON_HERE"},
}
function getSteamID()
return BadSteamID[1]
end
function getReason()
return BadSteamID[2]
end
hook.Add("CheckPassword", "Blacklist", function(SteamID)
if getSteamID[util.SteamIDFrom64(SteamID)] then return false, getReason end
end)[/CODE][/QUOTE]
Your code is wrong. The functions will just return the 1st and 2nd table.
Why do you even have functions for that?
[lua]local BadSteamID64 = {
["STEAMID64_HERE"] = "REASON HERE",
}
hook.Add("CheckPassword", "Blacklist", function(SteamID64)
local reason = BadSteamID64[SteamID64]
if reason then return false, reason end
end)[/lua]
[QUOTE=JasonMan34;52481259]Your code is wrong. The functions will just return the 1st and 2nd table.
Why do you even have functions for that?[/QUOTE]
Yeeeaaahh.. I kinda did a stupid idea, and the gamemode I am running had something similar and I may have thought that it would have worked.. Thanks for the help :)
I'm really trying to understand patterns, but I just don't understand how you get from [URL="http://wiki.garrysmod.com/page/Patterns"]this[/URL] to this
[QUOTE=Luni;52446030][lua]local path, name = v:match("^(.-)/?([^/]+)$")[/lua][/QUOTE]
Fixed the link for the guy below me [URL="http://wiki.garrysmod.com/page/render/ComputeDynamicLighting"]ComputeDynamicLighting[/URL]
Does anyone know what is normal in this function?[URL="ComputeLight"]http://wiki.garrysmod.com/page/render/ComputeDynamicLighting[/URL]
And does anyone have examples where this function is used? (It is needed to work with light)
I'm trying to make it so the Combine NPCs are friendly towards people on a certain team. However, ents.FindByClass expects a string instead of a table. Is there a way around this? What I've got so far:
[lua]
CPList = {}
CPList[1] = "npc_combine_camera"
CPList[2] = "npc_turret_ceiling"
CPList[3] = "npc_cscanner"
CPList[4] = "CombineElite"
CPList[5] = "npc_combinegunship"
CPList[6] = "npc_combine_s"
CPList[7] = "npc_hunter"
CPList[8] = "npc_helicopter"
CPList[9] = "npc_manhack"
CPList[10] = "npc_metropolice"
CPList[11] = "CombinePrison"
CPList[12] = "PrisonShotgunner"
CPList[13] = "npc_rollermine"
CPList[14] = "npc_clawscanner"
CPList[15] = "ShotgunSoldier"
CPList[16] = "npc_strider"
CPList[17] = "npc_turret_floor"
timer.Create( "MakeFriendly", 8, 0, function()
for k, ent in pairs( ents.FindByClass( CPList ) ) do
ent:Activate()
for l, ply in pairs( player.GetAll() ) do
if ply:Team() == TEAM_CCA or TEAM_OTA then
ent:AddEntityRelationship( ply, D_FR, 99 )
else
ent:AddEntityRelationship( ply, D_HT, 99 )
end
end
end
end)
[/lua]
The error:
[code]
[ERROR] lua/npc.lua:23: bad argument #1 to 'FindByClass' (string expected, got table)
1. FindByClass - [C]:-1
2. unknown - lua/npc.lua:23
Timer Failed! [MakeFriendly][@lua/npc.lua (line 21)]
[/code]
[QUOTE=Shadow02;52481504]I'm trying to make it so the Combine NPCs are friendly towards people on a certain team. However, ents.FindByClass expects a string instead of a table. Is there a way around this? What I've got so far:
[lua]
CPList = {}
CPList[1] = "npc_combine_camera"
CPList[2] = "npc_turret_ceiling"
CPList[3] = "npc_cscanner"
CPList[4] = "CombineElite"
CPList[5] = "npc_combinegunship"
CPList[6] = "npc_combine_s"
CPList[7] = "npc_hunter"
CPList[8] = "npc_helicopter"
CPList[9] = "npc_manhack"
CPList[10] = "npc_metropolice"
CPList[11] = "CombinePrison"
CPList[12] = "PrisonShotgunner"
CPList[13] = "npc_rollermine"
CPList[14] = "npc_clawscanner"
CPList[15] = "ShotgunSoldier"
CPList[16] = "npc_strider"
CPList[17] = "npc_turret_floor"
timer.Create( "MakeFriendly", 8, 0, function()
for k, ent in pairs( ents.FindByClass( CPList ) ) do
ent:Activate()
for l, ply in pairs( player.GetAll() ) do
if ply:Team() == TEAM_CCA or TEAM_OTA then
ent:AddEntityRelationship( ply, D_FR, 99 )
else
ent:AddEntityRelationship( ply, D_HT, 99 )
end
end
end
end)
[/lua]
The error:
[code]
[ERROR] lua/npc.lua:23: bad argument #1 to 'FindByClass' (string expected, got table)
1. FindByClass - [C]:-1
2. unknown - lua/npc.lua:23
Timer Failed! [MakeFriendly][@lua/npc.lua (line 21)]
[/code][/QUOTE]
There is no default function that accepts a list of classes and returns all entities with those classes. What I suggest you do is get all entities with ents.GetAll and then just use the ones with the classes you want.
[QUOTE=Shadow02;52481504]I'm trying to make it so the Combine NPCs are friendly towards people on a certain team. However, ents.FindByClass expects a string instead of a table. Is there a way around this? What I've got so far:[/QUOTE]
Adding another for loop that cycle CPList would be one way
[lua]
CPList = {}
CPList[1] = "npc_combine_camera"
CPList[2] = "npc_turret_ceiling"
CPList[3] = "npc_cscanner"
CPList[4] = "CombineElite"
CPList[5] = "npc_combinegunship"
CPList[6] = "npc_combine_s"
CPList[7] = "npc_hunter"
CPList[8] = "npc_helicopter"
CPList[9] = "npc_manhack"
CPList[10] = "npc_metropolice"
CPList[11] = "CombinePrison"
CPList[12] = "PrisonShotgunner"
CPList[13] = "npc_rollermine"
CPList[14] = "npc_clawscanner"
CPList[15] = "ShotgunSoldier"
CPList[16] = "npc_strider"
CPList[17] = "npc_turret_floor"
timer.Create( "MakeFriendly", 8, 0, function()
for _, v in ipairs (CPList) do
for k, ent in pairs( ents.FindByClass( v ) ) do
ent:Activate()
for l, ply in pairs( player.GetAll() ) do
if ply:Team() == TEAM_CCA or TEAM_OTA then
ent:AddEntityRelationship( ply, D_FR, 99 )
else
ent:AddEntityRelationship( ply, D_HT, 99 )
end
end
end
end
end)
[/lua]
[QUOTE=ATRanko;52481552]Adding another for loop that cycle CPList would be one way
[lua]
CPList = {}
CPList[1] = "npc_combine_camera"
CPList[2] = "npc_turret_ceiling"
CPList[3] = "npc_cscanner"
CPList[4] = "CombineElite"
CPList[5] = "npc_combinegunship"
CPList[6] = "npc_combine_s"
CPList[7] = "npc_hunter"
CPList[8] = "npc_helicopter"
CPList[9] = "npc_manhack"
CPList[10] = "npc_metropolice"
CPList[11] = "CombinePrison"
CPList[12] = "PrisonShotgunner"
CPList[13] = "npc_rollermine"
CPList[14] = "npc_clawscanner"
CPList[15] = "ShotgunSoldier"
CPList[16] = "npc_strider"
CPList[17] = "npc_turret_floor"
timer.Create( "MakeFriendly", 8, 0, function()
for _, v in ipairs (CPList) do
for k, ent in pairs( ents.FindByClass( v ) ) do
ent:Activate()
for l, ply in pairs( player.GetAll() ) do
if ply:Team() == TEAM_CCA or TEAM_OTA then
ent:AddEntityRelationship( ply, D_FR, 99 )
else
ent:AddEntityRelationship( ply, D_HT, 99 )
end
end
end
end
end)
[/lua][/QUOTE]
FindByClass actually loops through GetAll anyway, so this will cause more lag than just going through GetAll "manually".
[QUOTE=NeatNit;52481566]FindByClass actually loops through GetAll anyway, so this will cause more lag than just going through GetAll "manually".[/QUOTE]
:boxhide:
[LUA]CPList = {}
CPList["npc_combine_camera"] = true
CPList["npc_turret_ceiling"] = true
CPList["npc_cscanner"] = true
CPList["CombineElite"] = true
CPList["npc_combinegunship"] = true
CPList["npc_combine_s"] = true
CPList["npc_hunter"] = true
CPList["npc_helicopter"] = true
CPList["npc_manhack"] = true
CPList["npc_metropolice"] = true
CPList["CombinePrison"] = true
CPList["PrisonShotgunner"] = true
CPList["npc_rollermine"] = true
CPList["npc_rollermine"] = true
CPList["ShotgunSoldier"] = true
CPList["npc_strider"] = true
CPList["npc_turret_floor"] = true
timer.Create( "MakeFriendly", 8, 0, function()
for k,ent in pairs (ents.GetAll()) do
if CPList[ent:GetClass()] then
ent:Activate()
for l, ply in pairs(player.GetAll()) do
if ply:Team() == TEAM_CCA or TEAM_OTA then
ent:AddEntityRelationship( ply, D_FR, 99 )
else
ent:AddEntityRelationship( ply, D_HT, 99 )
end
end
end
end
end)
[/LUA]
Solved: How do I allow the player to still move around (IN_USE, IN_JUMP, IN_FORWARD, etc) while the context menu is open? I want them to be able to use the mouse still, so I don't want to EnableScreenClicker(false), I just want them to be able to avoid being shot while browsing the menu.
[QUOTE=ATRanko;52481584]:boxhide:
[LUA]CPList = {}
CPList["npc_combine_camera"] = true
CPList["npc_turret_ceiling"] = true
CPList["npc_cscanner"] = true
CPList["CombineElite"] = true
CPList["npc_combinegunship"] = true
CPList["npc_combine_s"] = true
CPList["npc_hunter"] = true
CPList["npc_helicopter"] = true
CPList["npc_manhack"] = true
CPList["npc_metropolice"] = true
CPList["CombinePrison"] = true
CPList["PrisonShotgunner"] = true
CPList["npc_rollermine"] = true
CPList["npc_rollermine"] = true
CPList["ShotgunSoldier"] = true
CPList["npc_strider"] = true
CPList["npc_turret_floor"] = true
timer.Create( "MakeFriendly", 8, 0, function()
for k,ent in pairs (ents.GetAll()) do
if CPList[ent:GetClass()] then
ent:Activate()
for l, ply in pairs(player.GetAll()) do
if ply:Team() == TEAM_CCA or TEAM_OTA then
ent:AddEntityRelationship( ply, D_FR, 99 )
else
ent:AddEntityRelationship( ply, D_HT, 99 )
end
end
end
end
end)
[/LUA][/QUOTE]
Thank you very much. Works perfectly.
[QUOTE=ATRanko;52481584]:boxhide:
[LUA]CPList = {}
CPList["npc_combine_camera"] = true
CPList["npc_turret_ceiling"] = true
CPList["npc_cscanner"] = true
CPList["CombineElite"] = true
CPList["npc_combinegunship"] = true
CPList["npc_combine_s"] = true
CPList["npc_hunter"] = true
CPList["npc_helicopter"] = true
CPList["npc_manhack"] = true
CPList["npc_metropolice"] = true
CPList["CombinePrison"] = true
CPList["PrisonShotgunner"] = true
CPList["npc_rollermine"] = true
CPList["npc_rollermine"] = true
CPList["ShotgunSoldier"] = true
CPList["npc_strider"] = true
CPList["npc_turret_floor"] = true
timer.Create( "MakeFriendly", 8, 0, function()
for k,ent in pairs (ents.GetAll()) do
if CPList[ent:GetClass()] then
ent:Activate()
for l, ply in pairs(player.GetAll()) do
if ply:Team() == TEAM_CCA or TEAM_OTA then
ent:AddEntityRelationship( ply, D_FR, 99 )
else
ent:AddEntityRelationship( ply, D_HT, 99 )
end
end
end
end
end)
[/LUA][/QUOTE]
Jesus that code is bad. Couldn't you hook to when the NPC is spawned instead of calling this every 8 seconds for the entire game time?
Sorry to repost but I still haven't found a way to do this, can anyone help?
[QUOTE=Shorthouse06;52480069]Does anyone know the function / piece of code that's used to automatically insert newlines into the toolmenu help text?
[IMG]https://i.imgur.com/4wbmzgM.png[/IMG]
I'm creating a derma panel and need to make a DLabel span multiple lines without knowing what the exact text is (so I can't just manually insert line breaks)[/QUOTE]
[QUOTE=Shorthouse06;52482035]Sorry to repost but I still haven't found a way to do this, can anyone help?[/QUOTE]
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Panel/SetWrap]Panel:SetWrap[/url]
[QUOTE=mib999;52482042][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Panel/SetWrap]Panel:SetWrap[/url][/QUOTE]
Thanks, works perfectly, don't know how I didn't see that before.
Does anyone know what is normal in this function?[URL="http://wiki.garrysmod.com/page/render/ComputeDynamicLighting"]http://wiki.garrysmod.com/page/render/ComputeDynamicLighting[/URL]
And does anyone have examples where this function is used? (It is needed to work with light)
Is there a way to play a UI sound clientside but modify its volume?
[QUOTE=mib999;52482022]Jesus that code is bad. Couldn't you hook to when the NPC is spawned instead of calling this every 8 seconds for the entire game time?[/QUOTE]
I'm going to hook it so it calls this when the NPC is spawned or when a player changes team.
Edit: Can someone tell me what is wrong with this, please?
I'm trying to make a 3D2D button work.
[lua]
if LocalPlayer():GetEyeTrace().Entity then
if LocalPlayer():GetEyeTrace().Entity == self then
localTrace = self:WorldToLocal( LocalPlayer():GetEyeTrace().HitPos )
if ( localTrace.x > -37.5 and localTrace.x < 37.5 + 29 ) and ( localTrace.y > 80 and localTrace.y < 80 + 5 ) then
print("Looked at it")
end
end
end
[/lua]
It does not return any errors but it doesn't work. I'm trying to get it so it triggers when you look at [code] draw.RoundedBox(0,-375,-800,290,50,Color(39, 96, 196)) [/code]
Using the solution found in [url]https://facepunch.com/showthread.php?t=1416766[/url]
-snip
-snip-
[code]
-- If round is active, player is alive, and on a team, award credits.
if round.Status == 1 and (round.time_left % TIMER_PAY == 0) then
for _,ply in pairs(player.GetAll()) do
if ply:Alive() and not ply:IsSpec() then
ply:SetCredits(ply:GetCredits() + PAYMENT_ALIVE)
end
end
end
[/code]
Any more efficient way to handle this? It's only being ran once every TIMER_PAY (which by default is set to 10), but looping through the players with nested ifs seems like it could be come problematic.
[QUOTE=Rory;52483049][code]
-- If round is active, player is alive, and on a team, award credits.
if round.Status == 1 and (round.time_left % TIMER_PAY == 0) then
for _,ply in pairs(player.GetAll()) do
if ply:Alive() and not ply:IsSpec() then
ply:SetCredits(ply:GetCredits() + PAYMENT_ALIVE)
end
end
end
[/code]
Any more efficient way to handle this? It's only being ran once every TIMER_PAY (which by default is set to 10), but looping through the players with nested ifs seems like it could be come problematic.[/QUOTE]
This really isn't anything to worry about. If you really NEED those micro-optimizations you could switch to ipairs and then localize both ipairs and player.GetAll. But you aren't even gaining full nano-seconds if you do that.
[QUOTE=Robotboy655;52480890][url]https://github.com/Facepunch/garrysmod-issues/issues/1820[/url][/QUOTE]
Thanks! I should have known to check the github first :)
Hey is there a way to write on a new line for every time file.Append is used? I'm trying to use it to create a model list but it's been coming out as an unspaced mess so far.
How does lua scope work when including? I'm sure I read somewhere that include("file") is that same as copy and pasting that code into the main file but that doesn't seem to be the case.
Local functions in the main file can't be called from the included file.
My code layout is essentially this
Main file
[CODE]local function myFunction()
print("Hello world")
end
include("otherfile.lua")[/CODE]
otherfile.lua
[CODE]myFunction()[/CODE]
When run gives
[CODE]attempt to call global 'myFunction' (a nil value)[/CODE]
Is there any way to run local functions from inside an included script or do I have to make them global?
[QUOTE=Shorthouse06;52483775]:snip:[/QUOTE]
include doesn't work like that in Lua, it's a separate environment. You can either define the function as a global, put it into a global table, or return it in the file, e.g.
myfile.lua
[code]
local function doStuff() print "hi" end
return doStuff
[/code]
otherfile.lua
[code]
local funcFromOtherFile = include "myfile.lua"
funcFromOtherFile() -- hi
[/code]
Is there a way to draw a HUD element once instead of per frame?
I've written a HUD with static elements, such as rounded boxes, and a very detailed HUD Clock (time left function). The problem is, there's about fifty lines of static code that never changes, so I don't need to have the client wasting CPU on drawing all fifty lines of this crap every frame.
[QUOTE=Rory;52484297]Is there a way to draw a HUD element once instead of per frame?
I've written a HUD with static elements, such as rounded boxes, and a very detailed HUD Clock (time left function). The problem is, there's about fifty lines of static code that never changes, so I don't need to have the client wasting CPU on drawing all fifty lines of this crap every frame.[/QUOTE]
The only way is to use a PNG really
Is there anyway to open the options dialog in-game? Something similar to [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/RunGameUICommand]RunGameUICommand[/url]("OpenOptionsDialog") maybe?
Sorry, you need to Log In to post a reply to this thread.