• CHud error
    19 replies, posted
RetroRP/gamemode/cl_init.lua:7: unexpected symbol near '-' ********************************************** ********************************************** ********** COULDN'T LOAD GAMEMODE!! ********** ********************************************** ********************************************** There was a problem opening the gamemode file 'RetroRP/gamemode/cl_init.lua' I tryed to make this HUD work here is the lines: 1. function hidehud(name) 2. for k, v in pairs{"CHudHealth", "CHudBattery"} 3. if name == v then return false end 4. end 5. end 6. hook.Add("HUDShouldDrawn", "hidehud", hidehud) 7. 8. function GM:HUDPaint () 9. 10. self.BaseCLASS:HUDpaint() 11. 12. local person = LocalPlayer() 13. 14. local Health = LocalPlayer () :Health () 15. 16. surface.CreateFont("coolvetica",64,409,false,false,("roleplay") 17. 18. surface.SetTextColor( 255,255,255,255 ) 19. surface.SetTextPos( 34, (ScrH()/2)+(ScrH()/4) ) 20. surface.SetFont("roleplay") 21. surface.DrawText( Health ) 22. 23. end 24. 25. end 26. 27. surface.SetTextColor( 255,255,255,255 ) 28. surface.SetTextPos( 34, (ScrH()/4+(ScrH()/8) ) 29. surface.SetFont("roleplay" 30. surface.Drawtext ( Battery ) 31. 32. end Sorry i'm trying to learn lua to it's fullest and was wondering how i could fix this error
first use lua tags and is that the whole cl_init.lua?
Yes it is the whole cl_init
Try replacing it with this: [code]function hidehud(name) if !table.HasValue({"CHudHealth" , "CHudbattery"} , name) then return false end return true end hook.Add("HUDShouldDraw", "hidehud", hidehud) [/code]
Still getting RetroRP/gamemode/cl_init.lua:7: unexpected symbol near '-'
Post the code in [lua ] [/lua ] without the extra space at the end.
Ok i'm try i messed it up first time
[QUOTE=RamRam;18207678][lua ]function hidehud(name) if !table.HasValue({"CHudHealth" , "CHudbattery"} , name) then return false end return true end hook.Add("HUDShouldDraw", "hidehud", hidehud) function GM:HUDPaint () self.BaseCLASS:HUDpaint() local person = LocalPlayer() local Health = LocalPlayer () :Health () surface.CreateFont("coolvetica",64,409,false,false,("roleplay") surface.SetTextColor( 255,255,255,255 ) surface.SetTextPos( 34, (ScrH()/2)+(ScrH()/4) ) surface.SetFont("roleplay") surface.DrawText( Health ) end end surface.SetTextColor( 255,255,255,255 ) surface.SetTextPos( 34, (ScrH()/4+(ScrH()/8) ) surface.SetFont("roleplay" surface.Drawtext ( Battery ) end [/lua ][/QUOTE] Without the space at the end. Like this. [lua]function hidehud(name) if !table.HasValue({"CHudHealth" , "CHudbattery"} , name) then return false end return true end hook.Add("HUDShouldDraw", "hidehud", hidehud) function GM:HUDPaint () self.BaseCLASS:HUDpaint() local person = LocalPlayer() local Health = LocalPlayer () :Health () surface.CreateFont("coolvetica",64,409,false,false,("roleplay") surface.SetTextColor( 255,255,255,255 ) surface.SetTextPos( 34, (ScrH()/2)+(ScrH()/4) ) surface.SetFont("roleplay") surface.DrawText( Health ) end end surface.SetTextColor( 255,255,255,255 ) surface.SetTextPos( 34, (ScrH()/4+(ScrH()/8) ) surface.SetFont("roleplay" surface.Drawtext ( Battery ) end [/lua] Now we can read it :3 Try this. [lua]function hidehud(name) if !table.HasValue({"CHudHealth" , "CHudbattery"} , name) then return false end return true end hook.Add("HUDShouldDraw", "hidehud", hidehud) function GM:HUDPaint () self.BaseClass:HUDPaint() local person = LocalPlayer() local Health = person:Health() local Battery = person:Armor() surface.CreateFont("coolvetica",64,409,false,false,("roleplay") surface.SetTextColor( 255,255,255,255 ) surface.SetTextPos( 34, (ScrH()/2)+(ScrH()/4) ) surface.SetFont("roleplay") surface.DrawText( Health ) surface.SetTextColor( 255,255,255,255 ) surface.SetTextPos( 34, (ScrH()/4+(ScrH()/8) ) surface.SetFont("roleplay" surface.Drawtext ( Battery ) end [/lua]
It appears there are too many ends and code outside of a draw hook. :3: I bet it wasn't indented like that for him. Also no trace of a ' - '.
xD ok thanks, and the end codes do i need the one's near the end?
[QUOTE=RamRam;18207769]xD ok thanks, and the end codes do i need the one's near the end?[/QUOTE] Try this (Posted above) [lua]function hidehud(name) if !table.HasValue({"CHudHealth" , "CHudbattery"} , name) then return false end return true end hook.Add("HUDShouldDraw", "hidehud", hidehud) function GM:HUDPaint () self.BaseClass:HUDPaint() local person = LocalPlayer() local Health = person:Health() local Battery = person:Armor() surface.CreateFont("coolvetica",64,409,false,false,("roleplay") surface.SetTextColor( 255,255,255,255 ) surface.SetTextPos( 34, (ScrH()/2)+(ScrH()/4) ) surface.SetFont("roleplay") surface.DrawText( Health ) surface.SetTextColor( 255,255,255,255 ) surface.SetTextPos( 34, (ScrH()/4+(ScrH()/8) ) surface.SetFont("roleplay" surface.Drawtext ( Battery ) end [/lua]
I keep getting RetroRP/gamemode/cl_init.lua:7: unexpected symbol near '-'
Try removing this: self.BaseClass:HUDPaint()
Ok i did that now i'm getting RetroRP/gamemode/cl_init.lua:24: ')' expected (to close '(' at line 22) near 'surface' to fix that i would do surface.Drawtext (Battery) Sorry still learning lua a bit.
[lua]function hidehud(name) if table.HasValue({"CHudHealth" , "CHudbattery"} , name) then return false end return true end hook.Add("HUDShouldDraw", "hidehud", hidehud) function GM:HUDPaint () self.BaseClass:HUDPaint() local person = LocalPlayer() local Health = person:Health() local Battery = person:Armor() surface.CreateFont("coolvetica",64,409,false,false,("roleplay")) surface.SetTextColor( 255,255,255,255 ) surface.SetTextPos( 34, (ScrH()/2)+(ScrH()/4) ) surface.SetFont("roleplay") surface.DrawText( Health ) surface.SetTextColor( 255,255,255,255 ) surface.SetTextPos( 34, (ScrH()/4+(ScrH()/8) )) surface.SetFont("roleplay") surface.Drawtext ( Battery ) end [/lua] You forgot to close the brackets in several places. Suprised I didn't notice before xD
So that small errors such as wrong blocks and missing brackets don't affect you as much I suggest you get Notepad++, a free editor, along with a Gmod lua syntax highlighting plugin.
I gave it my friend he got it to work but they both show as zero: [url]http://i34.tinypic.com/11uhuyv.png[/url]
Replace [lua]local Health = person:Armor()[/lua] with [lua]local Health = person:Health()[/lua] Pretty obvious error, eh?
Yeah works find now thanks.
[QUOTE=DarKSunrise;18218488]Replace [lua]local Health = person:Armor()[/lua] with [lua]local Health = person:Health()[/lua] Pretty obvious error, eh?[/QUOTE] Copy / paste fail on my part :3
Sorry, you need to Log In to post a reply to this thread.