For some reason, DFU standalone does not load the mod, but the unity builder will. Any ideas on what is going on? I'll drop the code below. I must be accessing something that is within the builder, but not within the stand alone game, right?
any assists would be helpful.
Code: Select all
using UnityEngine;
using DaggerfallWorkshop.Game.Entity;
using DaggerfallWorkshop.Game.Utility.ModSupport; //required for modding features
using DaggerfallWorkshop.Game.Utility.ModSupport.ModSettings;
using System.Collections;
namespace DaggerfallWorkshop.Game.DodgeMod
{
public class DodgeMod : MonoBehaviour
{
//sets up script properties/variables.
private PlayerMotor playerMotor;
private GameObject mainCamera;
private CharacterController playerController;
private WeaponManager weaponManager;
public float dodgingdistance;
public float TimeCovered;
float fractionOfJourney;
int AvoidHitMod;
float dodgetimer;
float headDelta;
float dodgeMaxTime;
float dodgeDistanceMult;
float dodgeTimeMult;
bool touchingSides;
bool touchingGround;
bool dodging;
bool sheathedState;
string inputKey;
Vector3 dodgeCamera;
Vector3 dodgeDirection;
Vector3 motion;
static Mod mod;
static DodgeMod instance;
static ModSettings settings;
//sets up different class properties.
#region Properties
//sets up player entity class for easy retrieval and manipulation of player character.
PlayerEntity playerEntity;
//sets up player class instance properties for manipulation.
public PlayerEntity PlayerEntity
{
get { return (playerEntity != null) ? playerEntity : playerEntity = GameManager.Instance.PlayerEntity; }
}
#endregion
//starts mod manager on game begin. Grabs mod initializing paramaters.
//ensures SateTypes is set to .Start for proper save data restore values.
[Invoke(StateManager.StateTypes.Start, 0)]
public static void Init(InitParams initParams)
{
Debug.Log("DODGE MOD STARTED!");
//sets up instance of class/script/mod.
GameObject go = new GameObject("DodgeMod");
instance = go.AddComponent<DodgeMod>();
//initiates mod paramaters for class/script.
mod = initParams.Mod;
//initates mod settings
settings = mod.GetSettings();
//after finishing, set the mod's IsReady flag to true.
mod.IsReady = true;
}
void Start()
{
//Sets up object instances for GameManager, so said scripts can be manipulated/accessed. Prints Message when done.
playerMotor = GameManager.Instance.PlayerMotor;
weaponManager = GameManager.Instance.WeaponManager;
mainCamera = GameObject.FindGameObjectWithTag("MainCamera");
playerController = playerMotor.GetComponent<CharacterController>();
//StartCoroutine(debug());
dodgeDistanceMult = settings.GetValue<float>("Settings", "DodgeDistanceMult");
dodgeTimeMult = settings.GetValue<float>("Settings", "DodgeTimeMult");
DaggerfallUI.Instance.PopupMessage("Dodge Script Started:");
}
void Update()
{
//Checks if player is touching the ground or side. Used to stop dodging when player hits objects/walls or is in the air.
touchingSides = (playerMotor.CollisionFlags & CollisionFlags.Sides) != 0;
touchingGround = (playerMotor.CollisionFlags & CollisionFlags.Below) != 0;
//put in for now to verify mod is active in stand alone game.
DaggerfallUI.Instance.PopupMessage("Dodge Script Running:");
//activates on frame of key press and player not attacking. Sets up vars for dodging routine below.
if (Input.GetKeyDown(KeyCode.J) && weaponManager.IsAttacking == false)
{
//records players avoidhit modifier stat to reset to default after dodge is over.
AvoidHitMod = PlayerEntity.BiographyAvoidHitMod;
sheathedState = GameManager.Instance.WeaponManager.Sheathed;
//Figures out fatigue cost. most is 20 at 0 agility and least is 10 at 100 agility.
PlayerEntity.CurrentFatigue = PlayerEntity.CurrentFatigue - ((200 - PlayerEntity.Stats.LiveAgility) / 10);
//max is .5f seconads at 100 agility;
dodgeMaxTime = ((PlayerEntity.Stats.LiveAgility/2f)/100f) * dodgeTimeMult;
//max is .1f at 100 agility;
dodgingdistance = ((PlayerEntity.Stats.LiveAgility / 10f) / 100f) * dodgeDistanceMult;
}
//executes actual dodge routine, as long as player holds dodge key and movement direction and is not attacking.
if (Input.GetKey(KeyCode.J) && weaponManager.IsAttacking == false)
{
//counts how long player is dodging/holding dodge key.
dodgetimer += Time.deltaTime;
//if then check for movement direction. Sets dodge direction based on detected movement direction.
if (InputManager.Instance.HasAction(InputManager.Actions.MoveRight))
dodgeDirection = mainCamera.transform.right;
else if (InputManager.Instance.HasAction(InputManager.Actions.MoveLeft))
dodgeDirection = mainCamera.transform.right * -1;
else if (InputManager.Instance.HasAction(InputManager.Actions.MoveForwards))
dodgeDirection = mainCamera.transform.forward;
else if (InputManager.Instance.HasAction(InputManager.Actions.MoveBackwards))
dodgeDirection = mainCamera.transform.forward * -1;
//sheathes weapons, executs dodge, and sets player hit avoidance to 100%, as long as it is below max dodge time allowed.
if (dodgetimer < dodgeMaxTime)
{
GameManager.Instance.WeaponManager.Sheathed = true;
dodging = true;
PlayerEntity.BiographyAvoidHitMod = 100;
}
else
{
dodging = false;
GameManager.Instance.WeaponManager.Sheathed = sheathedState;
}
}
//resets dodge and dodge vars for next dodge when dodge key is released.
if (Input.GetKeyUp(KeyCode.J))
{
dodging = false;
TimeCovered = 0;
dodgetimer = 0;
fractionOfJourney = 0;
PlayerEntity.BiographyAvoidHitMod = AvoidHitMod;
GameManager.Instance.WeaponManager.Sheathed = sheathedState;
}
//ensures player is grounded and not against an object/wall to execute dodge.
if(!touchingGround || touchingSides)
{
GameManager.Instance.WeaponManager.Sheathed = sheathedState;
dodging = false;
}
//Executes Feign routine that moves player, as long as dodge key is pressed.
if (dodging == true)
ExecFeignIn(dodgeDirection, dodgeMaxTime, dodgingdistance);
}
void ExecFeignIn(Vector3 direction, float duration, float distance)
{
// Distance moved equals elapsed time times speed.
TimeCovered += Time.deltaTime;
// Fraction of journey completed equals current time divided by total movement time.
fractionOfJourney = TimeCovered / duration;
//reprocesses time passed into a sin graph function to provide a ease out movement shape instead of basic linear movement.
fractionOfJourney = fractionOfJourney * fractionOfJourney * fractionOfJourney * (fractionOfJourney * (6f * fractionOfJourney - 15f) + 10f);
//Mathf.Sin(fractionOfJourney * Mathf.PI * 0.33f);
dodgeCamera = mainCamera.transform.position - (mainCamera.transform.up * (fractionOfJourney / 10));
mainCamera.transform.position = dodgeCamera;
//sets movement direction and distance.
motion = direction * distance;
//moves player by taking the motion and then lerping it over time to provide a set movement distance and speed
//for movement/code execution.
playerController.Move(motion * (fractionOfJourney));
//Ensures feignin stops if timecovered passes a 100 % of its value. Ensures weird outputs don't happen by ensuring time doesn't go over
//100% of the execution time. Turns off FeignIn so FeignWait coroutine can start next phase of dodge.
if (fractionOfJourney > .99f && !(fractionOfJourney < 0f))
{
//InvokeFeign = true;
dodging = false;
}
}
//Debug coroutine for fine tuning.
IEnumerator debug()
{
while (true)
{
DaggerfallUI.Instance.PopupMessage("distance: " + dodgingdistance.ToString());
//DaggerfallUI.Instance.PopupMessage("Sides: " + touchingSides.ToString());
//DaggerfallUI.Instance.PopupMessage("Ground: " + touchingGround.ToString());
//DaggerfallUI.Instance.PopupMessage("time: " + TimeCovered.ToString());
DaggerfallUI.Instance.PopupMessage("time%: " + fractionOfJourney.ToString());
yield return new WaitForSeconds(1.0f);
}
}
}
}