Search results for query: *

  1. How to Make Custom Bannerlord Scripts Run on a Multiplayer Server

    Here is a video I made that talks about getting custom scripts in the scene editor to work on a multiplayer server. Ive attached the code examples from the video. I made a similar post earlier for getting scripts to run just in single player...
  2. How to deal damage to an agent

    Hi, I have written code to deal damage to an agent when they get too close to an object. The code works however when the player dies the game crashes. There are alot of options I could set and im not sure what I need to in order to get a proper death and avoid a crash, all im doing now is...
  3. How to create custom scripts to use in scene editor

    I was able to figure out how to do this by piecing together info from various sources. Ive created a crappy youtube video that says how to do it which includes a demo of an example map I made that utilizes a custom script I made. Ive also included the script code:

    C#:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using TaleWorlds.Engine;
    using TaleWorlds.Library;
    
    namespace MyMods
    {
        public class CS_MoveBackAndForth : ScriptComponentBehavior
        {
            public bool EnabledInGame = false;
            public bool EnabledInEditor = false;
            public float Destination_X1 = 0f;
            public float Destination_Y1 = 0f;
            public float Destination_Z1 = 0f;
            public float Destination_X2 = 0f;
            public float Destination_Y2 = 0f;
            public float Destination_Z2 = 0f;
            public float MoveSpeedX = 0f;
            public float MoveSpeedY = 0f;
            public float MoveSpeedZ = 0f;
            public float SlowAtDist = 0f;
            public float SlowSpeedPercent = 0f;
            protected bool FirstRun = true;
            protected bool GoToDest1 = true;
            protected bool DestXGreater = true;
            protected bool DestYGreater = true;
            protected bool DestZGreater = true;
            protected float sixtyFpsFrameTime = 0.0166f;
    
            private void Move(float dt)
            {
                float frameTime = dt;
    
                // We need to compensate for frame differences vs my standard 60 fps. Need to figure out what fps the server uses.
                float movementFrameModifier = frameTime / sixtyFpsFrameTime;
    
                if (GoToDest1 == true)
                {
                    MakeMove(Destination_X1, Destination_Y1, Destination_Z1, movementFrameModifier);
                }
                else
                {
                    MakeMove(Destination_X2, Destination_Y2, Destination_Z2, movementFrameModifier);
                }
    
            }
    
            private void MakeMove(float Destination_X, float Destination_Y, float Destination_Z, float movementFrameModifier)
            {
                float curPositionX = base.GameEntity.GetFrame().origin.x;
                float curPositionY = base.GameEntity.GetFrame().origin.y;
                float curPositionZ = base.GameEntity.GetFrame().origin.z;
                bool reachedDestination = false;
                float movementX = MoveSpeedX * movementFrameModifier, movementY = MoveSpeedY * movementFrameModifier, movementZ = MoveSpeedZ * movementFrameModifier;
    
                // Set compare types for first run in current route to destination
                if (FirstRun)
                {
                    if (curPositionX >= Destination_X)
                    {
                        DestXGreater = false;
                    }
                    if (curPositionY >= Destination_Y)
                    {
                        DestYGreater = false;
                    }
                    if (curPositionZ >= Destination_Z)
                    {
                        DestZGreater = false;
                    }
                    FirstRun = false;
                }
                /////////////////////////////////////
    
                // Do compares based on compare types we set to see what direction we move or if we are done
    
                movementX = DetermineMovement(movementX, curPositionX, Destination_X, DestXGreater);
                movementY = DetermineMovement(movementY, curPositionY, Destination_Y, DestYGreater);
                movementZ = DetermineMovement(movementZ, curPositionZ, Destination_Z, DestZGreater);
    
                ///////////////////////////////////////////////////
    
                // Check if we have reached destination
                if (movementX == 0f && movementY == 0f && movementZ == 0f)
                {
                    reachedDestination = true;
                }
                //////////////////////////////////////////////
    
                // If we have reached our destination then setup for going to the other destination and return
                if (reachedDestination == true)
                {
                    GoToDest1 = !GoToDest1;
                    FirstRun = true;
    
                    DestXGreater = true;
                    DestYGreater = true;
                    DestZGreater = true;
    
                    return;
                }
                //////////////////////////////////////////////////////////////
    
                // Do the actual vector move for the entity
                Vec3 vec = new Vec3(movementX, movementY, movementZ, -1f);
                MatrixFrame frame = base.GameEntity.GetFrame();
                frame.origin += vec;
                base.GameEntity.SetFrame(ref frame);
                //////////////////////////////////////////
            }
    
            private float DetermineMovement(float movement, float curPosition, float destination, bool DestGreater)
            {
    
                if (DestGreater == true)
                {
                    if (destination <= curPosition)
                    {
                        movement *= 0f;
                    }
                    else if (destination <= (curPosition + SlowAtDist))
                    {
                        movement *= SlowSpeedPercent;
                    }
                }
                else
                {
                    movement *= -1f;
                    if (destination >= curPosition)
                    {
                        movement *= 0f;
                    }
                    else if (destination >= (curPosition - SlowAtDist))
                    {
                        movement *= SlowSpeedPercent;
                    }
                }
    
                return movement;
            }
    
            protected override void OnInit()
            {
                base.OnInit();
                base.SetScriptComponentToTick(this.GetTickRequirement());
            }
    
            public override ScriptComponentBehavior.TickRequirement GetTickRequirement()
            {
                return ScriptComponentBehavior.TickRequirement.Tick | base.GetTickRequirement();
            }
    
            protected override void OnTick(float dt)
            {
                if (EnabledInGame == true)
                {
                    this.Move(dt);
                }
            }
    
            protected override void OnEditorTick(float dt)
            {
                base.OnEditorTick(dt);
    
                if (EnabledInEditor == true)
                {
                    this.Move(dt);
                }
            }
    
        }
    }
  4. How to create custom scripts to use in scene editor

    In the bannerlord scene editor you can add a script to an object. I was wondering how I could make my own script that I could then assign to an object in the scene editor to get a behavior I want. Im mainly looking to find out where I would need to store the script for it to show up in the...
Back
Top Bottom