PLUGIN.Name = "Tool Trust"; -- What is the plugin name
PLUGIN.Author = "LuaBanana"; -- Author of the plugin
PLUGIN.Description = "Toolgun permissions, as well as physgun ban."; -- The description or purpose of the plugin

function Tooltrust_Give(ply)

	if(tostring(GetPlayerField(ply, "tooltrust")) == "1") then
	
		ply:Give("gmod_tool");
		
	end
	
	if(tostring(GetPlayerField(ply, "phystrust")) == "1") then
	
		ply:Give("weapon_physgun");
	
	end
	
	if(tostring(GetPlayerField(ply, "gravtrust")) == "1") then
	
		ply:Give("weapon_physcannon");
		
	end
	
end

function Admin_Tooltrust(ply, cmd, args)

	if(#args != 2) then
	
		SendChat( ply, "Invalid number of arguments! ( rp_admin tooltrust \"name\" 1/0 )" );
		return;

	end
	
	local target = FindPlayer(args[1])
	
	if(target != nil and target:IsValid() and target:IsPlayer()) then
		-- klol
	else
		SendChat( ply, "Target not found!" );
		return;
	end
	
	if(args[2] == "1") then
	
		SetPlayerField(target, "tooltrust", 1);
		target:Give("gmod_tool");
		SendChat( target, "You have been given tooltrust by " .. ply:Name() );
		SendChat( ply, target:Name() .. " has been given tooltrust" );
		
	elseif(args[2] == "0") then
	
		SetPlayerField(target, "tooltrust", 0);
		target:StripWeapon("gmod_tool");
		SendChat( target, "Your tooltrust has been removed by " .. ply:Name() );
		SendChat( ply, target:Name() .. "'s tooltrust has been removed" );
		
	end
	
end

function Admin_Phystrust(ply, cmd, args)

	if(#args != 2) then
	
		SendChat( ply, "Invalid number of arguments! ( rp_admin phystrust \"name\" 1/0 )" );
		return;

	end
	
	local target = FindPlayer(args[1])
	
	if(target != nil and target:IsValid() and target:IsPlayer()) then
		-- klol
	else
		SendChat( ply, "Target not found!" );
		return;
	end
	
	if(args[2] == "0") then
	
		SetPlayerField(target, "phystrust", 0);
		target:StripWeapon("weapon_physgun");
		SendChat( target, "You have been banned from the physics gun by " .. ply:Name());
		SendChat( ply, target:Name() .. " has been banned from the physics gun" );
		
	elseif(args[2] == "1") then
	
		SetPlayerField(target, "phystrust", 1);
		target:Give("weapon_physgun");
		SendChat( target, "You have been given the physgun by " .. ply:Name() );
		SendChat( ply, target:Name() .. " has been given a physgun" );
		
	end
	
end

function Admin_Gravtrust(ply, cmd, args)

	if(#args != 2) then
	
		SendChat( ply, "Invalid number of arguments! ( rp_admin gravtrust \"name\" 1/0 )" );
		return;

	end
	
	local target = FindPlayer(args[1])
	
	if(target != nil and target:IsValid() and target:IsPlayer()) then
		-- klol
	else
		SendChat( ply, "Target not found!" );
		return;
	end
	
	if(args[2] == "0") then
	
		SetPlayerField(target, "gravtrust", 0);
		target:StripWeapon("weapon_physcannon");
		SendChat( target, "You have been banned from the gravity gun by " .. ply:Name());
		SendChat( ply, target:Name() .. " has been banned from the gravity gun" );
		
	elseif(args[2] == "1") then
	
		SetPlayerField(target, "gravtrust", 1);
		target:Give("weapon_physcannon");
		SendChat( target, "You have been given the gravgun by " .. ply:Name() );
		SendChat( ply, target:Name() .. " has been given a gravgun" );
		
	end
	
end

function Admin_Proptrust(ply, cmd, args)

	if(#args != 2) then
	
		SendChat( ply, "Invalid number of arguments! ( rp_admin proptrust \"name\" 1/0 )" );
		return;

	end
	
	local target = FindPlayer(args[1])
	
	if(target != nil and target:IsValid() and target:IsPlayer()) then
		-- klol
	else
		SendChat( ply, "Target not found!" );
		return;
	end
	
	if(args[2] == "0") then
	
		SetPlayerField(target, "proptrust", 0);
		SendChat( target, "You have been banned from spawning props by " .. ply:Name());
		SendChat( ply, target:Name() .. " has been banned from spawning props" );
		
	elseif(args[2] == "1") then
	
		SetPlayerField(target, "proptrust", 1);
		SendChat( target, "You have been allowed to spawn props by " .. ply:Name() );
		SendChat( ply, target:Name() .. " has been allowed to spawn props" );
		
	end
	
end

	
function PLUGIN.Init()

	ConVars[ "Default_Tooltrust" ] = "0"; -- Are players allowed to have the toolgun when they first start.
	ConVars[ "Default_Gravtrust" ] = "0"; -- Are players allowed to have the gravgun when they first start.
	ConVars[ "Default_Phystrust" ] = "0"; -- Are players allowed to have the physgun when they first start.
	ConVars[ "Default_Proptrust" ] = "0"; -- Are players allowed to spawn props when they first start.
	
	AddDataField( 1, "tooltrust", ConVars[ "Default_Tooltrust" ] ); -- Is the player allowed to have the toolgun
	AddDataField( 1, "gravtrust", ConVars[ "Default_Gravtrust" ] ); -- Is the player allowed to have the gravity gun
	AddDataField( 1, "phystrust", ConVars[ "Default_Phystrust" ] ); -- Is the player allowed to have the physics gun
	AddDataField( 1, "proptrust", ConVars[ "Default_Proptrust" ] ); -- Is the player allowed to spawn props
	
	AddHook("PlayerSpawn", "tooltrust_give", Tooltrust_Give);
	
	AdminCommand( "tooltrust", Admin_Tooltrust, "Change someones tooltrust", true, true, false );
	AdminCommand( "gravtrust", Admin_Gravtrust, "Change someones gravtrust", true, true, false );
	AdminCommand( "phystrust", Admin_Phystrust, "Change someones phystrust", true, true, false );
	AdminCommand( "proptrust", Admin_Proptrust, "Change someones proptrust", true, true, false );
	
end