inventory problem | DARKRP

Hello i am getting this In my Console:

[ERROR] gamemodes/darkrp/gamemode/modules/kinventory/cl_init.lua:254: ‘<eof>’ expected near ‘end’

  1. unknown - gamemodes/darkrp/gamemode/modules/kinventory/cl_init.lua:0

And this is my Lua File


local Tag = "KInv"
local localply = LocalPlayer()

KInvC = {}

KInv_ClientData = KInv_ClientData or {}
net.Receive( Tag .. "_SyncItems", function( len )
	local data = net.ReadTable()
	KInv_ClientData = data
end)

net.Receive( Tag .. "_SyncItemsEmpty", function( len )
	KInv_ClientData = {}
end)

local function addButton( item, am, pnl )
	local localTbl = KInvItems[ item ]
	local mdl = localTbl.Model
	
	local btn = vgui.Create( "SpawnIcon" )
	btn:SetSize( 64, 64 )
	btn:InvalidateLayout()
	
	btn.PaintOver = function() end
	
	btn.Paint = function( self, w, h )
		local color = Color( 150, 150, 150 )
		local c = Color( 150, 150, 150 )

		if ( !self.m_bBackground ) then return end
		
		if ( self.Depressed || self:IsSelected() ) then
			color = Color( c.r + 30, c.g + 30, c.b + 30 )
		end	
		
		if ( self.Hovered ) then
			if ( self.Depressed || self:IsSelected() ) then
				color = Color( c.r + 30, c.g + 30, c.b + 30 )
			else
				color = Color( c.r - 30, c.g - 30, c.b - 30 )
			end		
		end
				
		KDraw.drawFancyBox( 0, 0, 0, w, h, color )
	end
	
	if localTbl.Pic == true then
		local texture = surface.GetTextureID( "vgui/entities/" .. item )
		mdl = "models/props_c17/metalladder003.mdl"
		local oldPaint = btn.Paint
		btn.Paint = function( s, w, h )	
			oldPaint( s, w, h )
			surface.SetDrawColor( 255, 255, 255, 255 )
			surface.SetTexture( texture )
			surface.DrawTexturedRect( 0, 0, w, h )
		end 
	end

	btn.OnCursorEntered = function()
		if localTbl.Pic then
			pnl:UpdatePriceInfo( am, localTbl.Name, localTbl.Weight, mdl, item, true )
		else
			pnl:UpdatePriceInfo( am, localTbl.Name, localTbl.Weight, mdl )
		end
	end
		
	btn.OnCursorExited = function()
		pnl:CancelPriceInfo()
	end
	
	btn.DoClick = function()
		local menu = DermaMenu()
		local isammo = localTbl.Ammo or false
		menu:AddOption( "Drop", function()
			net.Start( Tag .. "_InvAction" )
				net.WriteTable( { Action = "drop", Item = item, IsWep = localTbl.Weapon, IsAmmo = isammo } )
			net.SendToServer()
			timer.Simple( 2, function()
				if pnl and pnl:IsValid() then
					pnl:Update()
					pnl:CancelPriceInfo()
				end
			end )
		end ):SetImage( "icon16/package_go.png" )
		
		if localTbl.Weapon or isammo == true then
			menu:AddOption( "Equip", function()
				net.Start( Tag .. "_InvAction" )
					net.WriteTable( { Action = "equip", Item = item } )
				net.SendToServer()
				timer.Simple( 2, function()
					if pnl and pnl:IsValid() then
						pnl:Update()
						pnl:CancelPriceInfo()
					end
				end )					
			end ):SetImage( "icon16/gun.png" )
		end
		
		menu:AddOption( "Remove one", function()
			net.Start( Tag .. "_InvAction" )
				net.WriteTable( { Action = "remove", Item = item } )
			net.SendToServer()
			timer.Simple( 2, function()
				if pnl and pnl:IsValid() then
					pnl:Update()
					pnl:CancelPriceInfo()
				end
			end )		
		end ):SetImage( "icon16/delete.png" )		

		menu:AddOption( "Remove Amount...", function()
			Derma_StringRequest( 
				"Remove item", "Enter the desired amount of items you want to remove", "1",
				function( a )
					a = tonumber( a )
					if type( a ) != "number" then
						Derma_Message( "Invalid number format!", "Error", "Try Again" )
					elseif a < 1 then
						Derma_Message( "You can't remove that amount", "Error", "Try Again" )
					else
						net.Start( Tag .. "_InvAction" )
							net.WriteTable( { Action = "remove", Item = item, Am = a } )
						net.SendToServer()
						timer.Simple( 2, function()
							if pnl and pnl:IsValid() then
								pnl:Update()
								pnl:CancelPriceInfo()
							end
						end )		
					end
				end )
		end ):SetImage( "icon16/delete.png" )		

		menu:AddOption( "Remove All", function()
			net.Start( Tag .. "_InvAction" )
				net.WriteTable( { Action = "remove", Item = item, Am = am } )
			net.SendToServer()
			timer.Simple( 2, function()
				if pnl and pnl:IsValid() then
					pnl:Update()
					pnl:CancelPriceInfo()
				end
			end )		
		end ):SetImage( "icon16/delete.png" )	
		
		menu:AddOption( "Close", function()
		end ):SetImage( "icon16/book_delete.png" )	
		
		menu:Open()		
	end
	
	btn:SetModel( mdl )
	btn:SetToolTip()
	
	return btn
