C#:
using System;
using System.Linq;
using System.Text;
using System.Collections.Generic;
using UnityEngine;
using System.Reflection;
using Oxide.Game.Rust.Cui;
namespace Oxide.Plugins
{
[Info("Fishing", "Colon Blow", "1.0.6")]
class Fishing : RustPlugin
{
private static int waterlayer;
private int weaponmod;
private int attiremod;
string fxfishpluck = "assets/content/unimplemented/fishing_rod/vm_fishing_rod/pluck_fish.prefab";
void OnServerInitialized()
{
waterlayer = UnityEngine.LayerMask.GetMask("Water");
}
void OnLoad()
{
weaponmod = 0;
attiremod = 0;
}
Dictionary<ulong, string> GuiInfo = new Dictionary<ulong, string>();
bool ShowIndicator = true;
// Checks to see if player is standing around open water
bool isonOcean(BasePlayer player)
{
UnityEngine.Ray ray1 = new UnityEngine.Ray(player.transform.position, Vector3.down);
var hits1 = UnityEngine.Physics.RaycastAll(ray1, 5f, waterlayer);
foreach (var hit in hits1)
if (hit.distance > 0f) return false;
return true;
}
// Checks to see if player is standing near or in a river
bool isonRiver(BasePlayer player)
{
UnityEngine.Ray ray2 = new UnityEngine.Ray(player.transform.position, Vector3.down);
var hits2 = UnityEngine.Physics.RaycastAll(ray2, 5f, 4);
foreach (var hit in hits2)
if (hit.distance > 0f) return false;
return true;
}
// Checks to see if player is close enough to see fish in water
bool checkfishingdist(BasePlayer player)
{
UnityEngine.Ray ray3 = new UnityEngine.Ray(player.eyes.position, player.eyes.HeadForward());
var hits3 = UnityEngine.Physics.RaycastAll(ray3, 100f, waterlayer);
foreach (var hit in hits3)
if (hit.distance < 5f) return true;
return false;
}
// Show fish icon and player animation when catching fish
void catchFishCui(BasePlayer player)
{
if (ShowIndicator) FishingGui(player);
timer.Once(2f, () => DestroyCui(player));
}
// Chance roll to see if player gets a fish or not in Open water areas
void rollforWaterfish(BasePlayer player)
{
var Waterroll = UnityEngine.Random.Range(weaponmod + attiremod, 10);
var Watercatchroll = UnityEngine.Random.Range(weaponmod + attiremod, 10);
if (Waterroll == Watercatchroll)
{
Effect.server.Run(fxfishpluck, player.transform.position);
player.inventory.GiveItem(-1658459025, 2);
SendReply(player, "You Got a Savis Island Swordfish");
catchFishCui(player);
}
if (Waterroll != Watercatchroll)
{
SendReply(player, "You Missed the fish....");
}
}
// Chance roll to see if player gets a fish or not in Rivers
void rollforRiverfish(BasePlayer player)
{
var riverroll = UnityEngine.Random.Range(weaponmod + attiremod, 10);
var rivercatchroll = UnityEngine.Random.Range(weaponmod + attiremod, 10);
if (riverroll == rivercatchroll)
{
Effect.server.Run(fxfishpluck, player.transform.position);
player.inventory.GiveItem(-1658459025, 1);
SendReply(player, "You Got A Hapis Island RazorJaw !!!");
catchFishCui(player);
}
if (riverroll != rivercatchroll)
{
SendReply(player, "You Missed the fish....");
}
}
// Modifiers that chance the chance a player will get a fish or not
void catchChanceMod(BasePlayer player, HitInfo hitInfo)
{
if (hitInfo.WeaponPrefab.ToString().Contains("stone") || hitInfo.WeaponPrefab.ToString().Contains("cross"))
{
weaponmod = 6;
}
int hasBoonieOn = player.inventory.containerWear.GetAmount(-1397343301, true);
if (hasBoonieOn >= 1)
{
attiremod = 6;
}
if (weaponmod + attiremod > 8)
{
weaponmod = 4;
attiremod = 4;
}
}
// Runs Fishing Action on player attack when all criteria are met
void OnPlayerAttack(BasePlayer player, HitInfo hitInfo)
{
weaponmod = 0;
attiremod = 0;
catchChanceMod(player, hitInfo);
if (hitInfo.WeaponPrefab.ToString().Contains("spear") || hitInfo.WeaponPrefab.ToString().Contains("bow"))
{
if (isonOcean(player) && checkfishingdist(player))
{
rollforWaterfish(player);
return;
}
if (isonRiver(player) && checkfishingdist(player))
{
rollforRiverfish(player);
return;
}
}
}
// Displays Fish catch icon
void FishingGui(BasePlayer player)
{
DestroyCui(player);
var elements = new CuiElementContainer();
GuiInfo[player.userID] = CuiHelper.GetGuid();
if (ShowIndicator)
{
elements.Add(new CuiElement
{
Name = GuiInfo[player.userID],
Components =
{
new CuiRawImageComponent { Color = "1 1 1 1", Url = "http://i.imgur.com/HftxU00.png" },
new CuiRectTransformComponent { AnchorMin = "0.025 0.04", AnchorMax = "0.075 0.12" }
}
});
}
CuiHelper.AddUi(player, elements);
}
void Unload()
{
foreach (var player in BasePlayer.activePlayerList)
{
string guiInfo;
if (GuiInfo.TryGetValue(player.userID, out guiInfo)) CuiHelper.DestroyUi(player, guiInfo);
}
}
void DestroyCui(BasePlayer player)
{
string guiInfo;
if (GuiInfo.TryGetValue(player.userID, out guiInfo)) CuiHelper.DestroyUi(player, guiInfo);
}
}
}