Check for game start?

Discuss modding questions and implementation details.
Post Reply
User avatar
Ralzar
Posts: 815
Joined: Mon Oct 07, 2019 4:11 pm
Location: Norway

Check for game start?

Post by Ralzar » Thu Feb 06, 2020 7:37 am

I'm trying to find a way to run a method once, right after your character is created in Privateers Hold.
I might be able to do some kind of akward trick to make this happen, but I was wondering if anyone knew a straightforward way to just make the mod trigger at the same time as the intro/tutorial prompt?

I would take a look at code in existing mods, but the ones who do stuff at character start do it through quests. Except Ironman System, but that mod does a LOT of crazy reflection code stuff that is way beyond anything I want to mess with.
My released mods

"I feel like Ralzar specifically wrote those mods for me and then said "Use them". Just so he could watch me die more."
-FuzzyBeanPlays

User avatar
Kaedius
Posts: 38
Joined: Wed Apr 17, 2019 11:04 pm

Re: Check for game start?

Post by Kaedius » Thu Feb 06, 2020 10:02 am

Sounds like you are looking for the StartGameBehaviour.OnNewGame event! You can do something like the following:

Code: Select all

using DaggerfallWorkshop.Game.Utility;
using DaggerfallWorkshop.Game.Entity;

void Start()
{
	StartGameBehaviour.OnNewGame += () =>
	{
		PlayerEntity playerEntity = GameManager.Instance.PlayerEntity;

		DaggerfallUnityItem item = ItemBuilder.CreateArmor(playerEntity.Gender, playerEntity.Race, Armor.Boots, ArmorMaterialTypes.Adamantium);

		playerEntity.Items.AddItem(item);
	};
}
and it'll add to the players inventory at start. Check out ItemBuilder for sure if you haven't already, it has plenty of options.

User avatar
Ralzar
Posts: 815
Joined: Mon Oct 07, 2019 4:11 pm
Location: Norway

Re: Check for game start?

Post by Ralzar » Thu Feb 06, 2020 10:24 am

Thanks! That looks pretty close to what I was trying to do allready based on Ironmans code. But since his code hasn't been updated in quite some time I couldn't even be sure it was still correct for the live build. I was actually just taking some notes about StartGameBehaviour.cs to try when I got back home.

I allready have some code that works for adding/removing items, I just couldn't figure out how to make it run at startup.
Hm, now I just need ot figure out how to remove/add spells as well...
My released mods

"I feel like Ralzar specifically wrote those mods for me and then said "Use them". Just so he could watch me die more."
-FuzzyBeanPlays

User avatar
Hazelnut
Posts: 2006
Joined: Sat Aug 26, 2017 2:46 pm
Contact:

Re: Check for game start?

Post by Hazelnut » Fri Feb 07, 2020 10:00 am

Just be aware that this event is triggered when a classic save is loaded as well as when player starts a new character.

I think it would be better to expose AssignStartingGear and SetStartingSpells to be overridden by mods and do it properly. You would need to have patience for that work to happen before creating your mod however. I don't mind doing it if you have the patience. :)
See my mod code for examples of how to change various aspects of DFU: https://github.com/ajrb/dfunity-mods

User avatar
Ralzar
Posts: 815
Joined: Mon Oct 07, 2019 4:11 pm
Location: Norway

Re: Check for game start?

Post by Ralzar » Fri Feb 07, 2020 10:41 am

Hazelnut wrote:
Fri Feb 07, 2020 10:00 am
Just be aware that this event is triggered when a classic save is loaded as well as when player starts a new character.

I think it would be better to expose AssignStartingGear and SetStartingSpells to be overridden by mods and do it properly. You would need to have patience for that work to happen before creating your mod however. I don't mind doing it if you have the patience. :)
Yes please :)

I actually discovered that StartGameBehaviour.OnNewGame was not quitewhat I was after, since it ran the mod too early in the character creation. I found something similar that worked better that the Ironman mod used. (Not at the PC atm, so can't remember the exact code.)
I figured out how to use swtiches to add items based on skills, but I've yet to figure out a way to properly empty the inventory first. (Hopefully without removing items gained from character creation questions)
And then there's the whole spell book editing thing.
It's really finicky getting this to run right, and needs a lot of conditionals to work.

I'd much rather have mod access to the actual starting equipment and starting spell code :)


Edit: Btw, talking about exposing character creation stuff for modding. How much hassle would it be to be able to mod other parts of the character creation? Like the questions that give you Ebony Dagger, etc?
My released mods

"I feel like Ralzar specifically wrote those mods for me and then said "Use them". Just so he could watch me die more."
-FuzzyBeanPlays

Post Reply