So, I've been making a menu that includes pictures in the format of both png and jpg. They work fine in singleplayer of course, but I tried to add it to a server and the textures were
missing, replaced with the pink and black checkers. There was no errors or anything.
Here's some of the code.
[CODE]resource.AddFile("resource/gunlicense.jpg")
resource.AddFile("resource/carlicense.jpg")
resource.AddFile("resource/weedlicense.jpg")
resource.AddFile("resource/methcard.png")
resource.AddFile("resource/gun.png")
resource.AddFile("resource/car.png")
resource.AddFile("resource/weed.png")
resource.AddFile("resource/weedsel.png")
resource.AddFile("resource/meth.png")
resource.AddFile("resource/methsel.png")
resource.AddFile("resource/fonts/walkway.ttf")[/CODE]
This is put in addons/addonname/lua/autorun/server/forcedls.lua
The pictures are put in addons/addonname/resource
I should mention that the font works fine.
I saw a thread posted about a very similar problem but it didn't seem to have any solution that worked for me. Any ideas what I'm doing wrong here?
Regards
[QUOTE=isagrat;50697243]
~code~
[/QUOTE]
The folder under your addon folder mirror the base folder for garrysmod, you probably want to put your images under a materials folder, and change the paths accordingly.
[code]
garrysmod
addons
youraddon
lua
autorun
server
forcedls.lua
materials
gunlicense.jpg
carlicense.jpg
:
:
methsel.png
resource
fonts
walkway.ttf
[/CODE]
[QUOTE=Apickx;50697301]The folder under your addon folder mirror the base folder for garrysmod, you probably want to put your images under a materials folder, and change the paths accordingly.
[code]
garrysmod
addons
youraddon
lua
autorun
server
forcedls.lua
materials
gunlicense.jpg
carlicense.jpg
:
:
methsel.png
resource
fonts
walkway.ttf
[/CODE][/QUOTE]
I placed the pictures in addons/addonname/materials
Then I did
[CODE]resource.AddFile("materials/gunlicense.jpg")
resource.AddFile("materials/carlicense.jpg")
resource.AddFile("materials/weedlicense.jpg")
resource.AddFile("materials/gun.png")
resource.AddFile("materials/car.png")
resource.AddFile("materials/weed.png")
resource.AddFile("materials/weedsel.png")
resource.AddFile("resource/fonts/walkway.ttf")
[/CODE]
Just like before, and it didn't work.
Whenever I refer to it elsewhere in the addon, I use this
[CODE]local carLcnsIco = Material("materials/car.png")
[/CODE]
Still not working sadly.
Ah, found it, you don't need "materials/" as part of the path.
Here's a working example
[CODE]
--An example to show how to use resources!
resource.AddFile("example.png")
local exmat = Material("example.png","noclamp smooth")
hook.Add( "HUDPaint", "HUDPaint_DrawABox", function()
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetMaterial(exmat)
surface.DrawTexturedRect( 0, 0, 512, 512 )
end )
[/CODE]
And here's the folder structure
[CODE]
garrysmod/
addons/
resourcexample/
lua/
autorun/
example.lua
materials/
example.png
[/CODE]
[img]http://i.imgur.com/vM5XmGw.png[/img]
You need materials/ for resource.Add() but not Material()
[QUOTE=Chessnut;50698542]You need materials/ for resource.Add() but not Material()[/QUOTE]
Aight so lemme get this straight.
I put the pictures in myaddon/materials/
Then add them with
[CODE]resource.AddFile("materials/hello.png")[/CODE]
Then refer to them elsewhere as
[CODE]local hi = Material("hello.png")[/CODE]
Correct or no? I sadly can't test it out for another while.
Okay so, unfortunately the problem still occurs after everything. Images in addon/materials/. Lua file in lua/autorun/forcedownloads.lua containing all the resource.AddFile stuff. Referring to the materials as their file name in any other files. Yet it still fails to show the pictures in game.
It's working fine with a font I added, but the font is placed in resource/fonts/. Is it worth taking the time to convert the images to vtf/vmt to see if it fixes it? I'm at a loss for what to do.
No don't convert them I made that mistake once. Are you putting your code within a HUDPaint Hook?
for example
[code]
hook.Add("HUDPaint", "Your Identifier", function ()
--Your code here
end)
[/code]
It's 100% a problem with the files not downloading/being put in the wrong place. Nothing is wrong with the drawing of the pictures because it shows them in pink and black checkers.
move your forcedownloads.lua into your server folder.
Tried that before and it changed nothing.
[QUOTE=isagrat;50704512]Tried that before and it changed nothing.[/QUOTE]
Then put the code from forcedownloads.lua into your server.lua
No idea what you mean by server.lua. Where's that at?
the lua file in your server folder..
There's no file called server.lua in there so I had no idea what you were talking about. Anyway the problem still stands
So you don't have a lua file in wakemeupinside/lua/autorun/server ?
make one and put that code in there. You can call it anything, as long as it's a lua file.
Just did and it still won't work
just kill me
Did you rejoin the server?
Yes because I'm restarting it every time i change something
Well, I'm afraid you're SOL because I have no idea.
Unless someone else does.
Hmm, does it make any odds that when I'm referring to the materials to draw them it's done clientside. For example in cl_init.lua of an entity is this:
[CODE]local weedLcnsMat = Material("weedlicense.jpg")[/CODE]
But the resource.AddFile stuff is done serverside. Does it make any odds or am I just fucked?
try changing it from "weedlicense.jpg" to "materials/weedlicense.jpg"
if that doesn't work then mess with the filepaths in the resource.AddFile("") too because that's a problem I ran into. Just trial and error with the file paths until I got it.
Sorry, you need to Log In to post a reply to this thread.