Author Topic: How to use ship.SetEquipmentCacheValue?  (Read 4158 times)

ninekorn

  • Full Member
  • ***
  • Posts: 231
    • View Profile
How to use ship.SetEquipmentCacheValue?
« on: August 01, 2017, 08:15:16 pm »
Hi,
This question is for my follower/drone mod. I want to be able to modify their damage output. If I add    IMCache.AddValue("projectile_damage_energy_weap ons_instancepercent", 1000); in the calculateShip.js script my follower/drones do a lot of damage. The thing is this parameter wasnt there to start off. I added it just to try it and it works. Now i'm wondering if i can have access to that parameter through another script with ship.SetEquipmentCacheValue?. I might be going the wrong way with this but also wanted to know: is there a list of parameters that we can assign to IMCache for weapons/items and can we have that list? This parameter "projectile_damage_energy_weap ons_instancepercent" is something i found in the skills in the .XML files. With this type of parameters I have a couple ideas on how to fake Equipment changes to my follower/drone mod.

Thank you for answering.
nine

Edit: Is there also in the Scripting API a way to "ship.getequipment" for the NPCs? and like "ship.setequipment". Im asking coz it would be way easier than having to generate thousands of XML files with my xml file generator program I created especially if NPCS are generated and geared with different weapons when they have more than 1 weapon slots. I would have 10 times more drones xml files than weapons xml files.
« Last Edit: August 01, 2017, 08:20:27 pm by ninekorn »

ai_enabled

  • AtomicTorch Founder
  • Hero Member
  • *****
  • Posts: 2018
    • View Profile
Re: How to use ship.SetEquipmentCacheValue?
« Reply #1 on: August 01, 2017, 11:11:34 pm »
Hello,
unfortunately, for NPCs weapons are mapped directly from NPC XML, there is no way to change NPC weapons from scripting.
So, it makes sense to make a few NPC XMLs with particular weapons (per weapon type, multiple tiers). Giving too much choice to the player is something I would recommend to avoid as it might easily overwhelm the player. Consider having only a few presets for drones, the code generation for it is overcomplication and simply abusing the idea of XML's.

But you can modify NPC shield stats/properties, such as damage - as you found out, with the IMCache.
It's not recommended for mods to call ship.SetEquipmentCacheValue() - this method is intended to be used only by IMCache when it calculates "ship cache" (it combines stat values and bonuses from various sources and then applies them with ship.SetEquipmentCacheValue()). If you call this method directly you will overwrite the value set by IMCache (and if IMCache calculated any time later, it will overwrite your custom value). It's better to simply provide these values to IMCache instead. As you wrote, there is the CalculateShip.js script - and I think modifying it is the best way to do this.

ninekorn

  • Full Member
  • ***
  • Posts: 231
    • View Profile
Re: How to use ship.SetEquipmentCacheValue?
« Reply #2 on: August 01, 2017, 11:31:55 pm »
Ok thanks for the answer. But how would I go about calling the function with "args" for example i need to include IMCache.js and CalculateShip.js. Then I call calculateShip.CalculateNpcLev eledCache(SHIP_ID?) with the ship ID as args?

ai_enabled

  • AtomicTorch Founder
  • Hero Member
  • *****
  • Posts: 2018
    • View Profile
