Download lua autorun file from server

Hello. I have a lua autorun file that is clientside. But I need people when they join the server to download it. How can I do this?

If its easier can I incorporate it into DarkRP? I tried adding it into cl_init but that didn’t work.

Thanks.

Go to your garrysmod/garrysmod/autorun/server and make whatever.lua
Then copy this:
[lua]if SERVER then
AddCSLuaFile( “file.lua” )[/lua]

or if it’s a object, etc

[lua]if SERVER then
resource.AddFile(“material/model/lolwut.mdl”)[/lua]

Thanks, I was trying things like resource.addfile and stuff :stuck_out_tongue:

[editline]23rd January 2012[/editline]

Well. I got it to show up on the hud finally (Its a speedo off gmod.org that I edited with some extra text) but funny thing is that it doesn’t actually read the speed. It just stays on zero. Here’s the code. I’m guessing its something to do with serverside/clientside functions.




surface.CreateFont( "lcd", 36, 2, 0, 0, "lcd36" )

hook.Add("HUDPaint","espeedometer.paint",function()
	local conv = 10.936133
	local max = 114
	
	local speed = LocalPlayer()
	if LocalPlayer():IsValid() and LocalPlayer():InVehicle() then
		speed = speed:GetVelocity():Length()/conv
	else
		return
	end
	//speed = CurTime()*50%(max+30)
	
	if speed < 50 then
		draw.DrawText("You're below the speed limit!", "ScoreboardText", ScrW() / 2 - 70, ScrH() - 63, Color(255, 255, 0, 255),TEXT_ALIGN_TOP)
	elseif (speed < 60 && speed > 50) then
		draw.DrawText("You're at the speed limit!", "ScoreboardText", ScrW() / 2 - 70, ScrH() - 63, Color(0, 255, 0, 255),TEXT_ALIGN_TOP)
	else 
		draw.DrawText("You're above the speed limit!", "ScoreboardText", ScrW() / 2 - 70, ScrH() - 63, Color(255, 0, 0, 255),TEXT_ALIGN_TOP)
	end	
	
	draw.NoTexture()
	surface.SetDrawColor(0,0,0,128)
	
	local a = Vector(ScrW()*.25,ScrH(),1)
	local s = math.ceil(ScrW()/12/8)*8
	s = s
	
	surface.DrawPoly{
		{
			x = a.x - s*.5,
			y = a.y - s*.125,
		},
		{
			x = a.x + s*.2,
			y = a.y - s *.3,
		},
		{
			x = a.x + s*.5,
			y = a.y - s *.3,
		},
		{
			x = a.x + s*.5,
			y = a.y,
		},
		{
			x = a.x - s*.5,
			y = a.y,
		},
	}
	
	local alpha = 32
	for i = 0,math.min((speed/max)*(s/6-1),s/6-1) do
		if i < s/48 then
			surface.SetDrawColor(0,0,255,alpha)
		elseif i < s / 10 then
			surface.SetDrawColor(0,255,0,alpha)
		elseif i < s / 7 then
			surface.SetDrawColor(255,255,0,alpha)
		else
			surface.SetDrawColor(255,0,0,alpha)
		end
		
		//surface.DrawRect(a.x-s*.5+6*i+1,a.y-s,4,s)
		/*
			.3-.125
			.175
			s*.7
		*/
		
		local x = s*.5+6*i
		local c = 1-s
		local v = s/128
		local b = -s/32
		if i < s/8.5-1 then
			surface.DrawPoly{
				{
					x = a.x + c+x,
					y = a.y - x*.25+v,
				},
				{
					x = a.x + c+x+4,
					y = a.y - (x+4)*.25+v,
				},
				{
					x = a.x + c+x+4,
					y = a.y+b,
				},
				{
					x = a.x + c+x,
					y = a.y+b,
				},
			}
		else
			surface.DrawPoly{
				{
					x = a.x + c+x,
					y = a.y - s*.3+v,
				},
				{
					x = a.x + c+x+4,
					y = a.y - s*.3+v,
				},
				{
					x = a.x + c+x+4,
					y = a.y+b,
				},
				{
					x = a.x + c+x,
					y = a.y+b,
				},
			}
		end
	end
	
	
	
	local speedstr = tostring(math.Round(speed*10)/10)
	if string.sub(speedstr,-2,-2) ~= "." then
		speedstr = speedstr .. ".0"
	end
	draw.DrawText(speedstr,"lcd36",a.x+s*.5-8,a.y-36,Color(255,255,255,200),2)
end)

Change:

[lua]
local speed = LocalPlayer()
[/lua]

To

[lua]
local speed = LocalPlayer():GetVelocity();
[/lua]

Thanks but now that just errors in the console. Doesnt even show up. Something about not knowing what Getvelocity means

[editline]24th January 2012[/editline]

This is the error its creating.

ERROR: Hook ‘espeedometer.paint’ Failed: [lua\autorun\client\espeedometer.lua:16] attempt to call method ‘GetVelocity’ (a nil value)

Anyone?

It’s because Chessnut failed to realize that you were calling “speed” perfectly fine. You defined it as an entity, and checked for its velocity. What he has suggested would cause your code, if you only changed the bit he told you to change, to take the velocity of a velocity.

I don’t particularly know what’s wrong with your code, but I’ll try (and maybe someone else will get it before me) to help you out.

Thanks.