Hi, I've been looking around the web for about 4 hours total searching for this.
I need to force the client to download a sound file. From what I've learned:
I have to make a file called "forceddownloads.lua" (If this isn't deprecated), In the directory "garrysmod/lua/autorun/server/forceddownloads.lua"
However, I'm running a dedicated server, and making a gamemode.
Is there any way I could make a file that runs from the gamemodes' folder so that if I distribute it the file can download from "/gamemodes/test/content/sound" without having to put a seperate file into your servers' /lua folder?
Here you go: [url]http://facepunch.com/showthread.php?t=1283766&highlight=[/url]
[QUOTE=Sgt. Sicknezz;41691360]Here you go: [URL]http://facepunch.com/showthread.php?t=1283766&highlight=[/URL][/QUOTE]
Yeah, I rated too early. In the OP I stated that I want to make it unpack from the gamemode folder, or have it be portable without having to slap it in "/garrysmod/lua[...]". Making a "garrysmod\gamemodes\test\lua\autorun\server\addfiles.lua" did nothing.
Provide us with your code please.
[QUOTE=ShadowRanger;41691886]Provide us with your code please.[/QUOTE]
cl_init.lua
[CODE]
include("shared.lua")
function testpanel() -- Create the function
local Panel = vgui.Create("DFrame");
Panel:SetPos(100, 100);
Panel:SetSize(ScrW() - 100, ScrH() - 100);
Panel:SetTitle("Main Menu");
Panel:MakePopup();
local Sheet = vgui.Create("DPropertySheet", Panel);
Sheet:SetPos(25, 35);
Sheet:SetSize(Panel:GetWide() - 4, Panel:GetTall() - 22);
Sheet.Paint = function() -- The paint function
surface.SetDrawColor( 24, 37, 49, 255 ) -- What color ( R, G, B, A )
surface.DrawRect( 0, 0, ScrW() - 150, ScrH() - 150) -- How big is it (cords)
end
// local SheetItem = vgui.Create("DCheckBoxLabel", Sheet);
// SheetItem:SetText("Cheats");
// SheetItem:SetConVar("sv_cheats");
// SheetItem:SetValue(1);
// SheetItem:SizeToContents();
local SheetItem2 = vgui.Create("DTextEntry", Sheet);
SheetItem2:SetValue("Entity Name");
SheetItem2:SetPos(30, 10);
SheetItem2:SetSize(100, 18);
SheetItem2:SizeToContents();
local SheetItem3 = vgui.Create("DButton", Sheet);
SheetItem3:SetPos(30, 50);
SheetItem3:SetSize(100, 50);
SheetItem3:SetText("Get Entity");
SheetItem3.DoClick = function()
local Ent = SheetItem2:GetValue()
RunConsoleCommand("give", Ent)
end
local SheetItem4 = vgui.Create("DButton", Sheet);
SheetItem4:SetPos(30, 150);
SheetItem4:SetSize(100, 50);
SheetItem4:SetText("Get Healthkit");
SheetItem4.DoClick = function()
RunConsoleCommand("give", "item_healthkit")
end
local Battery = vgui.Create("DButton", Sheet);
Battery:SetPos(30, 200);
Battery:SetSize(100, 50);
Battery:SetText("Get Battery");
Battery.DoClick = function()
RunConsoleCommand("give", "item_battery")
end
local Team = vgui.Create("DButton", Sheet);
Team:SetPos(130, 10);
Team:SetSize(100, 18);
Team:SetText("Red Team");
Team.DoClick = function()
Msg("Fuck!")
end
local kill = vgui.Create("DButton", Sheet);
kill:SetPos(130, 50);
kill:SetSize(100, 50);
kill:SetText("Suicide");
kill.DoClick = function()
surface.PlaySound("test/content/sound/RRRR.wav")
RunConsoleCommand("kill")
Msg("\n\nDrank some bleach.\n\n")
end
Sheet:AddSheet("A sheet", SheetItem, "gui/silkicons/user", false, false, "Activate sv_cheats from here");
end -- ending the function
concommand.Add("menutest", testpanel) -- adding the console command
[/CODE]
player.lua
[CODE]
ply = FindMetaTable("Player")
teams = {}
teams[0] = {name = "Team 1", color = Vector( .2, .2, 1.0 ), weapons = {"weapon_crowbar", "weapon_crossbow"} } //Add weapons here, teams can be viewed in shared.lua
teams[1] = {name = "Team 2", color = Vector( 1.0, .2, .2 ), weapons = {"weapon_crowbar", "weapon_crossbow"} }
function ply:SetGamemodeTeam( n )
if not teams[n] then return end
self:SetTeam( n )
self:SetPlayerColor( teams[n].color )
self:GiveGamemodeWeapons()
self:GetHandsModel()
return true
end
function ply:GiveGamemodeWeapons()
local n = self:Team()
self:StripWeapons()
for k, wep in pairs(teams[n].weapons) do
self:Give(wep)
end
end
function ply:GetHandsModel()
return { model = "models/weapons/c_arms_cstrike.mdl", skin = 1, body = "0100000" }
end
[/CODE]
init.lua
[CODE]
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
include("player.lua")
function GM:PlayerConnect( name, ip )
print("Player: " .. name .. ", has joined the game.")
PrintMessage(HUD_PRINTCENTER, "Player: " .. name .. ", has joined the game.")
end
function GM:PlayerInitialSpawn( ply )
print("Player: " .. ply:Nick() .. ", has spawned.")
PrintMessage(HUD_PRINTCENTER, "Player: " .. ply:Nick() .. ", has spawned.")
ply:SetGamemodeTeam( 0 )
end
function GM:PlayerSpawn( ply )
print(ply:Nick().. " Respawned!")
PrintMessage(HUD_PRINTTALK, ply:Nick().. " Respawned!")
ply:GetHandsModel()
ply:GiveGamemodeWeapons()
end
function GM:PlayerAuthed( ply, steamID, uniqueID )
print("Player: " .. ply:Nick() .. ", has gotten authed.")
end
[/CODE]
shared.lua
[CODE]
GM.Name = "test" // Put Gamemode info here
GM.Author = "N/A"
GM.Email = "N/A"
GM.Website = "N/A"
team.SetUp( 0, "Team 1", Color(0, 0, 255) )
team.SetUp( 1, "Team 2", Color(255, 0, 0) )
function GM:Initialize()
self.BaseClass.Initialize( self )
end
sound.Add(
{
name = "RRRR",
channel = CHAN_STATIC,
volume = 1.0,
soundlevel = 80,
pitchstart = 95,
pitchend = 110,
sound = "content/sound/RRRR.wav"
})
[/CODE]
addfiles.lua
[CODE]
resource.AddFile("test\content\sound\RRRR.wav")
[/CODE]
By the way, there is a bunch of stuff lying around that I've yet to remove/modify. If you can ignore those bits (sound.Add for example), I'd appreciate it.
Have you AddCSLuaFile'd and include'd the addfiles.lua? I don't see it anywhere in your init.lua. Alternatively, to make it easier for you, try placing the resource.AddFile part in your init.lua instead.
[QUOTE=ShadowRanger;41692008]Have you AddCSLuaFile'd and include'd the addfiles.lua? I don't see it anywhere in your init.lua. Alternatively, to make it easier for you, try placing the resource.AddFile part in your init.lua instead.[/QUOTE]
I tried adding it to init.lua just now as you suggested, AddCSLuaFile recognizes it.
When I try
"include("/lua/autorun/server/addfiles.lua")" I get "Couldn't include file '\lua\autorun\\server\addfiles.lua (@gamemodes/test/gamemode/init.lua (line 7))
[QUOTE=Karnalphuli;41692073]I tried adding it to init.lua just now as you suggested, AddCSLuaFile recognizes it.
When I try
"include("/lua/autorun/server/addfiles.lua")" I get "Couldn't include file '\lua\autorun\\server\addfiles.lua (@gamemodes/test/gamemode/init.lua (line 7))[/QUOTE]Yeah it's probably best not to have your gamemode code in a completely different directory... Put it in your gamemode folder instead, not the autorun folder.
[QUOTE=ShadowRanger;41692117]Yeah it's probably best not to have your gamemode code in a completely different directory... Put it in your gamemode folder instead, not the autorun folder.[/QUOTE]
Okay, now that I've changed the directory (addfiles.lua is now in "test\gamemode\") I'm getting an error from console:
[CODE]
[ERROR] gamemodes/test/gamemode/addfiles.lua:1: invalid escape sequence near '"test'
1. unknown - gamemodes/test/gamemode/addfiles.lua:0
[/CODE]
My "addfiles.lua" is as follows:
[CODE]
resource.AddFile("test\content\sound\RRRR.wav")
[/CODE]
Is this because I need an opening/closing statement? I've never heard anything about needing one.
This might not make any difference but I've found that it works better for me and for some other people. Try using this instead:
[CODE]resource.AddSingleFile("test/content/sound/RRRR.wav")[/CODE]
Also, if that doesn't work you may need to further define that 'test' is your gamemode folder.
[QUOTE=ShadowRanger;41692237]This might not make any difference but I've found that it works better for me and for some other people. Try using this instead:
[CODE]resource.AddSingleFile("test/content/sound/RRRR.wav")[/CODE]
Also, if that doesn't work you may need to further define that 'test' is your gamemode folder.[/QUOTE]
Thanks, this stopped the errors, but I'm still not downloading the file...
In Garry's mod's console I'm getting
"Failed to load sound "test\content\sound\rrrr.wav", file probably missing from disk/repository" as usual.
Thanks for all your help so far, by the way.
Try resource.AddSingleFile("sound/RRRR.wav) so without the test/content bit.
Okay, I've changed the directory in both "cl_init.lua" and "addfiles.lua".
addfiles.lua
[CODE]
resource.AddSingleFile("sound/RRRR.wav")
[/CODE]
(Bit in use in) cl_init.lua
[CODE]
local kill = vgui.Create("DButton", Sheet);
kill:SetPos(130, 50);
kill:SetSize(100, 50);
kill:SetText("Suicide");
kill.DoClick = function()
surface.PlaySound("sound/RRRR.wav")
RunConsoleCommand("kill")
Msg("\n\nDrank some bleach.\n\n")
end
[/CODE]
This sort of worked!
We're making progress :D
I did download the file, however when I press the "suicide" button I still get that it cannot be loaded.
Could this be because the client is looking for the sound in a folder where it was not downloaded to?
Add util.PrecacheSound("sound/RRRR.wav") to your gamemode shared.lua
[QUOTE=ShadowRanger;41692463]Add util.PrecacheSound("sound/RRRR.wav") to your gamemode shared.lua[/QUOTE]
Done. Not sure if I did it right, but it seems fine to me.
shared.lua
[CODE]
GM.Name = "test" // Put Gamemode info here
GM.Author = "N/A"
GM.Email = "N/A"
GM.Website = "N/A"
util.PrecacheSound("sound/RRRR.wav")
team.SetUp( 0, "Team 1", Color(0, 0, 255) )
team.SetUp( 1, "Team 2", Color(255, 0, 0) )
function GM:Initialize()
self.BaseClass.Initialize( self )
end
sound.Add(
{
name = "RRRR",
channel = CHAN_STATIC,
volume = 1.0,
soundlevel = 80,
pitchstart = 95,
pitchend = 110,
sound = "content/sound/RRRR.wav"
})
[/CODE]
Again, please ignore the sound.add, I'm using this as a reminder to set that up in the future (unless it's messing this up, of course).
Also; I've been doing full server restarts between these, This is necessary, as it is adding new resources, correct?
You still have content/ in the sound.Add part. Also, you have the addfiles.lua serverside, correct? As for restarting the server, yes, it's best to do so in this case.
[QUOTE=ShadowRanger;41692598]You still have content/ in the sound.Add part. Also, you have the addfiles.lua serverside, correct? As for restarting the server, yes, it's best to do so in this case.[/QUOTE]
I didn't think the sound.Add even worked from there, huh.
And as for it being serverside, not sure how I'd change it...?
(AddSSLuaFile didn't do anything, decided to try it and it doesn't exist, woo! :P)
Show us the code for where you AddCSLuaFile and include it please.
[QUOTE=ShadowRanger;41692738]Show us the code for where you AddCSLuaFile and include it please.[/QUOTE]
init.lua
[CODE]
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
AddCSLuaFile("addfiles.lua")
include("shared.lua")
include("player.lua")
include("addfiles.lua")
function GM:PlayerConnect( name, ip )
print("Player: " .. name .. ", has joined the game.")
PrintMessage(HUD_PRINTCENTER, "Player: " .. name .. ", has joined the game.")
end
function GM:PlayerInitialSpawn( ply )
print("Player: " .. ply:Nick() .. ", has spawned.")
PrintMessage(HUD_PRINTCENTER, "Player: " .. ply:Nick() .. ", has spawned.")
ply:SetGamemodeTeam( 0 )
end
function GM:PlayerSpawn( ply )
print(ply:Nick().. " Respawned!")
PrintMessage(HUD_PRINTTALK, ply:Nick().. " Respawned!")
ply:GetHandsModel()
ply:GiveGamemodeWeapons()
end
function GM:PlayerAuthed( ply, steamID, uniqueID )
print("Player: " .. ply:Nick() .. ", has gotten authed.")
end
[/CODE]
Due to the fact your not using the sound.Add part, just remove it or comment it out for now. In addition to that, you don't need 'sound/' in surface.PlaySound so change it to surface.PlaySound("RRRR.wav")
[QUOTE=ShadowRanger;41692806]Due to the fact your not using the sound.Add part, just remove it or comment it out for now. In addition to that, you don't need 'sound/' in surface.PlaySound so change it to surface.PlaySound("RRRR.wav")[/QUOTE]
Alright, all set! It worked! Thanks a bunch man.
(Could I add you on steam or PM you about 2 other things related? (How to do the sound.Add params, is one)
I really appreciate your help, it really encourages me to keep going with LUA :)
[QUOTE=Karnalphuli;41692851]Alright, all set! It worked! Thanks a bunch man.
(Could I add you on steam or PM you about 2 other things related? (How to do the sound.Add params, is one)
I really appreciate your help, it really encourages me to keep going with LUA :)[/QUOTE]No problem, I'm glad it worked. Feel free to mark this thread as solved if you can so people know its already been sorted. Also, just PM me here on Facepunch if you ned a bit of help, I'll be happy to help you to the best of my ability.
Sorry, you need to Log In to post a reply to this thread.