Waterwell NPC SellerSolved

Hello, Umod!
Can you guys please tell me how to remove Waterwell NPC Seller from the server?

I've tried to do it by myself, but there is no any convars, commands about waterwell guy I've found. I dont wanna him to be here with his pumpkins and corns.

Thank you!

same problem!

Ya prob need a plugin made to do this.

We need this too! 👀

For oxide version this should be fine.

 

using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;

namespace Oxide.Plugins
{
[Info("RemoveWaterwellNPC", "fiftysnens", "1.0.1")]
[Description("Deletes all Waterwell NPCs wearing the jumpsuit.waterwellnpc and prevents them from respawning.")]
public class RemoveWaterwellNPC : RustPlugin
{
private const string WaterwellJumpsuitShortname = "jumpsuit.waterwellnpc";

// Called when the plugin is loaded
private void OnServerInitialized()
{
Puts("Checking for existing Waterwell NPCs...");
RemoveExistingWaterwellNPCs();
}

// Hook into the entity spawn event
private void OnEntitySpawned(BaseEntity entity)
{
if (entity is NPCPlayer npc)
{
if (IsWaterwellNPC(npc))
{
npc.Kill();
Puts($"Removed a Waterwell NPC at {npc.transform.position}.");
}
}
}

// Removes existing Waterwell NPCs
private void RemoveExistingWaterwellNPCs()
{
foreach (var entity in BaseNetworkable.serverEntities)
{
if (entity is NPCPlayer npc)
{
if (IsWaterwellNPC(npc))
{
npc.Kill();
Puts($"Removed an existing Waterwell NPC at {npc.transform.position}.");
}
}
}
}

// Checks if an NPC is a Waterwell NPC based on their outfit
private bool IsWaterwellNPC(NPCPlayer npc)
{
if (npc?.inventory?.containerWear?.itemList == null)
return false;

foreach (var item in npc.inventory.containerWear.itemList)
{
if (item.info.shortname == WaterwellJumpsuitShortname)
{
return true; // NPC is wearing the waterwell jumpsuit
}
}
return false;
}
}
}

fiftysnens

For oxide version this should be fine.

 

using Oxide.Core;
using Oxide.Core.Plugins;
using Oxide.Game.Rust.Cui;
using UnityEngine;

Where is the Cui?

using Oxide.Game.Rust.Cui;

I simply quickly pulled what i though was needed to help the guys with the problem. I try to help. Feel free to remove teh statement if you dont like it.

fiftysnens

I simply quickly pulled what i though was needed to help the guys with the problem. I try to help. Feel free to remove teh statement if you dont like it.

Thats why there is plugins reviews so bad things do not get quickly toss togather like why are you geting every entity on private void OnEntitySpawned(NPCPlayer entity) and checking every entity why not just check for OnEntitySpawned(NPCPlayer entity)?


Valid question. simply tought of a quick fix and its not liek this runs each tick or somthing, wont be that bad

, will it ? Changed it now, thanks for th hint

Jlo1hYIKPnof6LL.png Razor

Thats why there is plugins reviews so bad things do not get quickly toss togather like why are you geting every entity on private void OnEntitySpawned(NPCPlayer entity) and checking every entity why not just check for OnEntitySpawned(NPCPlayer entity)?

fiftysnens

Valid question. simply tought of a quick fix and its not liek this runs each tick or somthing, wont be that bad

, will it ? Changed it now, thanks for th hint

It runs for every entity what spawns so it still runs alot.



Merged post

Name File RemoveWaterWellNpc.cs
namespace Oxide.Plugins
{
    [Info("RemoveWaterWellNpc", "Razor", "1.0.0")]
    [Description("Remove unwanted WaterWell npc's")]
    public class RemoveWaterWellNpc : RustPlugin
    {
        private const string prefab = "assets/prefabs/npc/waterwell/waterwell_shopkeeper.prefab";

        private void OnServerInitialized()
        {
            foreach (var npc in BaseNetworkable.serverEntities)
            {
                if (npc != null && npc is NPCShopKeeper)
                    RemoveShopKeeper(npc.GetComponent<NPCShopKeeper>());
            }
        }

        private void OnEntitySpawned(NPCShopKeeper keeper) => RemoveShopKeeper(keeper);

        private void RemoveShopKeeper(NPCShopKeeper keeper)
        {
            if (keeper != null && keeper.name != null && keeper.name == prefab && keeper.skinID == 0UL)
            {
                if (keeper.invisibleVendingMachineRef.Get(true) != null && keeper.invisibleVendingMachineRef.Get(true) is InvisibleVendingMachine invisibleVendingMachine)
                {
                    PrintWarning("Killing WaterWell Npc Vendingmachine");
                    if (invisibleVendingMachine != null && !invisibleVendingMachine.IsDestroyed)
                        invisibleVendingMachine.Kill();
                }
                PrintWarning("Killing WaterWell Npc.");
                if (keeper != null && !keeper.IsDestroyed)
                    keeper.Kill();
            }
        }
    }
}
Locked automatically