... not working ! It do nothing on a Server !
Plugin is ...
Hi,
I have a version up to date including all the seeds (berries)
using System;
using Newtonsoft.Json;
using Oxide.Core;
using UnityEngine;
using Random = System.Random;
namespace Oxide.Plugins
{
[Info("Plant Drop", "Iv Misticos", "1.2.4")]
[Description("Allows planting growables anywhere by dropping the seed")]
class PlantDrop : RustPlugin
{
#region Variables
private const string PrefabCorn = "assets/prefabs/plants/corn/corn.entity.prefab";
private const string PrefabHemp = "assets/prefabs/plants/hemp/hemp.entity.prefab";
private const string PrefabPotato = "assets/prefabs/plants/potato/potato.entity.prefab";
private const string PrefabPumpkin = "assets/prefabs/plants/pumpkin/pumpkin.entity.prefab";
private const string PrefabBlackBerry = "assets/prefabs/plants/berrry/black/black_berry.entity.prefab";
private const string PrefabBlueBerry = "assets/prefabs/plants/berrry/blue/blue_berry.entity.prefab";
private const string PrefabGreenBerry = "assets/prefabs/plants/berrry/green/green_berry.entity.prefab";
private const string PrefabRedBerry = "assets/prefabs/plants/berrry/red/red_berry.entity.prefab";
private const string PrefabWhiteBerry = "assets/prefabs/plants/berrry/white/white_berry.entity.prefab";
private const string PrefabYellowBerry = "assets/prefabs/plants/berrry/yellow/yellow_berry.entity.prefab";
private readonly Random _random = new Random();
#endregion
#region Configuration
private Configuration _config;
private class Configuration
{
[JsonProperty(PropertyName = "Randomize Position")]
public bool RandomizePosition = false;
[JsonProperty(PropertyName = "Randomize Position On N")]
public float RandomizePositionOn = 2f;
}
protected override void LoadConfig()
{
base.LoadConfig();
try
{
_config = Config.ReadObject<Configuration>();
if (_config == null) throw new Exception();
}
catch
{
PrintError("Your configuration file contains an error. Using default configuration values.");
LoadDefaultConfig();
}
}
protected override void LoadDefaultConfig() => _config = new Configuration();
protected override void SaveConfig() => Config.WriteObject(_config);
#endregion
#region Hooks
private void OnItemDropped(Item item, BaseNetworkable entity)
{
if (item?.info == null || entity == null)
return;
var shortname = item.info.shortname;
var pos = entity.transform.position;
// ReSharper disable once SwitchStatementMissingSomeCases
switch (shortname)
{
case "seed.corn":
CreatePlant(entity, PrefabCorn, pos, item.amount);
break;
case "seed.hemp":
CreatePlant(entity, PrefabHemp, pos, item.amount);
break;
case "seed.potato":
CreatePlant(entity, PrefabPotato, pos, item.amount);
break;
case "seed.pumpkin":
CreatePlant(entity, PrefabPumpkin, pos, item.amount);
break;
case "seed.blue.berry":
CreatePlant(entity, PrefabBlueBerry, pos, item.amount);
break;
case "seed.black.berry":
CreatePlant(entity, PrefabBlackBerry, pos, item.amount);
break;
case "seed.green.berry":
CreatePlant(entity, PrefabGreenBerry, pos, item.amount);
break;
case "seed.white.berry":
CreatePlant(entity, PrefabWhiteBerry, pos, item.amount);
break;
case "seed.red.berry":
CreatePlant(entity, PrefabRedBerry, pos, item.amount);
break;
case "seed.yellow.berry":
CreatePlant(entity, PrefabYellowBerry, pos, item.amount);
break;
}
}
#endregion
#region Helpers
private void CreatePlant(BaseNetworkable seed, string prefab, Vector3 pos, int amount)
{
var layers = LayerMask.GetMask("Player (Server)");
RaycastHit hit;
Physics.Raycast(pos, Vector3.down, out hit,66f, LayerMask.GetMask("Terrain", "World", "Construction", "Water"));
if (hit.GetEntity() != null)
return;
pos.y = TerrainMeta.HeightMap.GetHeight(seed.transform.position);
seed.Kill();
for (var i = 0; i < amount; i++)
{
if (_config.RandomizePosition)
{
pos.x += UnityEngine.Random.Range(-_config.RandomizePositionOn, _config.RandomizePositionOn);
pos.z += UnityEngine.Random.Range(-_config.RandomizePositionOn, _config.RandomizePositionOn);
pos.y = TerrainMeta.HeightMap.GetHeight(pos);
}
var growable = GameManager.server.CreateEntity(prefab, pos, Quaternion.identity) as GrowableEntity;
if (growable == null) continue;
growable.Spawn();
}
}
#endregion
}
}
Bye
Stéphane
BrocoSoupHi,
I have a version up to date including all the seeds (berries)
... i will test it and write u ;) Thanks
Merged post
... it seems to work, good job BUT i don't want to drop the seed, i want to bring it to a psoition normally, eg. street and the plant must not wither... Is that possible? Plugin "Eternal Plants (https://umod.org/plugins/eternal-plants)" but doesn't work, plants still wither...