C#:
using System.Collections.Generic;
using UnityEngine;
using Rust;
using System;
using Oxide.Core;
using System.Reflection;
using System.Security.Policy;
using System.ComponentModel;
namespace Oxide.Plugins
{
[Info("ThunderPoon", "Death", "1.0.3")]
class ThunderPoon : RustPlugin
{
#region Declarations
const string perm = "thunderpoon.use";
System.Random DetonationChance = new System.Random();
List<DamageTypeEntry> PoonDamage;
#endregion
#region Hooks
void Init()
{
LoadConfigVariables();
permission.RegisterPermission(perm, this);
PoonDamage = new List<DamageTypeEntry> { new DamageTypeEntry { type = DamageType.Explosion, amount = configData.Properties.damage } };
}
object OnWorldProjectileCreate(HitInfo info, Item item)
{
if (item.info.itemid != 1602646136 && item.info.itemid != 1540934679 || item.skin != 2186193876)
{
return null;
}
NextTick(() => DeployPoon(info.Initiator, item));
return null;
}
void CanStackItem(Item spear, Item explosive)
{
if (spear.info.itemid != 1602646136 && spear.info.itemid != 1540934679 || explosive.info.itemid != 1840822026)
{
return;
}
if (spear.parent.playerOwner == null)
{
return;
}
if (configData.Options.UsePermission && !permission.UserHasPermission(spear.parent.playerOwner.UserIDString, perm))
{
return;
}
if (spear.amount > explosive.amount)
{
if (explosive.amount != 0)
{
spear.parent.playerOwner.GiveItem(ItemManager.Create(spear.info, spear.amount - explosive.amount, spear.skin));
}
spear.amount = explosive.amount;
spear.MarkDirty();
}
explosive.amount -= spear.amount;
if (explosive.amount <= 0)
{
explosive.Remove();
}
else
{
explosive.MarkDirty();
}
spear.skin = 2186193876;
Effect.server.Run("assets/bundled/prefabs/fx/repairbench/itemrepair.prefab", spear.parent.playerOwner.transform.position);
}
void OnMeleeThrown(BasePlayer player, Item item)
{
if (item.amount == 1 || item.skin != 2186193876)
{
return;
}
player.inventory.GiveItem(ItemManager.CreateByItemID(item.info.itemid, item.amount - 1, item.skin));
item.amount = 1;
item.MarkDirty();
}
#endregion
#region Functions
void DeployPoon(BaseEntity player, Item item)
{
if (DetonationChance.Next(0, 100) > configData.Properties.detonateChance)
{
return;
}
var worldEntity = item.GetWorldEntity();
if (worldEntity == null)
{
return;
}
Effect.server.Run("assets/prefabs/weapons/beancan grenade/effects/beancan_grenade_explosion.prefab", worldEntity.transform.position);
DamageUtil.RadiusDamage(player, worldEntity.LookupPrefab(), worldEntity.transform.position, configData.Properties.minRange, configData.Properties.maxRange, PoonDamage, ~1, true);
item.RemoveFromWorld();
}
#region Config
ConfigData configData;
class ConfigData
{
public Options Options = new Options();
public Properties Properties = new Properties();
}
class Options
{
public bool UsePermission = true;
}
class Properties
{
public float damage = 100f;
public float minRange = 0f;
public float maxRange = 10f;
public int detonateChance = 100;
}
void LoadConfigVariables()
{
configData = Config.ReadObject<ConfigData>();
SaveConfig(configData);
}
protected override void LoadDefaultConfig()
{
SaveConfig(new ConfigData());
}
void SaveConfig(ConfigData config)
{
Config.WriteObject(config, true);
}
#endregion
#endregion
}
}