• What do you need help with? V3
    6,419 replies, posted
Staneh, the wiki says that the function util.JSONToTable expects a JSON encoded string - but you're feeding it a file path. I assume you mean to get the file contents of that path first, then feed that to util.JSONToTable. [URL]http://wiki.garrysmod.com/page/Libraries/util/JSONToTable[/URL] Edit: Actually I see the example using Meta tables does read the file contents. However you should read about the changes made to the file library as it looks like you're not calling it correctly. [url]https://www.google.co.uk/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&ved=0CCIQFjAA&url=https%3A%2F%2Fdocs.google.com%2Fdocument%2Fd%2F1khSuIYrAMkqXu7wlH5YRJNwz6hOH6Xqi5lqBhE3x6gA%2Fedit&ei=zFeoUPr2IOTH0QWO9oDIBw&usg=AFQjCNEIEvpjeyFymucubbufC15DAq3u7Q[/url] Basically, after the file path, there's another argument which defines where the root folder of the file path is.. See wiki page for a better explanation: [url]http://wiki.garrysmod.com/page/Libraries/file/Find[/url] I know it's file.Find but file.Read needs the same new argument.
[QUOTE=Staneh;38495456]Changed it, but didn't change the outcome, still returning nil.[/QUOTE] -The Grinch just stole your present.-
[QUOTE=Staneh;38495194]I'm still trying to make a clientside inventory, this is what I have with saving right now: [lua]function SaveInventory() file.Write(gmod.GetGamemode().Name .."/Inventory/".. string.gsub(LocalPlayer():SteamID(), ":", "_") ..".txt", util.TableToJSON( Inventory )) end function GetInventory() Inventory = util.JSONToTable(gmod.GetGamemode().Name .."/Inventory/".. string.gsub(LocalPlayer():SteamID(), ":", "_") ..".txt") print(Inventory) end[/lua] But, when I run GetInventory(), it returns as nil, not as a table. Any help?[/QUOTE] Try changing that to [lua] hook.Add("Initialize", "create_directories", function() if not file.IsDir(gmod.GetGamemode().Name, "DATA") then file.CreateDir(gmod.GetGamemode().Name) end if not file.IsDir(gmod.GetGamemode().Name .. "/Inventory", "DATA") then file.CreateDir(gmod.GetGamemode().Name .. "/Inventory") end end) function SaveInventory() Inventory = Inventory or {} file.Write(gmod.GetGamemode().Name .."/Inventory/".. string.gsub(LocalPlayer():SteamID(), ":", "_") ..".txt", util.TableToJSON( Inventory )) end function GetInventory() Inventory = util.JSONToTable(file.Read(gmod.GetGamemode().Name .."/Inventory/".. string.gsub(LocalPlayer():SteamID(), ":", "_") ..".txt", "DATA")) or {} PrintTable(Inventory) end [/lua]
[QUOTE=Bioservers;38495548]Staneh, the wiki says that the function util.JSONToTable expects a JSON encoded string - but you're feeding it a file path. I assume you mean to get the file contents of that path first, then feed that to util.JSONToTable. [URL]http://wiki.garrysmod.com/page/Libraries/util/JSONToTable[/URL] Edit: Actually I see the example using Meta tables does read the file contents. However you should read about the changes made to the file library as it looks like you're not calling it correctly. [url]https://www.google.co.uk/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&ved=0CCIQFjAA&url=https%3A%2F%2Fdocs.google.com%2Fdocument%2Fd%2F1khSuIYrAMkqXu7wlH5YRJNwz6hOH6Xqi5lqBhE3x6gA%2Fedit&ei=zFeoUPr2IOTH0QWO9oDIBw&usg=AFQjCNEIEvpjeyFymucubbufC15DAq3u7Q[/url] Basically, after the file path, there's another argument which defines where the root folder of the file path is.. See wiki page for a better explanation: [url]http://wiki.garrysmod.com/page/Libraries/file/Find[/url] I know it's file.Find but file.Read needs the same new argument.[/QUOTE] I tried changing it, and run this: [lua]function SaveInventory() file.Write(gmod.GetGamemode().Name .."/Inventory/".. string.gsub(LocalPlayer():SteamID(), ":", "_") ..".txt", util.TableToJSON( Inventory )) end function GetInventory() local content = "" content = file.Read(gmod.GetGamemode().Name .."/Inventory/".. string.gsub(LocalPlayer():SteamID(), ":", "_") ..".txt") print("READING CONTENT") print(content) //Inventory = util.JSONToTable() end[/lua] But, the content just prints nil, it seems that it's not reading the thing right, but I'm not sure why it's doing that.
You're doing it wrong. Read the posts in between Bioservers and yours.
[QUOTE=Derek_SM;38495663]You're doing it wrong. Read the posts in between Bioservers and yours.[/QUOTE] I`ll fix it now, but it doesn`t really change the outcome, does it?
Testing my script now to ensure it works so you don't have to report back saying it's nil. Folders created successfully, testing out the inventory printing now. [img_thumb] http://puu.sh/1rqcI [/img_thumb] Saved inventory, it made the file. Loaded inventory, didn't print nil. Okay so everything works on my side.
Hmm, alright, I'll test the code out with the metatables tomorrow, I have to sleep now. Thanks for the help.
How would I go about updating this to gm13? [url]http://pastie.org/pastes/5395315/text[/url]
[QUOTE=prang123;38496888]How would I go about updating this to gm13? [url]http://pastie.org/pastes/5395315/text[/url][/QUOTE] By going through all the code and looking for what has changed in the new lua. EDIT: [url]https://docs.google.com/document/d/1khSuIYrAMkqXu7wlH5YRJNwz6hOH6Xqi5lqBhE3x6gA/[/url]
[img]http://puu.sh/1rxI8[/img] [lua]--[[--------------------------------------------------------- Name: gamemode:OnAchievementAchieved() -----------------------------------------------------------]] function GM:OnAchievementAchieved( ply, achid ) chat.AddText( ply, Color( 230, 230, 230 ), " earned the achievement ", Color( 255, 200, 0 ), achievements.GetName( achid ) ); end[/lua] ? [editline]18th November 2012[/editline] Also, base\gamemode\cl_init.lua:509 [lua]--[[--------------------------------------------------------- Name: gamemode:PreDrawOpaqueRenderables() Desc: Called before drawing opaque entities -----------------------------------------------------------]] function GM:PreDrawTranslucentRenderables( bDrawingDepth, bDrawingSkybox ) -- return true end[/lua]
perhaps chat.AddText was called too early?
Is there any way to make the duplicator not copy certain props or entities? Have found a way to allow entities to be copied (duplicator.Allow()) but not the other way around. I'm not really sure what duplicator.Allow() does. I mean if the entity isn't allowed it shouldn't be copied? It obviously copies the entities anyway.
[QUOTE=Cardcapture1;38494822]Is there a way to tell if a player, that was previous given from the PlayerConnect hook as a name and IP, is still trying to connect or has cancelled/crashed?[/QUOTE] The PlayerConnect hook is called when the player_connect source event is fired, so honestly your best bet would be just saving unique information about the player, and then later you can obtain the player handle and just :IsValid() it. If it returns true than, the player made it in. If it returns false, the player is gone. I can't really think of a way to see if the player is still connecting.
I need some help choosing weekends from [lua]os.date("%a")[/lua]. So far i got it to show the date with this. [lua] -- Testing Shit with os.date -- function testing() local date = os.date("%a") print( date ) if date == "Fri" or "Sat" or "Sun" then print("WEEKENDS YEAHHH!") else print("This sucks") end end hook.Add("PlayerSpawn", "Date", testing) [/lua] when the date changes to Monday is still prints as if its a weekend. I know its stupid but id rather ask for help than rage at it.
How would I go about making chat commands with arguments for my concomands? I would like to do !addtokens playername tokens.
[QUOTE=Cardcapture1;38494822]Is there a way to tell if a player, that was previous given from the PlayerConnect hook as a name and IP, is still trying to connect or has cancelled/crashed?[/QUOTE] Quoting myself to see if anyone has an idea.
How do I make players play ACT_GMOD_DEATH?
Hi, I'm trying to make a drop-down list with players in the server to choose to kill. Anyhow, here's the part that's giving me errors: [lua] local dchoice = vgui.Create("DListView", dform) dchoice:SetEditable(false) for _, v in ipairs(player.GetAll()) do dchoice:AddChoice(v:Name()) end [/lua] This is the error I get: [lua] [ERROR] gamemode/cl_killbook.lua:43: attempt to call method 'SetEditable' (a nil value) 1. CreateMenu - gamemode/cl_killbook.lua:43 [/lua]
-snip-
[QUOTE=JeffDOA;38504438]There is no such function as DListView.SetEditable()[/QUOTE] Ahh, that would explain it. Thanks. I'm trying to update it while following the "Why your scripts are now broken" google document. Originally it was this: [lua] local dchoice = vgui.Create("DMultiChoice", dform) dchoice:SetEditable(false) for _, v in ipairs(player.GetAll()) do dchoice:AddChoice(v:Name()) end [/lua] It gives me this error: [lua] [ERROR] gamemode/cl_killbook.lua:43: attempt to index local 'dchoice' (a nil value) [/lua] Anyone know how to fix?
[QUOTE=JohnsonBrown;38504577]Ahh, that would explain it. Thanks. I'm trying to update it while following the "Why your scripts are now broken" google document. Originally it was this: [lua] local dchoice = vgui.Create("DMultiChoice", dform) dchoice:SetEditable(false) for _, v in ipairs(player.GetAll()) do dchoice:AddChoice(v:Name()) end [/lua] It gives me this error: [lua] [ERROR] gamemode/cl_killbook.lua:43: attempt to index local 'dchoice' (a nil value) [/lua] Anyone know how to fix?[/QUOTE] [lua] local dchoice = vgui.Create("DMultiChoice", dform) dchoice:SetSize(100, 50) dchoice:SetPos(50, 50) for _, v in ipairs(player.GetAll()) do dchoice:AddChoice(v:Name()) end [/lua]
[QUOTE=Wolfo;38503784]How do I make players play ACT_GMOD_DEATH?[/QUOTE] I'm interested to know as well. Can anybody shed some light on this?
[QUOTE=JeffDOA;38504629][lua] local dchoice = vgui.Create("DMultiChoice", dform) dchoice:SetSize(100, 50) dchoice:SetPos(50, 50) for _, v in ipairs(player.GetAll()) do dchoice:AddChoice(v:Name()) end [/lua][/QUOTE] I get the same error as mentioned, [lua] [ERROR] gamemode/cl_killbook.lua:43: attempt to index local 'dchoice' (a nil value) [/lua] and also [lua]Warning: vgui.Create failed to create the VGUI component (DMultiChoice)[/lua] I checked back on the google document and it says quote, [QUOTE] DComboBox is swapped with DMultiChoice. When I originally made them they were named the wrong way around. DMultiChoice is now removed. This is because DListView was basically recreating all the functionality of DMultiChoice. DListView has extra settings to remove colums and headers - which make it exactly like the old DComboBox. Complicated eh? [/QUOTE] What would I replace DMultiChoice with?
In lua, how would I chatprint everyone's chat box? As in like, <everyone>:ChatPrint("blehblahbleble")
[QUOTE=JohnsonBrown;38504826]I get the same error as mentioned, [lua] [ERROR] gamemode/cl_killbook.lua:43: attempt to index local 'dchoice' (a nil value) [/lua] and also [lua]Warning: vgui.Create failed to create the VGUI component (DMultiChoice)[/lua] I checked back on the google document and it says quote, What would I replace DMultiChoice with?[/QUOTE] woops use DComboBox [editline]18th November 2012[/editline] [QUOTE=Sethxi;38504899]In lua, how would I chatprint everyone's chat box? As in like, <everyone>:ChatPrint("blehblahbleble")[/QUOTE] [LUA] function PrintEveryChat() for k, v in pairs(player.GetAll() do v:ChatPrint("asdf") end end [/LUA]
[QUOTE=JeffDOA;38504936]woops use DComboBox [editline]18th November 2012[/editline] [LUA] function PrintEveryChat() for k, v in pairs(player.GetAll() do v:ChatPrint("asdf") end end [/LUA][/QUOTE] Would this work for args? As in like, PrintEveryChat( "HEHEHEHE" ) and it prints "HEHEHEHE" in chat? I stopped doing lua for a while and forgot everything :P [LUA] function PrintEveryChat(args) for k, v in pairs(player.GetAll() do v:ChatPrint( args[1] ) end end[/LUA]
[LUA] function PrintEveryChat(args) for k, v in pairs(player.GetAll() do v:ChatPrint( args ) end end[/LUA]
[QUOTE=Drakehawke;38505242][LUA] function PrintEveryChat(args) for k, v in pairs(player.GetAll() do v:ChatPrint( args ) end end[/LUA][/QUOTE] Thanks [editline]19th November 2012[/editline] Apparently sticking this into your darkrp's main.lua file breaks all chat commands. Any possible fix? The concommand doesnt work either, its unknown command. [LUA]function PrintEveryChat(args) for k, v in pairs(player.GetAll() do v:ChatPrint( args[1] ) end end concommand.Add("printchat", PrintEveryChat) AddChatCommand("printchat", PrintEveryChat)[/LUA]
Trying to get a plugin for evolve to work that shows the name on the client who sprayed an image. I'm getting: [code]Hook 'HUDPaint' in plugin 'Sprays' failed with error: addons/evolve/lua/ev_plugins/sh_sprays.lua:19: bad argument #1 to 'pairs' (table expected, got nil) [/code] here is line 18-22 [code] function PLUGIN:HUDPaint() for name, position in pairs( EV_Sprays ) do if position:Distance( LocalPlayer():GetEyeTrace().HitPos ) < 48 then draw.SimpleText( "Sprayed by: " .. name, "Trebuchet24", 10, ScrH() / 2, Color( 255, 0, 0 ), 0, 1 ) break[/code] I'm unsure of how to fix it.
Sorry, you need to Log In to post a reply to this thread.