• Basic Gamemode Problem
    4 replies, posted
I'm trying to create a very basic gamemode deriving off sandbox in gmod 13. This gamemode is meant to keep all the functions, weapons and spawn menu from the sandbox gamemode and all I've tried to add is a small derma box and the ability to switch a variable called: "CurrentBuildMode". When I start the game I have no console errors and the derma box appears, but I spawn with no weapons, cannot access the spawn menu and can't use the concommand "ChangeBuildMode" to switch the variable in console. init.lua: [lua]AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include( "shared.lua" ) DeriveGamemode( "sandbox" ) local CurrentBuildMode = 1 print(CurrentBuildMode) function ChangeBuildMode if CurrentBuildMode == 1 CurrentBuildMode = 0 else CurrentBuildMode = 1 end end concommand.Add( "ChangeBuildMode", ChangeBuildMode )[/lua] cl_init.lua [lua]include( "shared.lua" ) DeriveGamemode( "sandbox" ) local TestingForm = vgui.Create( "DForm", DermaPanel ) TestingForm:SetPos( 1060, 760 ) TestingForm:SetSize( 350, 60 ) TestingForm:SetSpacing( 10 ) TestingForm:SetName( "Current Sandbox Mode:" ) TestingForm.Paint = function() surface.SetDrawColor( 255, 100, 15, 255 ) -- I draw a box here to show where the form is outlined surface.DrawOutlinedRect( 0, 0, TestingForm:GetWide(), TestingForm:GetTall() ) end local InfoPanel = vgui.Create( "DPanel", TestingForm ) InfoPanel:SetPos( 8 , 25 ) InfoPanel:SetSize( 342, 40) InfoPanel.Paint = function() surface.SetDrawColor( 50, 50, 50, 255 ) surface.DrawRect( 0, 0, InfoPanel:GetWide(), InfoPanel:GetTall() ) end local BuildText = vgui.Create( "DLabel", InfoPanel ) BuildText:SetPos(8, 8) BuildText:SetColor(Color(255,255,255,255)) BuildText:SetFont("default") BuildText:SetText( "Build Mode" ) BuildText:SizeToContents() local instructiontext = vgui.Create( "DLabel", InfoPanel ) instructiontext:SetPos( 8, 25) instructiontext:SetColor(Color(255,255,255,255)) instructiontext:SetFont("default") instructiontext:SetText( "Press Alt (Walk) to switch" ) instructiontext:SizeToContents()[/lua] shared.lua [lua]DeriveGamemode( "sandbox" ) GM.Name = "Test" GM.Author = "Zyler" GM.Email = "N/A" GM.Website = "N/A" function GM:Initialize() self.BaseClass.Initialize( self ) end[/lua]
Why are you deriving the gamemode in both shared.lua, init.lua and cl_init.lua? You just have to derive it in shared.lua. Also, it'd be of a lot more help if you could post the errors you are getting.
[QUOTE=Jocken300;37847897]Why are you deriving the gamemode in both shared.lua, init.lua and cl_init.lua? You just have to derive it in shared.lua. Also, it'd be of a lot more help if you could post the errors you are getting.[/QUOTE] [QUOTE=Zyler] When I start the game I have no console errors and the derma box appears, but I spawn with no weapons, cannot access the spawn menu and can't use the concommand "ChangeBuildMode" to switch the variable in console. [/QUOTE] I'm sorry if I wasn't very clear before, I was typing the op in a hurry. I'm not getting any console errors, but when I start the game I spawn with no weapons, cannot access the spawn menu and can't use the concommand I set up. This is happening even though I derived from sandbox in order to have these things (specifically the spawn menu, weapons etc.). I should add though that I was able to derive from sandbox and do these things before I added in the concommand and it's linking function into the code, so it's unlikely that that is the problem. I've fixed what you said anyway since it's unnecessary to have the deriving code in every lua file. It had no effect and I don't think having unnecessary code (that doesn't actually do anything) is the problem here. This is a problem with the Gmod 13 beta. Has something changed about concommands that I don't know about? Edit: And for the people who rated me dumb, would you care to elaborate on what I did to deserve that rating? Any help would be appreciated. Edit2: After testing a couple of times after changing the script based on Jocken's suggestion and running it with a fresh install (no addons etc). I've found some errors that weren't there before: [code][gamemodes/test/gamemode/init.lua:10] '(' expected near 'if' [cpp] Couldn't Load Init Script: 'test/gamemode/init.lua' E[/code] and [code]Couldn't include file 'shared.lua' (File not found) (@gamemodes/test/gamemode/cl_init.lua (line 1)) D[/code] I definitely have "shared.lua" located in that folder, so what's the problem?
init.lua [lua]function ChangeBuildMode(p) // if !p:IsAdmin() then return end // enable this so only admins and super admins can run the cmd if CurrentBuildMode == 1 then CurrentBuildMode = 0 print("Disabled build mode") elseif CurrentBuildMode == 0 then CurrentBuildMode = 1 print("Enabled build mode") end end concommand.Add( "ChangeBuildMode", ChangeBuildMode )[/lua] Shared or cl_init won't be added cause init is causing the error, testing in a dedicated server rather then single player if you have no clue on what you're doing also look up on the pil it'll help you alot. [URL="http://www.lua.org/manual/5.1/"]http://www.lua.org/manual/5.1/[/URL] [URL="http://www.lua.org/pil/"]http://www.lua.org/pil/[/URL]
Thanks, fixed.
Sorry, you need to Log In to post a reply to this thread.