C#:
using System;
using Oxide.Game.Rust.Cui;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using Newtonsoft.Json;
using Oxide.Core;
using Oxide.Core.Plugins;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("Rate", "WOLF#4002", "0.0.1")]
public class WRate : RustPlugin
{
[PluginReference] Plugin ImageLibrary;
private Dictionary<ulong, PlayerRate> PlayerRates = new Dictionary<ulong, PlayerRate>();
private class PlayerRate
{
[JsonProperty("Name")]
public string DisplayName;
[JsonProperty("SteamID")]
public ulong SteamID;
[JsonProperty("Rates")]
public float Rates;
}
void ADDRate(BasePlayer player, float amount)
{
var data = PlayerRates[player.userID];
data.Rates = (data.Rates += amount);
OnServerSave();
}
void TAKERate(BasePlayer player, float amount)
{
var data = PlayerRates[player.userID];
data.Rates = (data.Rates -= amount);
OnServerSave();
}
float FINDRate(BasePlayer player)
{
var data = PlayerRates[player.userID];
return data.Rates;
}
void OnServerSave()
{
Oxide.Core.Interface.Oxide.DataFileSystem.WriteObject($"{Name}/{Title}", PlayerRates);
}
void OnServerInitialized()
{
foreach (BasePlayer player in BasePlayer.activePlayerList)
{
OnPlayerConnected(player);
}
}
void OnPlayerConnected(BasePlayer player)
{
if (!PlayerRates.ContainsKey(player.userID))
{
PlayerRate NewUser = new PlayerRate()
{
DisplayName = player.displayName,
SteamID = player.userID,
Rates = Settings.Rates,
};
PlayerRates.Add(player.userID, NewUser);
Oxide.Core.Interface.Oxide.DataFileSystem.WriteObject($"{Name}/{Title}", PlayerRates);
}
Oxide.Core.Interface.Oxide.DataFileSystem.WriteObject($"{Name}/{Title}", PlayerRates);
}
enum Types
{
Gather,
Loot,
PickUP,
Quarry,
Excavator,
}
int Converted(Types RateType, string Shortname, float Amount, BasePlayer player = null, String UserID = null)
{
var R = PlayerRates[player.userID];
float ConvertedAmount = Amount;
switch (RateType)
{
case Types.Gather:
{
ConvertedAmount = Amount * R.Rates;
break;
}
case Types.Loot:
{
ConvertedAmount = Amount * R.Rates;
break;
}
case Types.PickUP:
{
ConvertedAmount = Amount * R.Rates;
break;
}
}
return Convert.ToInt32(ConvertedAmount);
}
void OnLootEntity(BasePlayer player, BaseEntity entity)
{
if (entity == null) return;
LootContainer container = entity as LootContainer;
if (entity.net == null) return;
UInt64 NetID = entity.net.ID.Value;
if (LootersListCrateID.Contains(NetID)) return;
if (container == null)
{
if (!(entity is NPCPlayerCorpse)) return;
NPCPlayerCorpse corpse = (NPCPlayerCorpse)entity;
foreach (ItemContainer corpseContainer in corpse.containers)
{
foreach (Item item in corpseContainer.itemList)
item.amount = Converted(Types.Loot, item.info.shortname, item.amount, player);
}
}
else
{
foreach (Item item in container.inventory.itemList)
item.amount = Converted(Types.Loot, item.info.shortname, item.amount, player);
}
LootersListCrateID.Add(NetID);
}
public List<UInt64> LootersListCrateID = new List<UInt64>();
void OnCollectiblePickup(CollectibleEntity collectible, BasePlayer player)
{
foreach(ItemAmount item in collectible.itemList)
item.amount = Converted(Types.PickUP, item.itemDef.shortname, (Int32)item.amount, player);
//player.SendConsoleCommand($"note.inv 605467368 1 \"{Settings.p.PickUpRat} Pickup\"");
}
void OnDispenserBonus(ResourceDispenser disp, BasePlayer player, Item item)
{
if (item == null || player == null) return;
int Rate = Converted(Types.Gather, item.info.shortname, item.amount, player);
item.amount = Rate;
//player.SendConsoleCommand($"note.inv 605467368 1 \"+{Settings.g.GatherRat} Gather\"");
}
object OnDispenserGather(ResourceDispenser dispenser, BaseEntity entity, Item item)
{
BasePlayer player = entity as BasePlayer;
if (item == null || player == null) return null;
Int32 Rate = Converted(Types.Gather, item.info.shortname, item.amount, player);
item.amount = Rate;
return null;
}
private void OnExcavatorGather(ExcavatorArm excavator, Item item)
{
GatherMultiplier(item);
}
void OnQuarryGather(MiningQuarry quarry, Item item)
{
if(quarry.OwnerID == 0)
{
GatherMultiplier(item);
return;
}
BasePlayer player = BasePlayer.FindByID(quarry.OwnerID);
if(player == null)
{
BasePlayer player1 = BasePlayer.FindSleeping(quarry.OwnerID);
if(player1 == null) return;
}
GatherMultiplier(item);
}
private void GatherMultiplier(Item item)
{
item.amount = (int)(item.amount * Settings.qRates);
}
private void GatherMultiplier(ItemAmount item)
{
item.amount = (int)(item.amount * Settings.qRates);
}
private class Configuration
{
[JsonProperty("Quarry, Excavator Rates")]
public float qRates;
[JsonProperty("Player Rates")]
public float Rates;
public static Configuration Generate()
{
return new Configuration
{
qRates = 10.0f,
Rates = 2.0f,
};
}
}
private static Configuration Settings;
protected override void LoadConfig()
{
base.LoadConfig();
try
{
Settings = Config.ReadObject<Configuration>();
}
catch
{
PrintWarning($"Error reading config, creating one new config!");
LoadDefaultConfig();
}
SaveConfig();
}
protected override void LoadDefaultConfig() => Settings = Configuration.Generate();
protected override void SaveConfig() => Config.WriteObject(Settings);
}
}