[FREE SCRIPT] Mayor Toolkit/Treasury Base (DarkRP)

If anyone wants it, here’s a basic derma-based system that allows the Mayor to make various changes and manage the funds of a treasury.

-- For non-commercial use only. Do not sell.

-- Coded by Toastibite for Facepunch.

include( "shared.lua" ) 

local rp_tax = 0 
local treasury = 0
local rp_taxmin = 0

function toolkit( ply, text, public ) 

if ply:Team == TEAM_MAYOR then 
	  if (string.sub(text, 1, 6) == "!mayor") then 
		local frame = vgui.Create( "DFrame", toolkit ) 
		frame:SetSize( 500, 500 ) 
		frame:SetTitle( "Mayor Toolkit" ) 
		frame:SetDraggable( false ) 
		frame:ShowCloseButton( true ) 
		local label = vgui.Create( "DLabel", frame ) 
		label:AlignTop( 10 ) 
		label:SetText( "What would you like to do today, Mr. Mayor?" ) 
		label:SetFont( "HUDNumber5" ) 
		local b1 = vgui.Create( "DButton", frame ) 
		b1:AlignTop( 20 ) 
		b1:AlignLeft( 10 ) 
		b1:SetText( "Enable Taxes [$1000]" ) 
		b1.DoClick = function()
			if treasury < 1000
				ply:PrintMessage( "There are not enough treasury funds to perform this action.")
				rp_tax = 1 
				treasury - 1000
				ply:PrintMessage( "Taxes have been enabled. Please set the tax rate." ) 
				local tax = vgui.Create( "DFrame" ) 
				tax:SetSize( 250, 250 ) 
				tax:SetTitle( "Mayor Toolkit" ) 
				tax:SetDraggable( false ) 
				tax:ShowCloseButton( true ) 
				local rate = vgui.Create( "DNumSlider", tax ) 
				rate:SetPos( 25,50 )
				rate:SetWide( 150 )
				rate:SetText( "Tax Rate" )
				rate:SetMin( 0 ) 
				rate:SetMax( 100 ) 
				rate:SetDecimals( 0 ) 
				rate:SetConVar( "rp_taxmin" ) 
		local b2 = vgui.Create( "DButton", toolkit ) 
		b1:AlignTop( 20 ) 
		b2:AlignLeft( 30 ) 
		b2:SetText( "Withdraw Treasury Funds [$500 Fee] " ) 
		b2.DoClick = function()
			ply:AddMoney( treasury ) 
			ply:AddMoney( -500 ) 
			if treasury = 0 then
				ply:PrintMessage( "The treasury is empty." ) 

function treasury( ply ) 
if ply:Team == TEAM_MAYOR then
	simple.Timer( 60, treasury + 500 ) 

function death( victim, weapon, killer ) 
	if victim:Team == TEAM_MAYOR then 
		PrintMessage( "The mayor has been killed by"..killer.."! He has received all the money in the treasury!" ) 
		killer:AddMoney( treasury )


hook.Add( "PlayerSay", "toolkit", toolkit );

To create your own functions, just make a new frame (copy/paste an existing frame and change its name) and add a button (same process). You can then script your own commands into the button.

There’s a few errors in that code I can spot straight away, first is that Player:Team returns a value as it’s a function, you’re attempting to use it like a variable, it needs to be;


You’re also using an assignment operator in an if statement, so you’ll get an error thrown in with that;

// Won't work, you're using an assignment operator for a relational check
if treasury = 0 then
    ply:PrintMessage( "The treasury is empty." ) 

// Change it to this;
if treasury == 0 then
    ply:PrintMessage( "The treasury is empty." ) 

Also, pretty sure it won’t work since you’ve named a function AND a variable the exact same thing (treasury). You’re also attempting to do this;

// Lua doesn't do this, I understand what you're trying to do, but Lua doesn't
treasury - 1000

// Needs to be;
treasury = treasury - 1000

The way you’re telling them to make a new frame as well is bad, don’t copy & paste to create a new frame, just extend the current frame and add another button.

Lastly, please don’t use generic naming for elements or objects, it doesn’t give you any indication as to what that element is for, and you need to look at all the code related to that element to actually know what it’s for, if you had called it something like btnEnableTaxes, it would be obvious what it does, it’s a button that enables taxes.


**Your frame will also open multiple times if they type the command in more than once, you’ve done no check to see if it’s already open.

Thanks for the feedback. I’m not really a Lua pro, so I appreciate the illumination of any issues I can work on.

Yeah, it’s all trial and error, but the best thing for you to do, is to launch either a local dedicated server using SteamCMD (Using SteamCMD for Garrysmod), or shove your lua file into either an addon in your local gmod installation, or in your autorun folder, so you can debug it locally, and see any errors it throws out.

Also, noticed something else, the GM.PlayerSay hook is serverside, so it won’t work the way you want it to, you’d need to hook it serverside, and then send a net message or something over to the client, telling them to open the menu.

Net Library Usage