• Simple Gamemode Error help
    10 replies, posted
I'm coding my own simple game mode. This is my first real big experience with lua, but it seems that every time I load up my gamemode it give's me this error [ERROR] gamemodes/teamdeathmatch/gamemode/cl_init.lua:9: 'do' expected near 'if' 1. unknown - gamemodes/teamdeathmatch/gamemode/cl_init.lua:0 Couldn't Load Init Script: 'teamdeathmatch/gamemode/cl_init.lua' I do not know how to fix it. If you can can you please help me.
Can you post your code?
This is what is done so far: include( 'shared.lua' ) // Clientside only stuff goes here function HUDHIDE( myhud ) for k, v in pairs{ "CHudHealth", "CHudBattery" } if myhud == v then return false end end end hook.Add( "HUDShouldDraw", "HUDHide", HUDHide ) function BetterHUD() local ply = LocalPlayer() local HP = ply:Health() local ARM = ply:Armor() local wep = ply:GetActiveWeapon() surface.DrawText( HP ) draw.RoundedBox( 6, 100, ScrH() - 100, 200, 40, Color ( 85, 52, 100, 120) ) draw.RoundedBox( 4, 100, ScrH() - 100, math.Clamp( HP, 0, 200)*2, 40, Color ( 220, 0, 0, 255)) draw.RoundedBox( 4, 100, ScrH() - 100, math.Clamp( HP, 0, 200)*2, 10, Color ( 255,255,255,40) ) end hook.Add( "HUDPaint", "BetterHUD", BetterHUD ) //Welcome message Function function WMsg() chat.AddText(Color(255, 75, 255), "[CG] ", Color(120, 0, 255), "Welcome to TDM. ENJOY!!!") end usermessage.Hook( "Welcome", WMsg ) function PMsg chat.Add( Color(255, 75, 255), "[CG] ", Color(120, 0, 255), UMsg:ReadString()) end usermessage.Hook( "Are you having fun, then join our forums", PMsg )
Normally questions like this would go in developer discussion. Anyways, just like you need a 'then' in an 'if' statement, you need a 'do' in a 'for' loop. So the 9th line should be for k, v in pairs{ "CHudHealth", "CHudBattery" } [b]do[/b] Alternatively, you could just replace that whole loop with something like [code]if myhud == "CHudHealth" or myhud == "CHudBattery" then return false end[/code]
It's still showing the Garry's Mod default health how do I get rid of that
The HUDHIDE function you have should get rid of it, but in the hook the function name needs to match the case of the function you created; names in lua are case-sensitive. You'll also have the problem of that function causing every hud element to not draw since it doesn't return true by default. A working example of lines 8 through 13 would be: [code]function HUDHide( hud ) if hud == "CHudHealth" or hud == "CHudBattery" then return false end return true end hook.Add( "HUDShouldDraw", "HUDHide", HUDHide )[/code]
I did that but now it stop including my shared, lua and sh_meta files heres the errors I get: [/lua]Couldn't include file 'shared.lua' (File not found) (@gamemodes/teamdeathmatch/gamemode/cl_init.lua (line 1)) Couldn't include file 'sh_meta.lua' (File not found) (@gamemodes/teamdeathmatch/gamemode/cl_init.lua (line 2))[/lua]
[QUOTE=bliptec;43878975]The HUDHIDE function you have should get rid of it, but in the hook the function name needs to match the case of the function you created; names in lua are case-sensitive. You'll also have the problem of that function causing every hud element to not draw since it doesn't return true by default. A working example of lines 8 through 13 would be: [code]function HUDHide( hud ) if hud == "CHudHealth" or hud == "CHudBattery" then return false end return true end hook.Add( "HUDShouldDraw", "HUDHide", HUDHide )[/code][/QUOTE] If you are hooking it you shouldn't return true, that will prevent any other hooks from running (shouldn't really matter for this persons gamemode, but would matter in other situations). If you don't return anything it should run the function from the gamemode, which will return true (if it's been left the same as the base gamemode).
I was just following my lua book, but ever since I changed my code these two annoying errors keep popping up and it stopped loading my team's loadout and everything these errors are below: Couldn't include file 'shared.lua' (File not found) (@gamemodes/teamdeathmatch/gamemode/cl_init.lua (line 1)) Couldn't include file 'sh_meta.lua' (File not found) (@gamemodes/teamdeathmatch/gamemode/cl_init.lua (line 2))
[QUOTE=Vontae;43879450]I was just following my lua book, but ever since I changed my code these two annoying errors keep popping up and it stopped loading my team's loadout and everything these errors are below: Couldn't include file 'shared.lua' (File not found) (@gamemodes/teamdeathmatch/gamemode/cl_init.lua (line 1)) Couldn't include file 'sh_meta.lua' (File not found) (@gamemodes/teamdeathmatch/gamemode/cl_init.lua (line 2))[/QUOTE] Look for different errors further up - if there is an error in those files then they won't get sent, so they can't be included. And I assume you have tried restarting the server/game first (seems obvious, but some people don't). And you are actually sending those files to the client with AddCSLuaFile() right?
ZYes, but I have no idea how to fix them I spent the past two to three hours trying to fix them but to no avail.
Sorry, you need to Log In to post a reply to this thread.