Xcomhadrian Posted February 23, 2016 Share Posted February 23, 2016 Hello peeps, me again. After some stellar advice and fiddling a bit with my code, I almost have my project up to a level I am happy with. The thing I have to do now is apparently add a custom function to my weapon schematic to make it add the item to the inventory instead of updating an existing item (updating items is causing a bug atm). Now I know a lot of you peeps are far more skilled than I at coding, and I would assume that someone else has already figured this out. So can someone show me some code I can add to my schematic that will, when its built, add my weapon to the inventory for usage? Much obliged. Link to comment Share on other sites More sharing options...
davidlallen Posted February 23, 2016 Share Posted February 23, 2016 Isn't that what the example weapon mod does in the sdk? Link to comment Share on other sites More sharing options...
Xcomhadrian Posted February 23, 2016 Author Share Posted February 23, 2016 (edited) No the example mod doesn't use a schematic, just a weapon template. Edited February 23, 2016 by Xcomhadrian Link to comment Share on other sites More sharing options...
davidlallen Posted February 23, 2016 Share Posted February 23, 2016 The operative part of this mod adds an item to the armory:http://www.nexusmods.com/xcom2/mods/163/It does that using XComGameState_HeadquartersXcom::AddToCrew. There is a similar function AddResource in that file, which appears to add to the inventory. Maybe that one? Link to comment Share on other sites More sharing options...
Xcomhadrian Posted February 23, 2016 Author Share Posted February 23, 2016 (edited) Yeah sorry that mod doesn't help. I already have it here and its not much of a help tbh. The finite armory mod has been more helpful but Im still stuck. Finite armory has this code which I think might be applicable; function Kv_OnSchematicBuiltFn(XComGameState NewGameState, XComGameState_Item ItemState) { local XComGameStateHistory History; local XComGameState_HeadquartersXCom XComHQ; local X2ItemTemplateManager ItemTemplateManager; local X2ItemTemplate ItemTemplate; local X2SchematicTemplate SchematicTemplate; local XComGameState_Item NewItemState; local int numExistingItems; History = `XCOMHISTORY; ItemTemplateManager = class'X2ItemTemplateManager'.static.GetItemTemplateManager(); // Set up HQ gamestate to work with foreach NewGameState.IterateByClassType(class'XComGameState_HeadquartersXCom', XComHQ) { break; } if (XComHQ == none) { XComHQ = XComGameState_HeadquartersXCom(History.GetSingleGameStateObjectForClass(class'XComGameState_HeadquartersXCom')); XComHQ = XComGameState_HeadquartersXCom(NewGameState.CreateStateObject(class'XComGameState_HeadquartersXCom', XComHQ.ObjectID)); NewGameState.AddStateObject(XComHQ); } // Get the template data of the schematic that was just built. SchematicTemplate = X2SchematicTemplate(ItemState.GetMyTemplate()); // Get the template of the schematic's reference item. This is the actual equippable item that the schematic template refers to. ItemTemplate = ItemTemplateManager.FindItemTemplate(SchematicTemplate.ReferenceItemTemplate); if (ItemTemplate == none) { `KvCLog("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ No item template named" @ SchematicTemplate.ReferenceItemTemplate @ "was found."); return; } numExistingItems = XComHQ.GetNumItemInInventory(ItemTemplate.DataName); if(numExistingItems > 0) { NewItemState = XComHQ.GetItemByName(ItemTemplate.DataName); } else { NewItemState = ItemTemplate.CreateInstanceFromTemplate(NewGameState); XComHQ.PutItemInInventory(NewGameState, NewItemState); } // Add 1 of the item (not the schematic) to the HQ inventory NewItemState.Quantity = numExistingItems + 1; NewGameState.AddStateObject(NewItemState); } But I dont what to cut out and/or change to make it work properly. :/ Edited February 23, 2016 by Xcomhadrian Link to comment Share on other sites More sharing options...
Xcomhadrian Posted February 24, 2016 Author Share Posted February 24, 2016 Anyone? Im really stuck here. Either my template bugs out and spits out the wrong weapon with the standard "upgradeitem" function. Or I cant get it to spawn an item if I remove upgradeitem. Please help, this is the linchpin of my mod. Without a working template I cant get my research to run properly, or update the armory. Link to comment Share on other sites More sharing options...
Recommended Posts