Jump to content

custom function to add item instead of upgrade?


Recommended Posts

Posted

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.

Posted (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 by Xcomhadrian
Posted

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.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...