Sovereignty: Crown of Kings

Sovereignty: Crown of Kings

View Stats:
Dad 28 Sep, 2016 @ 8:52am
Question on modding scripts
I was attempting to modify the Raider unit attribute script, but everytime I enable the mod and start a new game, it crashes after selecting a nation and hitting play. Tried a mod with an unmodified script in case it was a scripting error, but still crashes with the same error.
Any guidance appreciated. Thanks!

Posting the error below:


An error has occurred

User ID: 76561198028150522
Version Number: 2.1.1 build 1449
Flag type does not exist: CrushingBlow

at SovereigntyTK.Game.ActiveGameData.UnitFlag.CreateNamedFlag(Sovereignty Game, String Flagname) in c:\Users\Lord Jekky\Documents\Visual Studio 2012\Projects\SovereigntyTK\SovereigntyTK\Game\ActiveGameData\UnitFlag.cs:line 59
at SovereigntyTK.Game.ActiveGameData.WorkingUnit..ctor(SovereigntyGame Game, Int32 ID, UnitData BaseUnit) in c:\Users\Lord Jekky\Documents\Visual Studio 2012\Projects\SovereigntyTK\SovereigntyTK\Game\ActiveGameData\WorkingUnit.cs:line 310
at SovereigntyTK.Game.SovereigntyGame.CreateUnit(Int32 RealmID, UnitData UnitType) in c:\Users\Lord Jekky\Documents\Visual Studio 2012\Projects\SovereigntyTK\SovereigntyTK\Game\SovereigntyGame.cs:line 1187
at SovereigntyTK.Game.ActiveGameData.WorkingProvince..ctor(Int32 ID, Int32 OwnerID, SovereigntyGame Game, ProvinceData Data) in c:\Users\Lord Jekky\Documents\Visual Studio 2012\Projects\SovereigntyTK\SovereigntyTK\Game\ActiveGameData\WorkingProvince.cs:line 482
at SovereigntyTK.Game.SovereigntyGame.CreateProvinces() in c:\Users\Lord Jekky\Documents\Visual Studio 2012\Projects\SovereigntyTK\SovereigntyTK\Game\SovereigntyGame.cs:line 713
at SovereigntyTK.Game.SovereigntyGame.Init(String PlayerRealmName) in c:\Users\Lord Jekky\Documents\Visual Studio 2012\Projects\SovereigntyTK\SovereigntyTK\Game\SovereigntyGame.cs:line 198
at SovereigntyTK.Sovereignty.StartGame(String RealmName, CampaignBase Campaign, Boolean Ironman, String IronmanName) in c:\Users\Lord Jekky\Documents\Visual Studio 2012\Projects\SovereigntyTK\SovereigntyTK\Sovereignty.cs:line 373
at SovereigntyTK.UI.TitleForm.PlayClicked(UIControl Control)
at SovereigntyTK.UI.Controls.UIControl.HandleMouseClick(Single LocalX, Single LocalY, MouseButton Button) in c:\Users\Lord Jekky\Documents\Visual Studio 2012\Projects\SovereigntyTK\SovereigntyTK\UI\Controls\UIControl.cs:line 611
at SovereigntyTK.UI.Controls.ControlButton.HandleMouseClick(Single LocalX, Single LocalY, MouseButton Button) in c:\Users\Lord Jekky\Documents\Visual Studio 2012\Projects\SovereigntyTK\SovereigntyTK\UI\Controls\ControlButton.cs:line 81
at SovereigntyTK.UI.Controls.UIControl.HandleMouseUp(Single LocalX, Single LocalY, MouseButton Button) in c:\Users\Lord Jekky\Documents\Visual Studio 2012\Projects\SovereigntyTK\SovereigntyTK\UI\Controls\UIControl.cs:line 599
at SovereigntyTK.UI.Controls.ControlButton.HandleMouseUp(Single LocalX, Single LocalY, MouseButton Button) in c:\Users\Lord Jekky\Documents\Visual Studio 2012\Projects\SovereigntyTK\SovereigntyTK\UI\Controls\ControlButton.cs:line 207
at SovereigntyTK.UI.UIManager.Window_MouseUp(Object sender, MouseButtonEventArgs e) in c:\Users\Lord Jekky\Documents\Visual Studio 2012\Projects\SovereigntyTK\SovereigntyTK\UI\UIManager.cs:line 142
at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
at OpenTK.NativeWindow.OnMouseUp(MouseButtonEventArgs e) in c:\temp\opentk\Source\OpenTK\NativeWindow.cs:line 951
at OpenTK.NativeWindow.OnMouseUpInternal(Object sender, MouseButtonEventArgs e) in c:\temp\opentk\Source\OpenTK\NativeWindow.cs:line 1131
at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
at OpenTK.Platform.NativeWindowBase.OnMouseUp(MouseButton button) in c:\temp\opentk\Source\OpenTK\Platform\NativeWindowBase.cs:line 255
at OpenTK.Platform.Windows.WinGLNative.WindowProcedure(IntPtr handle, WindowMessage message, IntPtr wParam, IntPtr lParam) in c:\temp\opentk\Source\OpenTK\Platform\Windows\WinGLNative.cs:line 737
at OpenTK.Platform.Windows.Functions.DispatchMessage(MSG& msg)
at OpenTK.Platform.Windows.WinGLNative.ProcessEvents() in c:\temp\opentk\Source\OpenTK\Platform\Windows\WinGLNative.cs:line 1463
at SovereigntyTK.GameBase.Start() in c:\Users\Lord Jekky\Documents\Visual Studio 2012\Projects\SovereigntyTK\SovereigntyTK\GameBase.cs:line 295
at SovereigntyTK.Program.Main(String[] args) in c:\Users\Lord Jekky\Documents\Visual Studio 2012\Projects\SovereigntyTK\SovereigntyTK\Program.cs:line 86
< >
Showing 1-15 of 44 comments
Jekky 28 Sep, 2016 @ 9:57am 
There is a known issue in 2.1.1 - to get script mods working you have to include a copy of the entire scripts folder.

