• Lua gamemode help!
    2 replies, posted
Gmod lua help! It may sound simple, but i can't wrap my head around it! I made a Derma with a button. I want the button to decrease my money ----SERVER SIDE---- and not clientside! How do i do this? Please respond. Some of my code ---------------> function.lua include( 'level_system.lua' ) include( 'class.lua' ) function AddLevelPlayer(ply) ply:TakeMoney(100) print("Added") end concommand.Add("add" , AddLevelPlayer) ------------------> money_system.lua local meta = FindMetaTable("Player") function meta:AddMoney(amount) local current_cash = self:GetMoney() self:SetMoney( current_cash + amount ) end function meta:SetMoney(amount) self:SetNetworkedInt( "Money", amount ) self:SaveMoney() end function meta:SaveMoney() local cash = self:GetMoney() self:SetPData("money", cash) end function meta:SaveMoneyTXT() file.Write(gmod.GetGamemode().Name .."/Money/".. string.gsub(self:SteamID(), ":", "_") ..".txt", self:GetMoneyString()) end function meta:TakeMoney(amount) self:AddMoney(-amount) end function meta:GetMoney() return self:GetNetworkedInt( "Money" ) end ------------------> menu.lua local hey = FindMetaTable( "Player" ) include( 'shared.lua' ) include( 'money_system.lua' ) include( 'level_system.lua' ) include( 'class.lua' ) include( 'function.lua' ) function ClassMenu() local ply = LocalPlayer() local Frame = vgui.Create( "DFrame" ) Frame:SetPos( 200, 200 ) Frame:SetSize( 450,400 ) Frame:SetTitle( "Choose Class: " ) Frame:SetVisible( true ) Frame:SetDraggable( true ) Frame:ShowCloseButton( true ) Frame:MakePopup() local Combo = vgui.Create("DComboBox", Frame) Combo:SetPos( 10,35 ) Combo:SetSize(100, 35) Combo:AddChoice( "Starter" ) Combo:AddChoice( "Beginner" ) local Slid = vgui.Create( "DNumSlider", Frame ) Slid:SetPos( 25,150 ) Slid:SetSize( 150, 100 ) Slid:SetText( "Skill count:" ) Slid:SetMin( 1 ) Slid:SetMax( 100 ) Slid:SetValue( 1 ) Slid:SetDecimals( 0 ) local But = vgui.Create( "DButton", Frame ) But:SetText( "Buy Skill Level" ) But:SetPos( 25, 100 ) But:SetSize( 150, 50 ) But.DoClick = function() hey:ConCommand("add") end end ---------------> As you can see i made a console command "add", wich should play the function called AddLevelPlayer in the function.lua... It did not work. Hope to get an answer! Thanks in advance!
Instead of hey:ConCommand("add") do RunConsoleCommand("add")
It takes some of my money, but they are returned after some time.. [editline]17th December 2012[/editline] Fixed it somehow, thanks anyway!
Sorry, you need to Log In to post a reply to this thread.