• cl_init
    6 replies, posted
Im not having a problem initializing the file according to the console, but in my gamemode the hud and etc gives me this error : [ERROR] gamemodes/battleroyale/gamemode/cl_init.lua:121: attempt to call method 'Alive' (a nil value) , and onyl way to get rid of it is to re-save the file during runtime. Anyone know what would cause this..?
How are we meant to point you to the line and tell you what the hell is wrong - when you haven't provided any code at all? @Edit: Altho symptome seems like you are applying a variable to localplayer before he loads.
[CODE] GM.Version = "0.0.1" GM.Name = "Battle Royale" GM.Author = "Damien Ostler | 336-823-0423 | Damienostler1@outlook.com" DeriveGamemode("base" ) include("cl_commandsystem.lua") client=LocalPlayer() local armormat = Material ("battleroyale/armor2.png", "nocull") local barfillmat = Material ("battleroyale/barFill.png", "nocull") local barmarkermat = Material ("battleroyale/barMarker.png", "nocull") local barbackgroundmat = Material ("battleroyale/barBackground.png", "nocull") local healthmat = Material ("battleroyale/health2.png", "nocull") local playerportraitmat = Material ("battleroyale/playerPortrait.png", "nocull") local crosshairmat = Material ("battleroyale/crosshair.png", "nocull") local honeycomb mat = Material ("battleroyale/honeyComb.png", "nocull") local CrosshairRadius = 25 local CrosshairColor = Color( 0, 0, 0, 255 ) surface.CreateFont( "HudFont1", { font = "Tele-Marines", -- Use the font-name which is shown to you by your operating system Font Viewer, not the file name size = 20, weight = 100, blursize = 0, scanlines = 0, antialias = true, underline = false, italic = false, strikeout = false, symbol = false, rotary = false, shadow = false, additive = false, outline = false, } ) surface.CreateFont( "HudFont2", { font = "Tele-Marines", -- Use the font-name which is shown to you by your operating system Font Viewer, not the file name size = 14, weight = 100, blursize = 0, scanlines = 0, antialias = true, underline = false, italic = false, strikeout = false, symbol = false, rotary = false, shadow = false, additive = false, outline = false, } ) surface.CreateFont( "HudTimer", { font = "Tele-Marines", -- Use the font-name which is shown to you by your operating system Font Viewer, not the file name size = 30, weight = 100, blursize = 0, scanlines = 0, antialias = true, underline = false, italic = false, strikeout = false, symbol = false, rotary = false, shadow = false, additive = false, outline = false, } ) local hide = { CHudAmmo = true, CHudBattery = true, CHudCrosshair = true, CHudHealth = true, CHudSecondaryAmmo = true, --CHudWeaponSelection = true } if not ConVarExists("cl_covercamera") then CreateClientConVar("cl_covercamera", '1', true) end if not ConVarExists("cl_covertext") then CreateClientConVar("cl_covertext", '1', true) end if not ConVarExists("cl_coverauto") then CreateClientConVar("cl_coverauto", '0', true) end timevar=string.ToMinutesSeconds(0) net.Receive( "updateTimer", function( len, pl ) timervar=net.ReadString() end) hook.Add( "HUDShouldDraw", "HideHUD", function( name ) if ( hide[ name ] ) then return false end end ) function HUDPaint() surface.SetDrawColor( 255, 255, 255, 255 ) surface.SetMaterial( armormat ) -- If you use Material, cache it! surface.DrawTexturedRect( (ScrW()/2)-150,25, 300, 75 ) local w,h = draw.SimpleTextOutlined( timervar, "HudTimer", 900*( ScrW() / 1920),60*( ScrH() / 1080),Color(152,218,217),0,0,0.5,Color(150,150,150) ) if(client:Alive() && client:GetNWBool("inGame"))then --Player Portiat-- surface.SetDrawColor( 255, 255, 255, 255 ) surface.SetMaterial( playerportraitmat ) -- If you use Material, cache it! surface.DrawTexturedRect( 25*( ScrW() / 1920),25*( ScrH() / 1080), 200*( ScrW() / 1920) , 200*( ScrH() / 1080) ) ------------------ --Armor Bar-- surface.SetDrawColor( 255, 255, 255, 255 ) surface.SetMaterial( barbackgroundmat ) -- If you use Material, cache it! surface.DrawTexturedRect( 200*( ScrW() / 1920),88*( ScrH() / 1080), 200*( ScrW() / 1920), 49*( ScrH() / 1080) ) surface.SetDrawColor( 255, 255, 255, 255 ) surface.SetMaterial( barfillmat ) -- If you use Material, cache it! surface.DrawTexturedRect( 200*( ScrW() / 1920), 76*( ScrH() / 1080), ((200/client:GetNWInt("maxArmor"))*client:Armor())*( ScrW() / 1920), 75*( ScrH() / 1080) ) surface.SetMaterial( barmarkermat ) -- If you use Material, cache it! surface.DrawTexturedRect( 190*( ScrW() / 1920),93*( ScrH() / 1080), 35*( ScrW() / 1920), 35*( ScrH() / 1080) ) surface.SetDrawColor( 255, 255, 255, 255 ) surface.SetMaterial( armormat ) -- If you use Material, cache it! surface.DrawTexturedRect( 198*( ScrW() / 1920),65*( ScrH() / 1080), 200*( ScrW() / 1920), 45*( ScrH() / 1080) ) surface.SetDrawColor( 255, 255, 255, 255 ) if(client:Armor()>client:GetNWInt("maxArmor")/2)then local w,h = draw.SimpleTextOutlined( "Armor", "HudFont1", 245*( ScrW() / 1920),70*( ScrH() / 1080),Color(152,218,217),0,0,0.5,Color(150,150,150) ) elseif(client:Armor()>client:GetNWInt("maxArmor")/3)then local w,h = draw.SimpleTextOutlined( "Armor", "HudFont1", 245*( ScrW() / 1920),70*( ScrH() / 1080),Color(225,225,0),0,0,0.5,Color(150,150,150) ) else local w,h = draw.SimpleTextOutlined( "Armor", "HudFont1", 245*( ScrW() / 1920),70*( ScrH() / 1080),Color(152,0,0),0,0,0.5,Color(150,150,150) ) end ------------ -------------- --Health Bar-- surface.SetDrawColor( 255, 255, 255, 255 ) surface.SetMaterial( barbackgroundmat ) -- If you use Material, cache it! surface.DrawTexturedRect( 250*( ScrW() / 1920),168*( ScrH() / 1080), 200*( ScrW() / 1920), 49*( ScrH() / 1080) ) surface.SetDrawColor( 255, 255, 255, 255 ) surface.SetMaterial( barfillmat ) -- If you use Material, cache it! surface.DrawTexturedRect( 250*( ScrW() / 1920), 156*( ScrH() / 1080), ((200/client:GetMaxHealth())*client:Health())*( ScrW() / 1920), 75*( ScrH() / 1080) ) surface.SetMaterial( barmarkermat ) -- If you use Material, cache it! surface.DrawTexturedRect( 240*( ScrW() / 1920),173*( ScrH() / 1080), 35*( ScrW() / 1920), 35*( ScrH() / 1080) ) surface.SetDrawColor( 255, 255, 255, 255 ) surface.SetMaterial( armormat ) -- If you use Material, cache it! surface.DrawTexturedRect( 220*( ScrW() / 1920),145*( ScrH() / 1080), 240*( ScrW() / 1920), 45*( ScrH() / 1080) ) surface.SetDrawColor( 255, 255, 255, 255 ) if(client:Health()>client:GetMaxHealth()/2)then local w,h = draw.SimpleTextOutlined( "Health", "HudFont1", 285*( ScrW() / 1920),150*( ScrH() / 1080),Color(152,218,217),0,0,0.5,Color(150,150,150) ) elseif(client:Health()>client:GetMaxHealth()/3)then local w,h = draw.SimpleTextOutlined( "Health", "HudFont1", 285*( ScrW() / 1920),150*( ScrH() / 1080),Color(225,225,0),0,0,0.5,Color(150,150,150) ) else local w,h = draw.SimpleTextOutlined( "Health", "HudFont1", 285*( ScrW() / 1920),150*( ScrH() / 1080),Color(152,0,0),0,0,0.5,Color(150,150,150) ) end ------------ ------------ --Health Bar-- surface.SetDrawColor( 255, 255, 255, 255 ) surface.SetMaterial( barbackgroundmat ) -- If you use Material, cache it! surface.DrawTexturedRect( 50*( ScrW() / 1920),238*( ScrH() / 1080), 400*( ScrW() / 1920), 49*( ScrH() / 1080) ) surface.SetDrawColor( 255, 255, 255, 255 ) surface.SetMaterial( barfillmat ) -- If you use Material, cache it! surface.DrawTexturedRect( 50*( ScrW() / 1920), 226*( ScrH() / 1080), ((400/client:GetNWInt("maxStamina"))*client:GetNWInt("curStamina"))*( ScrW() / 1920), 75*( ScrH() / 1080) ) surface.SetMaterial( barmarkermat ) -- If you use Material, cache it! surface.DrawTexturedRect( 40*( ScrW() / 1920),243*( ScrH() / 1080), 35*( ScrW() / 1920), 35*( ScrH() / 1080) ) surface.SetDrawColor( 255, 255, 255, 255 ) surface.SetMaterial( armormat ) -- If you use Material, cache it! surface.DrawTexturedRect( 125*( ScrW() / 1920),215*( ScrH() / 1080), 240*( ScrW() / 1920), 45*( ScrH() / 1080) ) surface.SetDrawColor( 255, 255, 255, 255 ) if(client:GetNWInt("curStamina")>client:GetNWInt("maxStamina")/2)then local w,h = draw.SimpleTextOutlined( "Energy", "HudFont1", 175*( ScrW() / 1920),220*( ScrH() / 1080),Color(152,218,217),0,0,0.5,Color(150,150,150) ) elseif(client:GetNWInt("curStamina")>client:GetNWInt("maxStamina")/3)then local w,h = draw.SimpleTextOutlined( "Energy", "HudFont1", 175*( ScrW() / 1920),220*( ScrH() / 1080),Color(225,225,0)
[QUOTE=DamienTehDemo;48923801][CODE] -SNIP- [/CODE][/QUOTE] If you are going to give us the entire file post it on paste bin so it at least has line numbers.
Did you not read Neth's post? client=LocalPlayer() 'Altho symptome seems like you are applying a variable to localplayer before he loads.'
IIRC LocalPlayer() returns nil until after InitPostEntity is called, so you'll have to wait until that hook is called to assign/do anything with LocalPlayer().
[QUOTE=Melted Bu11et;48925641]IIRC LocalPlayer() returns nil until after InitPostEntity is called, so you'll have to wait until that hook is called to assign/do anything with LocalPlayer().[/QUOTE] I went to bed but yeah, was gonna say i found out i was assignning the variable "client" before LocalPlayer() could be called. It works perfectly now :)
Sorry, you need to Log In to post a reply to this thread.