Иконка ресурса

FREE FreeMoneyTimer : 1.1.0 1.1.0

Нет прав для скачивания
C#:
/*
* 
* Copyright © 2025 headtapper
* 
* You may not copy, modify, share, distribute, publish, or sell copies of this software.
* 
* You may use this plugin for personal use on your own Rust server if you downloaded it from https://codefling.com.
* 
* You may not use components of the software's code base for any other purpose.
* 
*/

using System;
using System.Collections.Generic;
using Oxide.Core;
using Oxide.Core.Plugins;

namespace Oxide.Plugins
{
	[Info("FreeMoneyTimer", "headtapper", "1.1.0")]
	[Description("Give money to players with a configurable timer and when they first spawn.")]

	public class FreeMoneyTimer : RustPlugin
	{
		#region Configuration

		private PluginConfig config;

		private class PluginConfig
		{
			public int AmountToGiveOnFirstSpawn { get; set; }
			public int AmountToGiveOnTimer { get; set; }
			public int TimerInSeconds { get; set; }
			public bool SendMessageToPlayer { get; set; }
			public string CurrencySymbol { get; set; }
			public string CurrencySymbolPlacement { get; set; }
			public bool UseTCBankSupport { get; set; }
            public bool UseEconomicsSupport { get; set; }
            public bool UseServerRewardsSupport { get; set; }
        }

		private PluginConfig GetDeafaultConfigValues()
		{
			return new PluginConfig
			{
				AmountToGiveOnFirstSpawn = 20,
				AmountToGiveOnTimer = 10,
				TimerInSeconds = 1800,
				SendMessageToPlayer = true,
				CurrencySymbol = "$",
				CurrencySymbolPlacement = "left",
				UseTCBankSupport = true,
				UseEconomicsSupport = false,
                UseServerRewardsSupport = false
            };
		}

		protected override void LoadDefaultConfig()
		{
			config = GetDeafaultConfigValues();
			SaveConfig();
		}

		protected override void LoadConfig()
		{
			try
			{
				base.LoadConfig();
				config = Config.ReadObject<PluginConfig>();
				SaveConfig();
			}
			catch (Exception ex)
			{
				LoadDefaultConfig();
			}
		}

		private void SaveConfig() => Config.WriteObject(config, true);

		#endregion

		#region Localization

		protected override void LoadDefaultMessages()
		{
			lang.RegisterMessages(new Dictionary<string, string>
			{
				["RewardMessage"] = "Thanks for playing! Enjoy {0} on us.",
			}, this);
		}

		#endregion

		#region Initialization

		[PluginReference]
		private Plugin TCBank;

        [PluginReference]
        private Plugin Economics;

        [PluginReference]
        private Plugin ServerRewards;

        private const string UsePluginPermission = "freemoneytimer.use";

		private void Init()
		{
			permission.RegisterPermission(UsePluginPermission, this);

			StartRewardTimer();
		}

		#endregion

		#region Hooks

		private void OnPlayerSpawn(BasePlayer player)
		{
			timer.Once(5.0f, () =>
			{
                if (config.UseTCBankSupport)
					TCBank.Call("AddToWallet", player.UserIDString, config.AmountToGiveOnFirstSpawn);
                if (config.UseEconomicsSupport)
                    Economics.Call<bool>("Deposit", player.UserIDString, (double)config.AmountToGiveOnFirstSpawn);
                if (config.UseServerRewardsSupport)
                    ServerRewards.Call("AddPoints", player.UserIDString, config.AmountToGiveOnFirstSpawn);
            });
		}

		#endregion

		#region Functions

		private void TimerPay(BasePlayer player)
		{
			if (player == null) return;

			if (config.UseTCBankSupport)
			{
                if ((bool)TCBank.Call("AddToWallet", player.UserIDString, config.AmountToGiveOnTimer))
                    player.ChatMessage(string.Format(lang.GetMessage("RewardMessage", this, player.UserIDString), FormatCurrencyValue(config.AmountToGiveOnTimer)));
            }
			if (config.UseEconomicsSupport)
			{
                Economics.Call<bool>("Deposit", player.UserIDString, (double)config.AmountToGiveOnTimer);
                player.ChatMessage(string.Format(lang.GetMessage("RewardMessage", this, player.UserIDString), FormatCurrencyValue(config.AmountToGiveOnTimer)));
            }
            if (config.UseServerRewardsSupport)
            {
                ServerRewards.Call("AddPoints", player.UserIDString, config.AmountToGiveOnTimer);
                player.ChatMessage(string.Format(lang.GetMessage("RewardMessage", this, player.UserIDString), FormatCurrencyValue(config.AmountToGiveOnTimer)));
            }
        }

		private void StartRewardTimer()
		{
			timer.Every((float)config.TimerInSeconds, () =>
			{
                foreach (BasePlayer player in BasePlayer.activePlayerList)
                {
                    if (permission.UserHasPermission(player.UserIDString, UsePluginPermission))
                        TimerPay(player);
                }
            });
		}

		private string FormatCurrencyValue(int amount)
		{
			string formattedAmount = $"{config.CurrencySymbol}{amount}";
			if (config.CurrencySymbol.ToLower() == "right")
				formattedAmount = $"{amount}{config.CurrencySymbol}";
			return formattedAmount;
		}

		#endregion
	}
}

Автор
15FPS
Скачиваний
0
Просмотры
1
Первый выпуск
Обновление
Оценка
0.00 звёзд 0 оценок
Сверху