1. I am trying to create an animal, and identify it so I can change his life, or kill him, etc.

    I can create it, but I have no idea how to handle it. I've been loking into BaseNPC, but I am lost.
     
  2. Calytic

    Calytic Community Admin Community Mod

  3. I was looking it but it is like on another level for me. I can't understand it.

    Thanks anyways.
     
  4. UPDATE: I made a breakthrough using @k1lly0u 's plugin. but I have a problem now. I want the animal to follow the player. That work. But the thing is that the animal is attacking the player. I don't want that, but I have no idea what to do. My brain is fried. :p

    Code:
    // Reference: RustBuild
    using System;
    using System.Collections.Generic;
    using UnityEngine;
    using System.Linq;
    using System.Reflection;namespace Oxide.Plugins
    {
        [Info("Test", "Test", "1.0.4")]
        class Test : RustPlugin
        {
            private Dictionary<BaseEntity, Vector3> animalList = new Dictionary<BaseEntity, Vector3>();        [ChatCommand("wesa")]
            void Spawnear(BasePlayer player)
            {
                Vector3 position = player.transform.position;
                var newAnimal = SpawnAnimalEntity(player, position);
                animalList.Add(newAnimal, position);
            }
            private BaseEntity SpawnAnimalEntity(BasePlayer player, Vector3 pos)
            {
                var newPos = pos;
                BaseEntity entity = GameManager.server.CreateEntity($"assets/bundled/prefabs/autospawn/animals/bear.prefab", newPos, new Quaternion(), true);
                entity.Spawn();
                var npc = entity.gameObject.AddComponent<RAController>();
                npc.SetHome(pos);
                npc.owner = player;
                return entity;
            }        #region NPCController
            class RAController : MonoBehaviour
            {
                private readonly MethodInfo SetDeltaTimeMethod = typeof(NPCAI).GetProperty("deltaTime", (BindingFlags.Public | BindingFlags.Instance)).GetSetMethod(true);            internal static double targetAttackRange = 70;            internal Vector3 Home;
                internal BaseCombatEntity Target;            internal bool isAttacking;            public BasePlayer owner;            public BaseNPC NPC;
                public NPCAI AI;
                public NPCMetabolism Metabolism;            void Awake()
                {
                    AI = GetComponent<NPCAI>();
                    NPC = GetComponent<BaseNPC>();
                    Metabolism = GetComponent<NPCMetabolism>();
                    isAttacking = false;
                    Target = null;
                    NPC.state = BaseNPC.State.Normal;
                    NPC.enableSaving = false;
                    BaseEntity.saveList.Remove(NPC);
                }
                void FixedUpdate()
                {
                    Pets chat_gateway = new Pets();
                    Vector3 pos = owner.transform.position;
                    if (AI.deltaTime < ConVar.Server.TickDelta()) return;
                    if (NPC.IsStunned()) return;
                    NPC.Tick();
                    NPC.state = BaseNPC.State.Normal;
                    Move(pos);
                }
                public void SetHome(Vector3 pos)
                {
                    Home = pos;
                }
                void Move(Vector3 pos)
                {
                    NPC.state = BaseNPC.State.Normal;
                    AI.sense.Think();
                    NPC.steering.Move((pos - transform.position).XZ3D().normalized, pos, (int)NPCSpeed.Trot);
                }
                void Sleep()
                {
                    NPC.state = BaseNPC.State.Sleeping;
                    NPC.sleep.Recover(20f);
                    Metabolism.stamina.Run(20f);
                    NPC.StartCooldown(20f, true);
                }
                internal void OnAttacked(HitInfo info)
                {
                    if (info.Initiator) Attack(info.Initiator.GetComponent<BaseCombatEntity>());
                }
                internal void Attack(BaseCombatEntity ent)
                {
                    Target = ent;
                    isAttacking = true;
                    targetAttackRange = Math.Pow(NPC._collider.bounds.XZ3D().extents.Max() + NPC.attack.range + ent._collider.bounds.XZ3D().extents.Max(), 2);
                }
            }
            #endregion
        }
    }
    
     
  5. The Pets plugin already listed has the ability for pets to follow you without attacking
     
  6. Yes. I did take a lot of code from there. And from other plugins that handle this.
    Thank you.