This issue will be fixed in 2.1.2
Dad 28 Sep, 2016 @ 2:27pm 
Thanks Jekky! Worked like a charm. :)
Dad 13 Oct, 2016 @ 8:21am 
Is there a way to unlock a unit for training when a building type is first built by a realm? What I am looking for is something along the lines of when a unit is enabled upon completing a quest objective, but instead tie the unit availability to a certain building type. Ideally, I would like to add a bit of code to existing buildings and enable a realm specific unit for training once the player has built that building.

Bad example, but if the player (or AI) builds a Vineyard:
If Sonneneve then enable "Drunken Elf"
If Elidon then enable "Wobbly Guard"
etc.
Jekky 13 Oct, 2016 @ 9:41am 
I think the best way to do such a thing would be to create a new Plugin script (Data\Scripts\Campaigns\Pluigins). These scripts contain little pieces of functionality which are shared by multiple realms, or are used in multiple campaigns.

First step is to create the unit in the editor - set it to be non-purchasable.

If you register for the "BuildingConstructed" event, you will be notified when any building gets built - you can then check to see if it is the first time for that realm, and use Realm.Restrictions.AllowUnits.Add("UnitName") to add the unit to the list of allowed units.
Dad 13 Oct, 2016 @ 8:19pm 
I am having trouble finding the arguments or an example of the BuildingConstructed event. I have browsed several of the existing scripts including other plugins, buildings and even several UI scripts related to buildings, but I am at a loss. I feel like it is probably obvious and I am just missing it. :)

Defined the class and registered the event. Below is what I have so far:

