Jump to content

Custom Attachment Script. Need help/feedback.


E3245

Recommended Posts

Hello everyone,

 

I'm trying to get this script for custom attachments to work. It compiles without any problems in Modbuddy, but when I run the game, it doesn't show up. I think I'm missing something here. I've added it to the X2DownloadableContentInfo, but it still doesn't show up.

 

Here's the script in question. I put it inside the spoiler tag since it was big:

 

X2Items_M16_Upgrades:

 

  Reveal hidden contents

 

 

X2DownloadableContentInfo_BlackOpsWeaponM16:

 

  Reveal hidden contents

 

Link to comment
Share on other sites

First, make sure that you load a save which was created before enabling the mod, otherwise OnLoadedSaveGame() won't work. I'd also put a log statement there somewhere to see if it runs at all; because people have reported having strange issues with this function.

 

Second, not sure about Templates but you can't do something like this:

//Make the changes to the HQ state. Here we add items to the HQ's inventory
ItemTemplate = ItemMgr.FindItemTemplate('BOM16');
ItemTemplate = ItemMgr.FindItemTemplate('CritUpgrade_M16');
ItemTemplate = ItemMgr.FindItemTemplate('AimUpgrade_M16');
ItemTemplate = ItemMgr.FindItemTemplate('ClipSizeUpgrade_M16');
ItemTemplate = ItemMgr.FindItemTemplate('ReloadUpgrade_M16');

This will only pick up the last ItemTemplate, so theoretically, ReloadUpgrade should've been present ???

I'd probably replace ItemTemplate with X2WeaponUpgradeTemplate. And you need to instantiate each one separately and add it to XcomHQState.

local X2WeaponUpgradeTemplate WeponUpgradeTemplate;

// .. skip

WeaponUpgradeTemplate = X2WeaponUpgradeTemplate(ItemMgr.FindItemTemplate('BOM16'));
ItemState = WeaponUpgradeTemplate.CreateInstanceFromTemplate(NewGameState);
NewGameState.AddStateObject(ItemState);
NewXComHQState.AddItemToHQInventory(ItemState);	

// next template

WeaponUpgradeTemplate = X2WeaponUpgradeTemplate(ItemMgr.FindItemTemplate('CritUpgrade_M16'));
ItemState = WeaponUpgradeTemplate.CreateInstanceFromTemplate(NewGameState);
NewGameState.AddStateObject(ItemState);
NewXComHQState.AddItemToHQInventory(ItemState);

^ this is just to illustrate. Obviously, it would be better to create some sort of FOR loop to handle it.

Edited by CaveRat
Link to comment
Share on other sites

Thanks for pointing me in the right direction. This is all new to me, so bear with me. Here's what I've come up with.

ItemTemplateNumber = 0;
 
//Start of the Switch. To add more items, you must make a new case number from the last case, and add your ItemTemplate. Example:
//case 5:
// ItemTempate = ItemMgr.FindItemTemplate('YourItemTemplateName');
// goto AddItemtoHQInventory;
//#######################################################################
//# NOTE: LEAVING OUT THE goto COMMAND WILL CAUSE THIS SCRIPT TO BREAK! #
//#######################################################################

StartLoop:
switch (ItemTemplateNumber)
{
case 0:
ItemTemplate = ItemMgr.FindItemTemplate('BOM16');
`log("Adding M16 to HQ Inventory");
goto AddItemtoHQInventory;

case 1:
ItemTemplate = ItemMgr.FindItemTemplate('CritUpgrade_M16');
`log("Adding M16A1 Red Dot Sight to HQ Inventory");
goto AddItemtoHQInventory;

case 2:
ItemTemplate = ItemMgr.FindItemTemplate('AimUpgrade_M16');
`log("Adding M16A1 ACOG Scope to HQ Inventory");
goto AddItemtoHQInventory;

case 3:
ItemTemplate = ItemMgr.FindItemTemplate('ClipSizeUpgrade_M16');
`log("Adding M16A1 Extended Magazine to HQ Inventory");
goto AddItemtoHQInventory;

case 4:
ItemTemplate = ItemMgr.FindItemTemplate('ReloadUpgrade_M16');
`log("Adding M16A1 Dual Magazines to HQ Inventory");
goto AddItemtoHQInventory;

default:
goto EndScript;
break;
}

//Loop Function
AddItemtoHQInventory:
//label
`log( "Adding Item to HQ Inventory" );

for( ItemTemplateNumber=ItemTemplateNumber; ItemTemplateNumber<5; ItemTemplateNumber++ )
{
ItemState = ItemTemplate.CreateInstanceFromTemplate(NewGameState);
NewGameState.AddStateObject(ItemState);
NewXComHQState.AddItemToHQInventory(ItemState);
ItemTemplateNumber++;
goto StartLoop;
}
`log( "All done.");
 
EndScript: 
//Instantiate a new item state object using the template.
//Try to create a loop function for every Item Template that exist
//ItemState = ItemTemplate.CreateInstanceFromTemplate(NewGameState);
//NewGameState.AddStateObject(ItemState);
 
//Add the newly created item to the HQ inventory
//NewXComHQState.AddItemToHQInventory(ItemState); 
 
//Commit the new HQ state object to the state change that we built
NewGameState.AddStateObject(NewXComHQState);
 
//Commit the state change into the history.
History.AddGameStateToHistory(NewGameState);
`log( "Script has completed. Can't log errors yet.");


Kinda nasty, but it should get the job done. It compiles without any issues, so I'm hoping that this doesn't break the game. I'm wondering though, should I add the NewGameState.AddStateObject(NewXComHQState) and the History.AddGameStateToHistory(NewGameState) to the loop as well? Or leave it outside the loop?

Edited by E3245
Link to comment
Share on other sites

@E3245, I've never seen GoTo and Labels used outside Actor state coding. You might wanna check Unreal Script reference.

 

https://udn.epicgames.com/Three/UnrealScriptReference.html

 

I would've probably done something like this:

 

 

  Reveal hidden contents

 

Link to comment
Share on other sites

  • Recently Browsing   0 members

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