I want to loop through a folder of .txt files inside data and read through all of them - How would I do this? I've been playing around and I'm so close but not quite there
[QUOTE=NiandraLades;48413313]I want to loop through a folder of .txt files inside data and read through all of them - How would I do this? I've been playing around and I'm so close but not quite there[/QUOTE]
[URL="http://wiki.garrysmod.com/page/file/Find"]file.Find()[/URL], store files in table. Loop over table and open files using [URL="http://wiki.garrysmod.com/page/file/Open"]file.Open()[/URL] then [URL="http://wiki.garrysmod.com/page/File/Read"]file:Read()[/URL] but I could be wrong.
That's roughly what I tried - like I can print the filename fine but can't get to the JSON stored inside that file
[code]
local our_file = file.Find("folder" .. "/*", "DATA")
for k, v in pairs(our_file) do
print(v)
end
[/code]
[QUOTE=NiandraLades;48413361]That's roughly what I tried - like I can print the filename fine but can't get to the JSON stored inside that file
[code]
local our_file = file.Find("folder" .. "/*", "DATA")
for k, v in pairs(our_file) do
print(v)
end
[/code][/QUOTE]
[code]
local dir = "somedir/"
for _, fn in ipairs(file.Find(dir .. "*", "DATA")) do
local data = file.Read(dir .. fn, "DATA")
print(data)
end
[/code]
How do I disable bullet collision to a player?
anyone know of a hook/game event that runs after autoexec.cfg is executed?
[QUOTE=EvacX;48415537]anyone know of a hook/game event that runs after autoexec.cfg is executed?[/QUOTE]
The Lua state hasn't even been created at that point.
I don't know whether I can post DarkRP related questions here, so if I am not allowed to then I'm sorry and it will be the last time I post some questions related to darkrp.
So here's my question:
I have some custom playermodels on my server. The playermodels are downlaoded correctly.
I've set the model path in my jobs.lua, but everytime I pick the specific job, the model is an error.
Do I have to enable somehing in the config in order to use custom skins?
Why I'm sure that the download is done correctly:
The files exist in my download folder and when I hold C and click on playermodel, I can see the playermodel without an error.
Any ideas?
[editline]9th August 2015[/editline]
Oh and with one of the custom skins, this error occurs sometimes:
[CODE]
[ERROR] addons/fas/lua/weapons/fas2_base/cl_model.lua:621: bad argument #2 to 'GetBonePosition' (number expected, got no value)
1. GetBonePosition - [C]:-1
2. unknown - addons/fas/lua/weapons/fas2_base/cl_model.lua:621[/CODE]
[editline]9th August 2015[/editline]
nevermind, it is fixed. I just needed to restart the game, lol.
[QUOTE=P4sca1;48415659]I don't know whether I can post DarkRP related questions here, so if I am not allowed to then I'm sorry and it will be the last time I post some questions related to darkrp.
So here's my question:
I have some custom playermodels on my server. The playermodels are downlaoded correctly.
I've set the model path in my jobs.lua, but everytime I pick the specific job, the model is an error.
Do I have to enable somehing in the config in order to use custom skins?
Why I'm sure that the download is done correctly:
The files exist in my download folder and when I hold C and click on playermodel, I can see the playermodel without an error.
Any ideas?
[editline]9th August 2015[/editline]
Oh and with one of the custom skins, this error occurs sometimes:
[CODE]
[ERROR] addons/fas/lua/weapons/fas2_base/cl_model.lua:621: bad argument #2 to 'GetBonePosition' (number expected, got no value)
1. GetBonePosition - [C]:-1
2. unknown - addons/fas/lua/weapons/fas2_base/cl_model.lua:621[/CODE]
[editline]9th August 2015[/editline]
nevermind, it is fixed. I just needed to restart the game, lol.[/QUOTE]
The FAS error happens because the playermodel you are using is not installed on your side, or the model is missing the bone that FAS is trying to adjust.
Uh, bit of a weird one - I've got a JSON thingie stored in a txt file on the server, I use util.JSONToTable and send that to the client via net library
Has anyone does this before and noticed sort of weird character/pixelly bugs?
[img]http://i.imgur.com/n6fCmVv.png[/img]
[QUOTE=NiandraLades;48418243]Uh, bit of a weird one - I've got a JSON thingie stored in a txt file on the server, I use util.JSONToTable and send that to the client via net library
Has anyone does this before and noticed sort of weird character/pixelly bugs?
[img]http://i.imgur.com/n6fCmVv.png[/img][/QUOTE]
Pretty sure its nothing related to JSON, but more to the way you display your string.
Possibly - I changed the font to Bebas in size 40 and it looks fine
[lua]function OpenMenu()
gui.EnableScreenClicker( true )
local dmenu = vgui.Create( "DFrame" )
dmenu:SetSize( 500, 500 )
dmenu:Center()
--function dmenu:Paint()
--draw.RoundedBox( 8, 0, 0, w, h, Color( 0, 0, 0, 225 ) )
--end
dmenu.OnClose = function()
gui.EnableScreenClicker( false )
end
local sheet = vgui.Create( "DPropertySheet", dmenu )
sheet:Dock( FILL )
local panel1 = vgui.Create( "DPanel", sheet )
--function panel1:Paint()
--draw.RoundedBox( 8, 0, 0, w, h, Color( 0, 0, 0, 225 ) )
--end
sheet:AddSheet( "Weapons", panel1, "icon16/cross.png" )
end
concommand.Add( "hnt_openmenu", OpenMenu() )[/lua]
in my gamemode's cl_init.lua
Why doesn't this work? What happens is the menu opens at the start of the game(instead of when the concommand is called), and it says the console command doesn't exist when I try to run it. What did I do wrong?
concommand.Add( "hnt_openmenu", OpenMenu() )
This is your problem
What you do here is call the function OpenMenu() as soon as the file loads, instead of passing the function as an argument to concommand.Add.
To fix this, do this:
concommand.Add( "hnt_openmenu", OpenMenu )
Notice the lack of parthesis.
[QUOTE=Robotboy655;48418737]concommand.Add( "hnt_openmenu", OpenMenu() )
This is your problem
What you do here is call the function OpenMenu() as soon as the file loads, instead of passing the function as an argument to concommand.Add.
To fix this, do this:
concommand.Add( "hnt_openmenu", OpenMenu )
Notice the lack of parthesis.[/QUOTE]
Thanks! It works perfectly now :D
ents.FindInBox, when used clientside, does not ever detect LocalPlayer().
Why?
Is there a way to get from an ammo id ( Weapon:GetPrimary/SecondaryAmmoType( ) ) to the actual ammo name without creating a reference table since addon load order can change the results?
game.BuildAmmoTypes sounds promising, but it sorts the ammo types by name instead of order registered ( since I could just subtract 26 and get it that way ).
The only thing that comes to mind that I could do would be overwriting game.AddAmmoType and generating a reference table that will always be correct, but that's really dirty, depends on my addon loading before another that would declare an ammo type, and I'd rather not do that if possible.
[QUOTE=Kogitsune;48419867]Is there a way to get from an ammo id ( Weapon:GetPrimary/SecondaryAmmoType( ) ) to the actual ammo name without creating a reference table since addon load order can change the results?
game.BuildAmmoTypes sounds promising, but it sorts the ammo types by name instead of order registered ( since I could just subtract 26 and get it that way ).
The only thing that comes to mind that I could do would be overwriting game.AddAmmoType and generating a reference table that will always be correct, but that's really dirty, depends on my addon loading before another that would declare an ammo type, and I'd rather not do that if possible.[/QUOTE]
There will be after next update.
[QUOTE=Robotboy655;48420058]There will be after next update.[/QUOTE]
I should start paying more attention to the Next Update thread - thanks!
Does a DCheckBoxLabel have its value set to false(and do they call the onchange method for doing so) when the panel it's parented to is removed?
[QUOTE=Mooda Looda;48420568]Does a DCheckBoxLabel have its value set to false(and do they call the onchange method for doing so) when the panel it's parented to is removed?[/QUOTE]
I don't think it does because there's literally no reason for it to do so.
So, this has been plaguing me forever.
I have a MySQL server with a schema whose default Collation is [B]utf8[/B]. All of my tables and columns are also set to [B]utf8[/B]. I use the [B]MySQLOO [/B]module that was picked up by Kingofbeast a while back.
Anyway, if some text like "[B]( ͡° ͜ʖ ͡°)[/B]" gets stored in the database via Lua, it gets stored as "[B]( ••° ͜ʖ ••°)[/B]".
Displaying that text on a webpage via PHP will print out ( ••° ͜ʖ ••°) instead of ( ͡° ͜ʖ ͡°).
However, if I directly insert ( ͡° ͜ʖ ͡°) into the MySQL database, it gets [B]stored [/B]as ( ͡° ͜ʖ ͡°) and [B]displays [/B]as ( ͡° ͜ʖ ͡°) on a PHP webpage.
I don't know if I am running into problems described in this [URL="http://lua-users.org/wiki/LuaUnicode"]lua-users wiki page about unicode in Lua[/URL] or if I am making a simple mistake. I really don't have a good understanding of character sets.
Has anyone else already dealt with this issue? Is there anything I can do about it?
[QUOTE=Mista Tea;48420706]So, this has been plaguing me forever.
I have a MySQL server with a schema whose default Collation is [B]utf8[/B]. All of my tables and columns are also set to [B]utf8[/B]. I use the [B]MySQLOO [/B]module that was picked up by Kingofbeast a while back.
Anyway, if some text like "[B]( ͡° ͜ʖ ͡°)[/B]" gets stored in the database via Lua, it gets stored as "[B]( ••° ͜ʖ ••°)[/B]".
Displaying that text on a webpage via PHP will print out ( ••° ͜ʖ ••°) instead of ( ͡° ͜ʖ ͡°).
However, if I directly insert ( ͡° ͜ʖ ͡°) into the MySQL database, it gets [B]stored [/B]as ( ͡° ͜ʖ ͡°) and [B]displays [/B]as ( ͡° ͜ʖ ͡°) on a PHP webpage.
I don't know if I am running into problems described in this [URL="http://lua-users.org/wiki/LuaUnicode"]lua-users wiki page about unicode in Lua[/URL] or if I am making a simple mistake. I really don't have a good understanding of character sets.
Has anyone else already dealt with this issue? Is there anything I can do about it?[/QUOTE]
Could be a fault of the module. Do more debugging like manually storing that into the database via Lua and make sure your .lua files are encoded in "UTF-8 without BOM" encoding just in case.
[QUOTE=Robotboy655;48420937]Could be a fault of the module. Do more debugging like manually storing that into the database via Lua and make sure your .lua files are encoded in "UTF-8 without BOM" encoding just in case.[/QUOTE]
Already doing that, unfortunately. Rather at a loss of what to try. I could always give tmysql4 a shot, though I've never used it.
I started work on a language system. But, I'm having a bit of trouble:
[code]
--Because I suck with tables I'll provide an example:
--lua_run local dumb = {} dumb["english"] = { moreinfo = "More Info", } PrintTable( dumb )
--result:
--english:
--moreinfo = More Info
CreateClientConVar( "hnt_preferred_language", "English", true )
languages = {}
lang = {}
lang["English"] = {
moreinfo = "More Info",
weps = "Weapons",
}
--[[lang["german"] = {
moreinfo = "Mehr Informationen",
weps = "Waffen",
}
lang["french"] = {
moreinfo = "Plus d'information"
weps = "armes"
}]]
function languages.AddNew( name, tbl )
lang[name] = tbl
end
function languages.GetTranslated( text )
return lang[GetConVar("hnt_preferred_language"):GetString()].text
end[/code]
Anyone know why languages.GetTranslated() returns nil(with the given arguments of "moreinfo")?
you should be doing [text], not .text
[QUOTE=PortalGod;48421034]you should be doing [text], not .text[/QUOTE]
Oh, thanks
It works perfectly now :D
[QUOTE=Mista Tea;48420706]So, this has been plaguing me forever.
I have a MySQL server with a schema whose default Collation is [B]utf8[/B]. All of my tables and columns are also set to [B]utf8[/B]. I use the [B]MySQLOO [/B]module that was picked up by Kingofbeast a while back.
Anyway, if some text like "[B]( ͡° ͜ʖ ͡°)[/B]" gets stored in the database via Lua, it gets stored as "[B]( ••° ͜ʖ ••°)[/B]".
Displaying that text on a webpage via PHP will print out ( ••° ͜ʖ ••°) instead of ( ͡° ͜ʖ ͡°).
However, if I directly insert ( ͡° ͜ʖ ͡°) into the MySQL database, it gets [B]stored [/B]as ( ͡° ͜ʖ ͡°) and [B]displays [/B]as ( ͡° ͜ʖ ͡°) on a PHP webpage.
I don't know if I am running into problems described in this [URL="http://lua-users.org/wiki/LuaUnicode"]lua-users wiki page about unicode in Lua[/URL] or if I am making a simple mistake. I really don't have a good understanding of character sets.
Has anyone else already dealt with this issue? Is there anything I can do about it?[/QUOTE]
Run "SET NAMES UTF8" query after connection to the database, should help.
[QUOTE=krekeris;48421050]Run "SET NAMES UTF8" query after connection to the database, should help.[/QUOTE]
Holy shit, thank you. :joy:
That was far easier than I was anticipating. Works perfectly.
[code]
include("tr_allowed_entities.lua")
hook.Add( "OnEntityCreated", "tr_SetColCheck", function(ent)
if trunk_entities[ent:GetClass()] then
ent:SetCustomCollisionCheck(true)
ent:SetNWBool("tr_Storable",true)
end
end )
hook.Add( "ShouldCollide", "tr_ColCheck", function(ent1,ent2)
if (ent2:IsVehicle() and ent1:GetNWBool("tr_Storable")) then
ent1:Remove()
end
end )
[/code]
I'm trying to remove entities that touch a car. The thing is, without them even touching they get removed if the car comes near them. How could I fix that? I want it to remove them only when it really colides.
Sorry, you need to Log In to post a reply to this thread.