That's because the type "Pumpjack" does not exist. If I'm not mistaken the pump jacks are either MiningQuarry or BaseResourceExtractor. Maybe both.
soo i managed to make it work it crafts the correct item and places it.... for 3 seconds... then it destroys itself, heres the entire script maybe someone will be able to look at it and can see what im doing wrong.
Edit: ok so if you disable Check ground for entity (destroy on missing)" the pumpjack stays around but the whole script is still soo jankey, it spawns a recycler in the middle of the pumpjack and i can only guess thats why the pumpjack is getting destroyed, but im not sure why the recycler is still even appearing since i removed every instance of the word recycler from the script.
honestly the only major problem im facing right now with this script is that the Recycler is still created when the Pumpjack is placed causing the item to become duplicated
using System.Collections.Generic;
using Newtonsoft.Json;
using UnityEngine;
namespace Oxide.Plugins
{
[Info("Extended Pumpjack", "Judess69er", "1.0.0")]
[Description("Extend pumpjacks for personal use and more")]
public class ExtendedPumpjack : RustPlugin
{
#region Vars
private const ulong skinID = 1594245394;
private const string prefab = "assets/bundled/prefabs/static/pumpjack-static.prefab";
private static ExtendedPumpjack plugin;
private const string permUse = "ExtendedPumpjack.use";
#endregion
#region Config
private static ConfigData config;
private class ConfigData
{
[JsonProperty(PropertyName = "1. Pickup settings:")]
public OPickup pickup;
[JsonProperty(PropertyName = "2. Craft settings:")]
public OCraft craft;
[JsonProperty(PropertyName = "3. Destroy settings:")]
public ODestroy destroy;
public class OPickup
{
[JsonProperty(PropertyName = "1. Enabled for personal pumpjacks (placed by player)")]
public bool personal;
[JsonProperty(PropertyName = "2. Check ability to build for pickup")]
public bool privilege;
[JsonProperty(PropertyName = "3. Only owner can pickup")]
public bool onlyOwner;
}
public class OCraft
{
[JsonProperty(PropertyName = "1. Enabled")]
public bool enabled;
[JsonProperty(PropertyName = "2. Cost (shortname - amount):")]
public Dictionary<string, int> cost;
}
public class ODestroy
{
[JsonProperty(PropertyName = "1. Check ground for pumpjacks (destroy on missing)")]
public bool checkGround;
[JsonProperty(PropertyName = "2. Give item on destroy pumpjack")]
public bool destroyItem;
[JsonProperty(PropertyName = "3. Effects on destroy pumpjack")]
public List<string> effects;
}
}
private ConfigData GetDefaultConfig()
{
return new ConfigData
{
pickup = new ConfigData.OPickup
{
personal = false,
privilege = true,
onlyOwner = false
},
craft = new ConfigData.OCraft
{
enabled = true,
cost = new Dictionary<string, int>
{
{"scrap", 500},
{"metal.fragments", 5000},
{"metal.refined", 50},
{"gears", 10}
}
},
destroy = new ConfigData.ODestroy
{
checkGround = true,
destroyItem = true,
effects = new List<string>
{
"assets/bundled/prefabs/fx/item_break.prefab",
"assets/bundled/prefabs/fx/impacts/stab/rock/stab_rock_01.prefab"
}
}
};
}
protected override void LoadConfig()
{
base.LoadConfig();
try
{
config = Config.ReadObject<ConfigData>();
}
catch
{
LoadDefaultConfig();
}
SaveConfig();
}
protected override void LoadDefaultConfig()
{
PrintError("Configuration file is corrupt(or not exists), creating new one!");
config = GetDefaultConfig();
}
protected override void SaveConfig()
{
Config.WriteObject(config);
}
#endregion
#region Language
private Dictionary<string, string> EN = new Dictionary<string, string>
{
{"Name", "Pumpjack"},
{"Pickup", "You picked up pumpjack!"},
{"Receive", "You received pumpjack!"},
{"Disabled", "Pickup disabled!"},
{"Build", "You must have ability to build to do that!"},
{"Damaged", "Pumpjack was recently damaged, you can pick it up in next 30s!"},
{"NoCraft", "Craft disabled!"},
{"Owner", "Only owner can pickup pumpjack!"},
{"Craft", "For craft you need more resources:\n{0}"},
{"Permission", "You need permission to do that!"}
};
private void message(BasePlayer player, string key, params object[] args)
{
if (player == null)
{
return;
}
var message = string.Format(lang.GetMessage(key, this, player.UserIDString), args);
player.ChatMessage(message);
}
#endregion
#region Oxide Hooks
private void OnEntityBuilt(Planner plan, GameObject go)
{
CheckDeploy(go.ToBaseEntity());
}
private void OnServerInitialized()
{
plugin = this;
lang.RegisterMessages(EN, this);
permission.RegisterPermission(permUse, this);
CheckPumpjacks();
}
private void OnHammerHit(BasePlayer player, HitInfo info)
{
CheckHit(player, info?.HitEntity);
}
#endregion
#region Core
private void SpawnPumpjack(Vector3 position, Quaternion rotation = default(Quaternion), ulong ownerID = 0)
{
var pumpjack = GameManager.server.CreateEntity(prefab, position, rotation);
if (pumpjack == null)
{
return;
}
pumpjack.skinID = skinID;
pumpjack.OwnerID = ownerID;
pumpjack.gameObject.AddComponent<ExtendedPumpjackComponent>();
pumpjack.Spawn();
}
private void CheckPumpjacks()
{
foreach (var pumpjack in UnityEngine.Object.FindObjectsOfType<BaseResourceExtractor>())
{
if (pumpjack.OwnerID != 0 && pumpjack.GetComponent<ExtendedPumpjackComponent>() == null)
{
pumpjack.gameObject.AddComponent<ExtendedPumpjackComponent>();
}
}
}
private void GivePumpjack(BasePlayer player, bool pickup = false)
{
var item = CreateItem();
if (item != null && player != null)
{
player.GiveItem(item);
message(player, pickup ? "Pickup" : "Receive");
}
}
private void GivePumpjack(Vector3 position)
{
var item = CreateItem();
item?.Drop(position, Vector3.down);
}
private Item CreateItem()
{
var item = ItemManager.CreateByName("box.repair.bench", 1, skinID);
if (item != null)
{
item.name = plugin?.GetPumpjackName();
}
return item;
}
private void CheckDeploy(BaseEntity entity)
{
if (entity == null)
{
return;
}
if (!IsPumpjack(entity.skinID))
{
return;
}
var transform = entity.transform;
SpawnPumpjack(transform.position, transform.rotation, entity.OwnerID);
entity.transform.position -= new Vector3(0, 3, 0);
entity.SendNetworkUpdate();
timer.Once(1f, () =>
{
if (entity.IsValid() == true && entity.IsDestroyed == false)
{
entity.Kill();
}
});
}
private void CheckHit(BasePlayer player, BaseEntity entity)
{
if (entity == null)
{
return;
}
if (!IsPumpjack(entity.skinID))
{
return;
}
timer.Once(1f, () =>
{
if (entity.IsValid() == true)
{
entity.GetComponent<ExtendedPumpjackComponent>()?.TryPickup(player);
}
});
}
[ChatCommand("pumpjack.craft")]
private void Craft(BasePlayer player)
{
if (CanCraft(player))
{
GivePumpjack(player);
}
}
private bool CanCraft(BasePlayer player)
{
if (!config.craft.enabled)
{
message(player, "NoCraft");
return false;
}
if (!permission.UserHasPermission(player.UserIDString, permUse))
{
message(player, "Permission");
return false;
}
var recipe = config.craft.cost;
var more = new Dictionary<string, int>();
foreach (var component in recipe)
{
var name = component.Key;
var has = player.inventory.GetAmount(ItemManager.FindItemDefinition(component.Key).itemid);
var need = component.Value;
if (has < component.Value)
{
if (!more.ContainsKey(name))
{
more.Add(name, 0);
}
more[name] += need;
}
}
if (more.Count == 0)
{
foreach (var item in recipe)
{
player.inventory.Take(null, ItemManager.FindItemDefinition(item.Key).itemid, item.Value);
}
return true;
}
else
{
var text = "";
foreach (var item in more)
{
text += $" * {item.Key} x{item.Value}\n";
}
player.ChatMessage(string.Format(lang.GetMessage("Craft", this), text));
return false;
}
}
#endregion
#region Helpers
private string GetPumpjackName()
{
return lang.GetMessage("Name", this);
}
private bool IsPumpjack(ulong skin)
{
return skin != 0 && skin == skinID;
}
#endregion
#region Command
[ConsoleCommand("pumpjack.give")]
private void Cmd(ConsoleSystem.Arg arg)
{
if (arg.IsAdmin && arg.Args?.Length > 0)
{
var player = BasePlayer.Find(arg.Args[0]) ?? BasePlayer.FindSleeping(arg.Args[0]);
if (player == null)
{
PrintWarning($"We can't find player with that name/ID! {arg.Args[0]}");
return;
}
GivePumpjack(player);
}
}
#endregion
#region Scripts
private class ExtendedPumpjackComponent : MonoBehaviour
{
private BaseResourceExtractor baseresourceextractor;
private void Awake()
{
baseresourceextractor = GetComponent<BaseResourceExtractor>();
if (config.destroy.checkGround)
{
InvokeRepeating("CheckGround", 5f, 5f);
}
}
private void CheckGround()
{
RaycastHit rhit;
var cast = Physics.Raycast(baseresourceextractor.transform.position + new Vector3(0, 0.1f, 0), Vector3.down,
out rhit, 4f, LayerMask.GetMask("Terrain", "Construction"));
var distance = cast ? rhit.distance : 3f;
if (distance > 0.2f)
{
GroundMissing();
}
}
private void GroundMissing()
{
baseresourceextractor.Kill();
if (config.destroy.destroyItem)
{
plugin.GivePumpjack(baseresourceextractor.transform.position);
}
foreach (var effect in config.destroy.effects)
{
Effect.server.Run(effect, baseresourceextractor.transform.position);
}
}
public void TryPickup(BasePlayer player)
{
if (config.pickup.personal == false)
{
plugin.message(player, "Disabled");
return;
}
if (config.pickup.privilege && !player.CanBuild())
{
plugin.message(player, "Build");
return;
}
if (config.pickup.onlyOwner && baseresourceextractor.OwnerID != player.userID)
{
plugin.message(player, "Owner");
return;
}
if (baseresourceextractor.SecondsSinceDealtDamage < 30f)
{
plugin.message(player, "Damaged");
return;
}
baseresourceextractor.Kill();
plugin.GivePumpjack(player, true);
}
public void DoDestroy()
{
Destroy(this);
}
}
#endregion
}
}
Merged postSolved the prudent issues and made it into a plugin
https://umod.org/plugins/wmgDorjK2Z