end

function KInvC.InvTab()
	local maxweightallowed = 100
--	if LocalPlayer():IsVIP() then
	--	maxweightallowed = 250
	end
	
	local InvPanel = vgui.Create( "DPanel" )
	InvPanel.Paint = function( s, w, h ) 
		draw.RoundedBox( 0, 0, 0, w, 84, Color( 55, 55, 55 ) )
		draw.DrawText( "*To pick up items press ALT + E on them, if that doesn't work, type !invhelp in chat", "K_Tre18", w - 10, 84 - 20, Color( 210, 210, 210 ), 2 )
	end
	
	InvPanel.InfoIcon = vgui.Create( "SpawnIcon", InvPanel )
	InvPanel.InfoIcon:SetPos( 4, 5 )
	InvPanel.InfoIcon:SetSize( 64, 64 )
	InvPanel.InfoIcon:SetModel( "models/props_borealis/bluebarrel001.mdl" )
	InvPanel.InfoIcon:SetToolTip()
	InvPanel.InfoIcon.OnMousePressed = function() return false end
	InvPanel.InfoIcon.PaintOver = function() return false end 
	InvPanel.InfoIcon:SetVisible( false )
	
	InvPanel.InfoName = vgui.Create( "DLabel", InvPanel )
	InvPanel.InfoName:SetPos( 90, 10 )
	InvPanel.InfoName:SetColor( Color( 255, 255, 255 ) )
	InvPanel.InfoName:SetFont( "K_Tre22" )
	InvPanel.InfoName:SetText( "Please select an item from the list below." )
	InvPanel.InfoName:SizeToContents()
	
	InvPanel.InfoWeight = vgui.Create( "DLabel", InvPanel )
	InvPanel.InfoWeight:SetPos( 90, 38 )
	InvPanel.InfoWeight:SetColor( Color( 192, 255, 192 ) )
	InvPanel.InfoWeight:SetFont( "K_Tre22" )
	local ttl = KInv_ClientData[ "weight" ] or 0
	InvPanel.InfoWeight:SetText( "Your total weight: " .. ttl .. " / " .. maxweightallowed .. " Kg" )
	InvPanel.InfoWeight:SizeToContents()
	
	function InvPanel:UpdatePriceInfo( amount, name, weight, Model, ent, bool )
		InvPanel.InfoIcon:SetModel( Model )
		if ent and bool == true then
			local texture = surface.GetTextureID( "vgui/entities/" .. ent )
			InvPanel.InfoIcon.Paint = function( s, w, h )
				surface.SetDrawColor( 255, 255, 255, 255 )
				surface.SetTexture( texture )
				surface.DrawTexturedRect( 0, 0, w, h )
			end 		
		else
			InvPanel.InfoIcon.Paint = function( s, w, h ) end
		end
		InvPanel.InfoIcon:SetVisible( true )
		InvPanel.InfoName:SetText( name .. " ( x" .. amount .. " )" )
		InvPanel.InfoName:SizeToContents()
	
		InvPanel.InfoWeight:SetText( "Item weight: " .. weight .. " Kg" )
		InvPanel.InfoWeight:SizeToContents()
	end
	
	function InvPanel:CancelPriceInfo()
		InvPanel.InfoIcon:SetVisible( false )
		InvPanel.InfoName:SetText( "Please select an item from the list below." )
		InvPanel.InfoName:SizeToContents()
	
		InvPanel.InfoWeight:SetColor( Color( 192, 255, 192 ) )
		local ttl = KInv_ClientData[ "weight" ] or 0
		InvPanel.InfoWeight:SetText( "Your total weight: " .. ttl .. " / " .. maxweightallowed .. " Kg" )
		InvPanel.InfoWeight:SizeToContents()
	end
	
	InvList = vgui.Create( "DPanelList", InvPanel )
	InvList:SetPos( 0, 89 )
	InvList:SetSize( 900 - 247, 600 - 187 )
	InvList:EnableVerticalScrollbar( true )
	InvList:EnableHorizontal(true)
	InvList:SetSpacing(9)
	InvList:SetPadding(9)
	InvList.Paint = function( s, w, h )
		KDraw.drawFancyBox( 0, 0, 0, w, h, Color( 35, 35, 35 ) )
	end
	
	function InvPanel:Update()	
		maxweightallowed = 100
		if LocalPlayer():IsVIP() then
			maxweightallowed = 250
		end	
		InvList:Clear()
		for k, v in pairs( KInv_ClientData ) do
			if k == "weight" then continue end
			local icon = addButton( k, v, InvPanel )
			InvList:AddItem( icon )
		end	
		InvPanel:CancelPriceInfo()
	end
	
	InvPanel:Update()
	
	return InvPanel