public class dad_BldgUnit_IronBarony: CampaignPlugin { public dad_BldgUnit_IronBarony(Sovereignty Game, bool NewGame) : base(Game, NewGame) { Game.RegisterEvent(evBldgConstructed, "BuildingConstructed"); } private void evBldgConstructed(MY MISSING ARGUMENTS) { }

Thanks again for your help!
Jekky 13 Oct, 2016 @ 8:37pm 
All events have the same parameters for the actual function definition, for this specific event though you would do something like this:

private void evBldgConstructed(string EventName, params object[] Args)
{
BuildingEffect Building = Args[0] as BuildingEffect;
//do stuff with Building
}
Dad 14 Oct, 2016 @ 11:32pm 
Almost there. Trying to find a way to determine which realm built the building.
For context, here is what I have:

using SovereigntyTK.Game.ActiveGameData; using SovereigntyTK.Game.Campaign; using SovereigntyTK.Game.Data; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using SovereigntyTK.Data.Scripts.Buildings; namespace SovereigntyTK.Data.Scripts.Campaigns.Plugins { public class dad_BldgUnit_IronBarony_RaidersCamp: CampaignPlugin { bool EventOccured; public dad_BldgUnit_IronBarony_RaidersCamp(Sovereignty Game, bool NewGame) : base(Game, NewGame) { Game.RegisterEvent(evBldgConstructed, "BuildingConstructed"); } private void evBldgConstructed(string EventName, params object[] Args) { BuildingEffect Building = Args[0] as BuildingEffect; WorkingRealm ThisRealm = *** WHO BUILT BUILDING? *** as WorkingRealm; WorkingRealm IronBarony = Game.CurrentGame.GetRealm("Iron Barony"); if (Building.BuildingName != "Raider's Camp") return; if (ThisRealm != IronBarony) return; // first time? if (EventOccured == true) return; // enable unit for training ThisRealm.Restrictions.AllowUnits.Add("Goblin Raiders"); EventOccured = true; } public override void Dispose() { Game.UnregisterEvent(evBldgConstructed, "BuildingConstructed"); base.Dispose(); } protected override int SaveData(System.IO.BinaryWriter w) { w.Write(EventOccured); return 0; } protected override void LoadData(System.IO.BinaryReader r) { EventOccured = r.ReadBoolean(); } } }


Edit:
I was able to determine if the player builds the building as Iron Barony, but not sure how to determine if AI builds the building as Iron Barony.


Thanks again for all of your help!
Last edited by Dad; 15 Oct, 2016 @ 6:02am
Jekky 15 Oct, 2016 @ 11:31am 
Building.Province.OwnerRealm would be the simplest way to determine who built it.
Jekky 15 Oct, 2016 @ 11:33am 
Also, the save function expects you to return the size of the saved data in bytes - if you return 0 it will fail to load the data correctly (it does this so that it can skip over any missing plugins while loading) - in this case you would do "return sizeof(bool);"
Dad 15 Oct, 2016 @ 4:45pm 
Script working! Next question:
When I try to add new game text in the editor, it creates lines in data.xml that appear to only want to update existing keys. Example below:

<Text> <Update Key="BLDG_UNIT_NAME1" TextKey="BLDG_UNIT_NAME1" english="Goblin Raiders" german=" " /> <Update Key="BLDG_UNIT_DESC1" TextKey="BLDG_UNIT_DESC1" english="Turns out the cowardly goblin fodder make quite voracious raiders." german=" " /> </Text>

This crashes the editor when I try to reload the mod until I manually remove the updates. I assume because it can't find an existing key to update. I tried playing around with tables and the <Additions> tags to no avail. Known issue?

Edit update:
The game plays fine, just the mod editor crashes. I will paste the error below.

************** Exception Text ************** System.Data.NoNullAllowedException: Column 'TextKey' does not allow nulls. at System.Data.DataColumn.CheckNullable(DataRow row) at System.Data.DataTable.RaiseRowChanging(DataRowChangeEventArgs args, DataRow eRow, DataRowAction eAction, Boolean fireEvent) at System.Data.DataTable.SetNewRecordWorker(DataRow row, Int32 proposedRecord, DataRowAction action, Boolean isInMerge, Boolean suppressEnsurePropertyChanged, Int32 position, Boolean fireEvent, Exception& deferredException) at System.Data.DataTable.InsertRow(DataRow row, Int64 proposedID, Int32 pos, Boolean fireEvent) at SovereigntyTools.TextCache.CreateDataTable() in c:\Users\Lord Jekky\Documents\Visual Studio 2012\Projects\SovereigntyTK\SovereigntyTools\TextCache.cs:line 212 at SovereigntyTools.Form1.PrepareTextTab() in c:\Users\Lord Jekky\Documents\Visual Studio 2012\Projects\SovereigntyTK\SovereigntyTools\Form1.cs:line 263 at SovereigntyTools.Form1.SetupInitialState() in c:\Users\Lord Jekky\Documents\Visual Studio 2012\Projects\SovereigntyTK\SovereigntyTools\Form1.cs:line 241 at SovereigntyTools.Form1.openModToolStripMenuItem_Click(Object sender, EventArgs e) in c:\Users\Lord Jekky\Documents\Visual Studio 2012\Projects\SovereigntyTK\SovereigntyTools\Form1.cs:line 330 at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e) at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e) at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e) at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e) at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met) at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met) at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea) at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.ToolStrip.WndProc(Message& m) at System.Windows.Forms.ToolStripDropDown.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Last edited by Dad; 15 Oct, 2016 @ 5:09pm
Jekky 15 Oct, 2016 @ 7:33pm 
I think that is something which the new patch should fix - there were a few editor issues like that. As you have discovered, only the editor is affected, and you can manually update the file.
Breca 23 Oct, 2016 @ 9:41pm 
Originally posted by Dad:
Is there a way to unlock a unit for training when a building type is first built by a realm? What I am looking for is something along the lines of when a unit is enabled upon completing a quest objective, but instead tie the unit availability to a certain building type. .

<----Like the concept!
Dad 24 Oct, 2016 @ 11:37am 
Thanks! So far I have 3 nations with 5 new units each.
Dad 9 Nov, 2016 @ 4:54pm 
How difficult would it be to create a unit flag "tax collector" that would function similar to the building of the same name? (So that whatever province the unit is in would generate income as if it was one province closer to the capital.)
Jekky 9 Nov, 2016 @ 5:06pm 
I expect tha would be fairly tricky to do.

Creating the flag wouldn't be too hard.. having it correctly apply the effect to the province where the unit is located would be harder.

If i were creating this flag, i would track the Unit.OnStackChanged which takes 2 Stacks as parameters - the new one and the old one.

Using the Stacks I would then determine which province the unit was in and which unit it is now in - removing the effect from one and applying it to the other.

The hardest part would be preventing the effect from stacking if more than one unit is in the province - assuming you don't want the effect to stack of course. I can't think of an easy way to do that currently.
< >
Showing 1-15 of 44 comments
Per page: 1530 50