Re: How to use ship.SetEquipmentCacheValue?
« Reply #3 on: August 02, 2017, 12:04:54 am »
Well it's not that simple... CalculateShip.js itself subscribing to OnCalculateNpcLeveledCache event:
Code: [Select]
actions.Bind("OnCalculateNpcLeveledCache", "CalculateNpcLeveledCache");I think the easiest way for you will be to modify CalculateShip.js (yes, it's hacky way...).

Another way is to create a new script, also bind to "OnCalculateNpcLeveledCache" and have your custom callback method for it (just copy CalculateNpcLeveledCache code from CalculateShip.js and modify for your needs). But it will work properly only in the case if OnCalculateNpcLeveledCache first handled by CalculateShip.js and then by your script. We don't have any API to setup callbacks priority, so you can try it and see if your method called after CalculateShip.js.

ninekorn

  • Full Member
  • ***
  • Posts: 231
    • View Profile
Re: How to use ship.SetEquipmentCacheValue?
« Reply #4 on: July 02, 2019, 12:42:22 am »
ai_enabled? Do you have an explanation for the nodes:

<upgrades_max>10</upgrades_max>
<upgrades>
</upgrades>

If I do this below, it doesn't crash the game as if maybe it was made for that? But how to activate or upgrade the item ingame?:
      
<upgrades_max>10</upgrades_max>
<upgrades>
     <effects>
      <effect>
         <effect_type>speed_max_value</effect_type>
         <effect_base>400</effect_base>
      </effect>
     </effects>
</upgrades>


I tried those functions here without luck:

//var upgrades0 = game.GetItemUpgrade(shipItems);
//var upgrades1 = game.GetItemUpgrades(shipItems);
//var upgrades2 = game.GetItemLevel(shipItems);
//var upgrades3 = game.GetItemLevels(shipItems);
//var test0=  items.GetItemUpgrade(items);
//var test1 = items.GetItemUpgrades(items);
//var test2 = items.GetItemLevel(items);
//var test3 = items.GetItemLevels(items);
//var test0=  items.GetItemsUpgrade(items);
//var test1 = items.GetItemsUpgrades(items);
//var test2 = items.GetItemsLevel(items);
//var test3 = items.GetItemsLevels(items);
//var test0=  game.GetItemsUpgrade(items);
//var test1 = game.GetItemsUpgrades(items);
//var test2 = game.GetItemsLevel(items);
//var test3 = game.GetItemsLevels(items);

//var test3 = items.GetItemData(items);
//var test3 = items.GetItemsData(items);



EDIT: I can put pretty much any type of string inside the node <upgrades> and the game won't crash. It's as if whatever data that the node contains, it's nullified or discarded in the core engine. maybe it is, maybe it's not.
« Last Edit: July 02, 2019, 02:43:23 am by ninekorn »

ai_enabled

  • AtomicTorch Founder
  • Hero Member
  • *****
  • Posts: 2018
    • View Profile
Re: How to use ship.SetEquipmentCacheValue?
« Reply #5 on: July 02, 2019, 01:43:39 pm »
Hello!

"upgrades"  and "upgrades_max" are actually not used by the game at all! They're just artifacts from something...I suppose you found them in one of the XML item definitions?

Regards!

ninekorn

  • Full Member
  • ***
  • Posts: 231
    • View Profile
Re: How to use ship.SetEquipmentCacheValue?
« Reply #6 on: July 02, 2019, 02:42:30 pm »
Yeah ai_enabled. Im halfway through building the "infinite" with procedural "icon" generator starting with the Engines items. So players will visually see different icons for each engine parts that they wish to get in the shop. Also, the icon visually will display the color of the engine "trail" so that players dont need to necessarily read what color the trail is, instead they will see it.

The thing is I stumbled upon the upgrades node and wanted to know if it was something i could incorporate in the item generator.

I will find another way with Global Variables. Anyways, upgrades are so much so the same thing as "passive skills". Im gonna think of something.



ai_enabled

  • AtomicTorch Founder
  • Hero Member
  • *****
  • Posts: 2018
    • View Profile
Re: How to use ship.SetEquipmentCacheValue?
« Reply #7 on: July 02, 2019, 03:36:44 pm »
Ok, good luck!

ninekorn

  • Full Member
  • ***
  • Posts: 231
    • View Profile
Re: How to use ship.SetEquipmentCacheValue?
« Reply #8 on: July 02, 2019, 10:30:55 pm »
ai_enabled, when you have the chance, can you also confirm that the node <durability> is also useless for the moment?

ai_enabled

  • AtomicTorch Founder
  • Hero Member
  • *****
  • Posts: 2018
    • View Profile
Re: How to use ship.SetEquipmentCacheValue?
« Reply #9 on: July 03, 2019, 04:43:08 pm »
It's decorated with
Code: [Select]
[Obsolete("NOT USED")]Sounds like it was never used or never implemented completely.
:-)

ninekorn

  • Full Member
  • ***
  • Posts: 231
    • View Profile
Re: How to use ship.SetEquipmentCacheValue?
« Reply #10 on: July 05, 2019, 10:07:47 am »
Ok thank you ai_enabled!