end

How to Fix this ?

Why are you modifying the base gamemode for DarkRP?
Also read the error, you are ending a function that doesn’t exist. So you are ending nothing. Read the code yourself and see what you are ending and when.

The error suggests one end too many; proper tabbing would help and also getting rid of making functions that aren’t necessary will also help…

Additionally, just because we have several ways to define functions doesn’t mean all methods need to be used…


function blah:blah( ) ... end
blah["blah"] = function( ) ... end
blah.blah = function( ) ... end
function blah.blah( self ) ... end	

Using name = function( ) … end is useful when you need to create a dynamically named function such as Set* or Get* functions… You can’t do


function blah["blah"]( ) ... end	

In my opinion it appears sloppy that one naming convention isn’t used through-out but different ones are used even when unnecessary…

A few examples of the unnecessary


menu:AddOption( "Close", function()
			end ):SetImage( "icon16/book_delete.png" )
	

Anyways, removing the last end removes the error but without knowing if the correct function is being ended means going through the code and re-tabbing…

The line with Derma_StringRequest( shows a gap at the associated ) because the end ends the function within the function call; I’d recommend moving ) to the next line so it fills the gap.

I’d change: menu:AddOption( “Close”, function()
end ):SetImage( “icon16/book_delete.png” )

or route it to an empty function reference ( Good idea to put in my dev-base, something like angle_zero, vector_origin, function_null / null_function / NULL_FUNC / FUNC_NULL / or whatever… )…

The issue is with these lines:


	function KInvC.InvTab()
		local maxweightallowed = 100
	--	if LocalPlayer():IsVIP() then
		--	maxweightallowed = 250
		end

You commented out the if statement, but not the end so removing the last end would cause function KInvC.InvTab() to do absolutely nothing ( aside from declaring a local value, then ending thus closing the scope where it could be used )…

Anyways, hopefully this helps; also don’t modify core files, use an addon ( which can overwrite the file if you use the same filename and path ).