• Shared File
    8 replies, posted
Alright, so I have an addon that plays audio emotes when certain words are said in chat. Everything there works fine. Now, I want to make a command (!emotes) that displays a GUI interface which has a list of all of the emotes. Here's what I have: function EmoteUI()     local EmoteList = net.ReadTable()     local emoteui = vgui.Create("DFrame")     emoteui:SetSize(500, 500)     emoteui:Center()     local EmoteListUI = vgui.Create( "DListView", emoteui )     EmoteListUI:Dock(FILL)     EmoteListUI:SetMultiSelect(false)     EmoteListUI:AddColumn("Say this")     EmoteListUI:AddColumn("Play this")          for k,v in pairs(EmoteList) do         EmoteListUI:AddLine( k, v )     end end As you can see, this is supposed to take the values from ChatSounds (an array) and put it in the VGUI element and display it to the player. The only problem I have here is I can't figure out how to make the client and server work together. The "ChatSounds" array is on the serverside file. How can I send the "ChatSounds" array to the "EmoteUI" function (on the clientside)? I've tried using the Net library but the array is too big to send.
I think, the best way for you here is to create that array on both, server and client (or maybe you can think about making it all client-side, if it won't harm it's functionality)
The only thing I forgot to mention is that both the server and clientside files need to read the array. Here's how the array is created in my server file ChatSounds = {} function AddChatSound(word,sound)     ChatSounds[word] = sound end AddChatSound("hello","vo/npc/male01/hi01.wav")
If you are sure that you want it to run on both server and client, as I said, the best way is to make that file shared. Second way is to network that table to player, but I find it stupid to network something that simple, especially if its not dynamic.
Excellent, I'll look into shared files. Thank you! One more question; How would I go about executing the EmoteUI function (in the original post) on the client that called the command in the shared file? Is there somewhere I can read up on shared files?
Shared file is just executed on both client and server, it's data is not shared between them (think about them as just cl_file and sv_file both in one to save space :v)
Another question, if anyone wants to answer. I made this: --Server stuff util.AddNetworkString( "EmoteListString" ) function ShowEmoteList(ply,text,team,death) if (string.lower(text) == "!emotes") then         net.Start("EmoteListString")         net.WriteEntity(ply)         net.Broadcast()     end end hook.Add("PlayerSay","ShowEmoteList", ShowEmoteList) --Client Stuff net.Receive("EmoteListString", EmoteUI) function EmoteUI()     local emoteui = vgui.Create("DFrame")     emoteui:SetSize(500, 500)     emoteui:Center()     local EmoteListUI = vgui.Create( "DListView", emoteui )     EmoteListUI:Dock(FILL)     EmoteListUI:SetMultiSelect(false)     EmoteListUI:AddColumn("Say this")     EmoteListUI:AddColumn("Play this")          for k,v in pairs(ChatSounds) do         EmoteListUI:AddLine( k, v )     end end (this is all in one file) This code works on a local game when I put it in the autorun folder. However, when I run it on my server typing '!emotes' doesn't show anything (no gui, no errors) Anyone know why this is happening?
util.AddNetworkString, net.Broadcast, GM/PlayerSay are server-side only. vgui is client-side only, your net.Receive callback should be only on client-side too. Fixed: Pastebin (still waiting for the code tag fix)
Awesome, that stuff works. Thank you so much! I'll have to work on declaring my variables and functions local.
Sorry, you need to Log In to post a reply to this thread.