Creating a changing var & Button do click custom job check!
6 replies, posted
So I am trying to create a bank robbery system. However, I want to create a variable called BankBalance that changes every 2 minutes by $3500. I have created an entity called Bank_ent. The code is :
Init.lua:
[CODE]AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( "shared.lua" )
function ENT:Initialize()
self:SetModel( "models/props/cs_assault/MoneyPallet.mdl" )
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)
local phys = self:GetPhysicsObject()
if phys:IsValid() then
phys:Wake()
end
end
util.AddNetworkString( "OpenBankMenu" )
function ENT:AcceptInput( name, activator, caller )
if name == "Use" and caller:IsPlayer() then
net.Start( "OpenBankMenu" )
net.Send( caller )
end
end[/CODE]
Cl_init.lua
[CODE]function ENT:Draw()
self:DrawModel()
end
local BankBalance = 1000
net.Receive( "OpenBankMenu", function()
local Background = vgui.Create( "DFrame" )
Background:SetTitle( "Bank Menu" )
Background:Center()
Background:SetSize( 300, 300 )
Background:SetDraggable( false )
Background:MakePopup( true )
Background:ShowCloseButton( true )
end)
local BalanceBut = vgui.Create( "DButton", Frame )
BalanceBut:SetText( "Bank Balance" )
BalanceBut:SetTextColor( Color( 255, 255, 255 ) )
BalanceBut:SetPos( 100, 100 )
BalanceBut:SetSize( 100, 30 )
BalanceBut.Paint = function( self, w, h )
draw.RoundedBox( 0, 0, 0, w, h, Color( 41, 128, 185, 250 ) )
end
BalanceBut.DoClick = function()
print("The Bank Balance is : $"..BankBalance)
end[/CODE]
shared.lua
[CODE]ENT.Type = "anim"
ENT.Base = "base_gmodentity"
ENT.PrintName = "Metro Bank"
ENT.Spawnable = true[/CODE]
So I am wanting the var BankBalance to change. I also want the var BankBalance to be used in a entity later be still always be the same as the one in here if that makes sense. Another thing I would like is to make it so there is a job check when the Button BalanceBut is clicked would I just do this like a ULX rank custom check but change where the ranks would go with jobs :
[CODE]customCheck = function(ply) return
table.HasValue({"TEAM_POLICE"}, ply:GetNWString("usergroup"))
end,
CustomCheckFailMsg = "You are not the correct job for this action!",[/CODE]
use timer.Create(). create a table with all the allowed jobs then do if ( not table[ ply:Team() ] ) then return end
Just do
[lua]
if not ply:Team() == TEAM_WHATEVER then return end
[/lua]
and you would want to network the variable if you want to make it serverside.
How would I make a variable that updates every so often. Would I have to make something in lua\autorun then make the bank entity in lua\entities then do something like
[CODE]include("lua\autorun\sv_bankent")[/CODE]
[editline]28th March 2016[/editline]
local var = 0
timer.Create( "changevar", 1, 0, function()
var = var + 1
end )
will add one to var every second, forever.
Thank you for that,
So would I just create it like a normal entity or would I have to create something in lua autorun ?
*bump*
Not sure what you mean by "something in lua autorun" but the way you have it now should work.
Sorry, you need to Log In to post a reply to this thread.