[WTF][HUD] attempt to index global 'surface' (a nil value)

I’ve got this error when i try to run my LUA hud , it’s based on Dlaor’s Crysis quick menu (http://www.garrysmod.org/downloads/?a=view&id=83466)

ERROR : [lua][addons\crysishud\lua\autorun\client\crysishud.lua:8] attempt to index global ‘surface’ (a nil value)[/lua]

Code :

[lua]
local soundconvar = CreateClientConVar( “crysishud_enablesounds”, 1, false, false )
local smoothconvar = CreateClientConVar( “crysishud_enabletransitions”, 1, false, false )

local crytx = surface.GetTextureID(“crysis_button”)
local crycircletx = surface.GetTextureID(“crysis_circle”)
local cryarrowtx = surface.GetTextureID( “crysis_arrow”)
local global_mul, global_mul_goal = 0, 0 //The global multiplier, if this is 0 the menu is hidden, 1 and it’s fully visible, between 0 and 1 for transition
local cryx, cryy = ScrW() / 2, ScrH() / 2 //Changing this makes the menu appear in a different place
local selected, oldselected = 0, 0 //Which slot is selected?

local snd_o, snd_c, snd_s, snd_h, snd_e = Sound( “cry_open.wav” ), Sound( “cry_close.wav” ), Sound( “cry_select.wav” ), Sound( “cry_hover.wav” ), Sound( “cry_error.wav” )

local crydist = {}
for i = 1, 5 do
crydist* = 0
end

local armormode = {}
armormode[“Armor”] = {}
armormode[“Armor”].number = “6”
armormode[“Armor”].name = “Armor”
armormode[“Speed”] = {}
armormode[“Speed”].number = “9”
armormode[“Speed”].name = “Speed”
armormode[“Strenght”] = {}
armormode[“Strenght”].number = “9”
armormode[“Strenght”].name = “Strenght”
armormode[“Cloak”] = {}
armormode[“Cloak”].number = “-”
armormode[“Cloak”].name = “Cloak”
armormode[“Drop”] = {}
armormode[“Drop”].number = “.”
armormode[“Drop”].name = “Drop”

local slots = {}
slots[1] = armormode[“Armor”]
slots[2] = armormode[“Strenght”]
slots[3] = armormode[“Speed”]
slots[4] = armormode[“Strenght”]
slots[5] = armormode[“Drop”]

function MouseInCircle( x, y )

local centerdist = math.Dist( gui.MouseX(), gui.MouseY(), x, y )
return ( centerdist > 32 and centerdist < 150 )

end

function CRYHUD() //Good luck figuring all this shit out

if ( global_mul_goal != global_mul ) then
	global_mul = global_mul + ( global_mul_goal - global_mul ) * math.Clamp( FrameTimeExt() * 10, 0, 1 ) //I love mah math
end 

if ( global_mul == 0 ) then return end //Don't run if the menu ain't visible

surface.SetTexture( crytx )
surface.SetDrawColor( 255, 255, 255, 255 )
surface.SetTextColor( 255, 255, 255, global_mul * 255 )
surface.SetFont( "HL2MPTypeDeath" )

local cryadd = 360/5
local numb = 1
local cursorang = math.fmod( math.atan2( gui.MouseY() - cryy, gui.MouseX() - cryx ), math.pi * 2 ) //This angle shit makes my head implode
local cursorangd = math.deg( cursorang ) + 180

if ( cursorangd >= 0 and cursorangd < cryadd ) then selected = 4
elseif ( cursorangd >= cryadd and cursorangd < cryadd * 2 ) then selected = 3
elseif ( cursorangd >= cryadd * 2 and cursorangd < cryadd * 3 ) then selected = 2
elseif ( cursorangd >= cryadd * 3 and cursorangd < cryadd * 4 ) then selected = 1
elseif ( cursorangd >= cryadd * 4 and cursorangd < cryadd * 5 ) then selected = 5
end //Fucking hell this took like forever ever to figure out

if ( !MouseInCircle( cryx, cryy ) ) then selected = 0 end //If the mouse isn't in the circle, don't light up any slot

for i = 0 + cryadd / 2, 360 - cryadd / 2, cryadd do
	
	local crydistadd = 96
	local crygray = 200
	if ( numb == selected ) then //If the slot is selected, light it up and move it outside
		crydistadd = crydistadd * 1.3
		crygray = 255
	end
	
	crydist[numb] = crydist[numb] + ( crydistadd - crydist[numb] ) * math.Clamp( FrameTimeExt() * 20, 0, 1 )
	
	local cryaddx, cryaddy = math.sin( math.rad( i ) ) * crydist[numb] * global_mul, math.cos( math.rad( i ) ) * crydist[numb] * global_mul
	local crytxtw, crytxth = surface.GetTextSize( slots[numb].number )
	surface.SetDrawColor( crygray, crygray, crygray, global_mul * 200 )
	surface.DrawTexturedRectRotated( cryx + cryaddx, cryy + cryaddy, 100 * global_mul, 100 * global_mul, i - 180 )
	surface.SetTextPos( cryx + cryaddx - crytxtw / 2, cryy + cryaddy - crytxth / 2 + 10 )

	surface.DrawText( slots[numb].number ) //Draw the character
	
	numb = numb + 1
	
end

surface.SetTexture( crycircletx )
surface.SetDrawColor( 255, 255, 255, global_mul * 255 )
surface.DrawTexturedRectRotated( cryx, cryy, 128 * global_mul, 128 * global_mul, math.fmod( CurTime() * -20, 360 ) )

surface.SetTexture( cryarrowtx )
local arrowang = math.pi * 2 - cursorang + math.pi / 2
local arrowdist = 47 * global_mul
local arrowx, arrowy = math.sin( arrowang ) * arrowdist, math.cos( arrowang ) * arrowdist
surface.DrawTexturedRectRotated( cryx + arrowx, cryy + arrowy, 128 / 3, 32 / 3, math.deg( arrowang ) + 180 )

if ( selected != oldselected and selected != 0 ) then PlaySnd( snd_h ) oldselected = selected end

end

hook.Add( “HUDPaint”, “CRYHUD”, CRYHUD )

function EnableMenu( b )

if ( ( b and global_mul_goal == 0 ) ) then PlaySnd( snd_o ) end
gui.EnableScreenClicker( b )
if ( b ) then global_mul_goal = 1 else global_mul_goal = 0 end

end

concommand.Add( “crysishud_slots”, ChangeSlots, ChangeSlotsAutoComplete )

function CryOpenClose( ply, command, args )

if ( command != "+crysishud" ) then
	if ( MouseInCircle( cryx, cryy ) ) then
		PlaySnd( snd_s )
		if ( slots[selected] ) then RunConsoleCommand = ( slots[selected].name )   end 

EnableMenu( command == "+crysishud" ) //Enable menu if it's +crysishud, disable otherwise

end
end

end

concommand.Add( “+crysishud”, CryOpenClose )
concommand.Add( “-crysishud”, CryOpenClose )

function player:ArmorMode(player)
if ( slots[selected] ) and ( slots[selected].name ) == “Armor” then return true

end
end

function player:CloakMode(player)
if ( slots[selected] ) and ( slots[selected].name ) == “Cloak” then return true

end
end

function player:SpeedMode(player)
if ( slots[selected] ) and ( slots[selected].name ) == “Speed” then return true

end
end

function player:StrenghtMode(player)
if ( slots[selected] ) and ( slots[selected].name ) == “Strenght” then return true

end
end

function PlaySnd( snd )

if ( soundconvar:GetBool() ) then surface.PlaySound( snd ) end

end

function FrameTimeExt()

if ( smoothconvar:GetBool() ) then return FrameTime() else return 1 end

end
[/lua]

This error usually occurs when you are trying to include a clientside file (like this one) on the server. The surface library is only available on the client.

I use this Addon in SinglePlayer …

EDIT :

[lua]
local crytx = surface.GetTextureID(“crysis_button”)
local crycircletx = surface.GetTextureID(“crysis_circle”)
local cryarrowtx = surface.GetTextureID( “crysis_arrow”)
[/lua]

Was already in the script…

When i use the addon on a server , no LUA error but it doesn’t work…

Thats what I was thinking but the path location of the error shows it is in autorun/client

So where the file should be located ?

Nobody can help me ?

Your file seems to be in the right location. However, you have not really told us what isn’t working as of now:

Does the HUD not load at all?
What color is the error message you receive? Blue or yellow?

If the message is blue then your file is being included on the server for some reason.
If it is yellow, the surface library is not being found / being overwritten.

FIXED , I replaced

[lua]function CryOpenClose( ply, command, args )

if ( command != "+crysishud" ) then
    if ( MouseInCircle( cryx, cryy ) ) then
        PlaySnd( snd_s )
        if ( slots[selected] ) then RunConsoleCommand = ( slots[selected].name )   end

EnableMenu( command == "+crysishud" ) //Enable menu if it's +crysishud, disable otherwise

end
end

end [/lua]

by

[lua]
function CryOpenClose( ply, command, args )

if ( command != "+crysishud" ) then
	if ( MouseInCircle( cryx, cryy ) ) then
		PlaySnd( snd_s )

for k,v in pairs(player.GetAll()) do
if ( slots[selected] ) and ( slots[selected].name ) == “Armor” then
v:ArmorMode(true)
end
end

for k,v in pairs(player.GetAll()) do
if ( slots[selected] ) and ( slots[selected].name ) == “Speed” then
v:SpeedMode(true)
end
end

for k,v in pairs(player.GetAll()) do
if ( slots[selected] ) and ( slots[selected].name ) == “Cloak” then
v:CloakMode(true)
end
end

for k,v in pairs(player.GetAll()) do
if ( slots[selected] ) and ( slots[selected].name ) == “Strenght” then
v:CloakMode(true)

end
end

	if ( slots[selected] )  and (  slots[selected].name ) == "Drop"  then  

v:ArmorMode(true)
RunConsoleCommand( “Drop” )
end

	elseif ( global_mul_goal == 1 ) then PlaySnd( snd_c ) end
end	

EnableMenu( command == "+crysishud" ) 

end

[/lua]

Now i have an other error :
[lua]
[lua\autorun\server\crysis_armor.lua:15] attempt to call method ‘SetNoTarget’ (a nil value)

[/lua]

Code :

[lua]

function speed()
for k,v in pairs(player.GetAll()) do
v:SetWalkSpeed(500)
v:SetRunSpeed(1000)
v:SetNoTarget(false)
v:DrawViewModel(true)
v:DrawWorldModel(true)
end
end

concommand.Add(“Speed”, speed)

[/lua]

Comment line number 5 out, tell us what breaks.

I want to make the player invisible by the NPC but it doesn’t work and i get this error

[lua] [lua\autorun\server\crysis_armor.lua:15] attempt to call method ‘SetNoTarget’ (a nil value) [/lua]

Why don’t you listen, so far you’ve done nothing anyones said. I doubt anyone is going to continue to help if you continue to ignore them.