[How to] Get each specific NPC (on platform) inventory prices?
Moderators: Moderators for English X Forum, Scripting / Modding Moderators
-
- Posts: 115
- Joined: Wed, 30. Oct 13, 16:38
-
- Posts: 115
- Joined: Wed, 30. Oct 13, 16:38
Takin a break from smashing my head against engineer.ai I decided to take a look into this.
It looks like the script takes a created actor, populates his trade list, generating prices for each item as it goes then stores them as parameters within the actor, then erasing them from the script one second later. Due to this you will need to either capture the values as they are being generated or use an outside script to poll the actors on the station for their wares/price list.
for option one you might do something like this
problem here is you need a way to clean up the list or it'll just keep growing.
Maybe a separate script that polls the station for actors and reads from their parameter lists would work better but you'd still have a lot of data to display.
It looks like the script takes a created actor, populates his trade list, generating prices for each item as it goes then stores them as parameters within the actor, then erasing them from the script one second later. Due to this you will need to either capture the values as they are being generated or use an outside script to poll the actors on the station for their wares/price list.
for option one you might do something like this
Code: Select all
<cues>
<cue name="Platform_TraderHandlerRef" ref="TraderHandler">
<param name="actor" value="$actor"/>
<param name="EngineUpgradesList" value="$EngineUpgradesList"/>
<param name="ShieldUpgradesList" value="$ShieldUpgradesList"/>
<param name="WeaponUpgradesList" value="$WeaponUpgradesList"/>
<param name="ScannerUpgradesList" value="$ScannerUpgradesList"/>
<param name="SoftwareUpgradesList" value="$SoftwareUpgradesList"/>
(add upgradelists to master ware list)
</cue>
Maybe a separate script that polls the station for actors and reads from their parameter lists would work better but you'd still have a lot of data to display.
-
- Posts: 83
- Joined: Sun, 22. Aug 10, 13:55
Hello,
Here is the solution, kindly offered by Xenon_Slayer (aka Owen Lake) from [ external image ] by PM this morning
Thanks again Owen,
Regards,
ybeline
Here is the solution, kindly offered by Xenon_Slayer (aka Owen Lake) from [ external image ] by PM this morning

I'll surely experiment over it in the hours to come.Xenon_Slayer (aka Owen) wrote:Hi,
Yeah, I see what the problem is. You'll have to look in the md script NPC_Upgradetrader.xml
The problem is that the prices are stored in there. The good thing is that you can modify that script so that the values are also stored on the NPC too.
Look for the library <library name="TraderHandler">
In its cues node add:These lists are made up of a list containing the ware id and price. e.g.Code: Select all
<cue name="SaveListsToNPC"> <actions> <set_value name="$actor.$EngineUpgradesList" exact="$EngineUpgradesList"/> <set_value name="$actor.$ShieldUpgradesList" exact="$ShieldUpgradesList"/> <set_value name="$actor.$WeaponUpgradesList" exact="$WeaponUpgradesList"/> <set_value name="$actor.$ScannerUpgradesList" exact="$ScannerUpgradesList"/> <set_value name="$actor.$SoftwareUpgradesList" exact="$SoftwareUpgradesList"/> </actions> </cue>
[ [ware.upg_pla_shield_bal_mk1.id, 30000Cr], [ware.upg_pla_shield_bal_mk3.id, 50000Cr] ]
So, you'll have to loop through the outer list to get to the list containing the wareID and price. Note, the wareID is just a string, it will need to be converted back into a ware value.
In a loop you can do that with:
ware.{$EngineUpgradesList.{$Counter}.{1}}
$EngineUpgradesList.{$Counter}.{1} is the wareID, ware.{ } allows you to turn a wareID into a ware. You can then use .name and other properties.
$EngineUpgradesList.{$Counter}.{2} is the price.
Hope that helps.
Owen
Thanks again Owen,
Regards,
ybeline
-
- Posts: 83
- Joined: Sun, 22. Aug 10, 13:55
Hello again,
For the record, the following code is totally properly working:
\md\NPC_Upgradetrader.xml allows to store ware prices:
\md\OnPlatform_Upgradetraders_Prices.xml allows to get Mechanic wares and their prices for each Mechanic on platform:
And then, if you want the price of the first item of the first Mechanic aboard:
$Upgradetrader_OnPlatform.{1}.$EngineUpgradesList.{1}.{2}
This can be expanded to any type of trader by modifying the right NPC_xxxx.xml.
About that price, if you can buy the ware from the Mechanic for 11 Cr and sell it for 9 Cr, then the price that you get with this code is: (9+11)/2=10.
It's half the sum of buying and selling prices.
I still haven't found inside the code the mysterious constant that links the buying and the selling prices of a ware, maybe it's hardcoded.
But it seems that it is: (buying price)/(selling price) = 90,48%.
Any idea about that ratio?
Thanks,
Regards,
ybeline
For the record, the following code is totally properly working:
\md\NPC_Upgradetrader.xml allows to store ware prices:
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<diff>
<add sel="/mdscript/cues/library[@name='TraderHandler']/cues">
<cue name="SaveListsToNPC">
<actions>
<set_value name="$actor.$EngineUpgradesList" exact="$EngineUpgradesList" />
<set_value name="$actor.$ShieldUpgradesList" exact="$ShieldUpgradesList" />
<set_value name="$actor.$WeaponUpgradesList" exact="$WeaponUpgradesList" />
<set_value name="$actor.$ScannerUpgradesList" exact="$ScannerUpgradesList" />
<set_value name="$actor.$SoftwareUpgradesList" exact="$SoftwareUpgradesList" />
</actions>
</cue>
</add>
</diff>
\md\OnPlatform_Upgradetraders_Prices.xml allows to get Mechanic wares and their prices for each Mechanic on platform:
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<mdscript name="OnPlatform_Upgradetraders_Prices">
<cues>
<cue name="OnPlatform_Upgradetraders_Prices_Main" instantiate="true" namespace="this">
<conditions>
<event_object_changed_room object="player.entity" />
<check_value value="player.platform" />
</conditions>
<actions>
<include_actions ref="Get_OnPlatformNPCs" />
</actions>
</cue>
<library name="Get_OnPlatformNPCs" namespace="this">
<actions>
<find_object_component name="$Upgradetrader_OnPlatform" object="player.platform" multiple="true" class="class.npc" entitytype="entitytype.upgradetrader" />
</actions>
</library>
</cues>
</mdscript>
And then, if you want the price of the first item of the first Mechanic aboard:
$Upgradetrader_OnPlatform.{1}.$EngineUpgradesList.{1}.{2}
This can be expanded to any type of trader by modifying the right NPC_xxxx.xml.
About that price, if you can buy the ware from the Mechanic for 11 Cr and sell it for 9 Cr, then the price that you get with this code is: (9+11)/2=10.
It's half the sum of buying and selling prices.
I still haven't found inside the code the mysterious constant that links the buying and the selling prices of a ware, maybe it's hardcoded.
But it seems that it is: (buying price)/(selling price) = 90,48%.
Any idea about that ratio?
Thanks,
Regards,
ybeline
-
- Posts: 83
- Joined: Sun, 22. Aug 10, 13:55
Hello,
Here is also how to get prices of wares of NPCs that have the entitytype of itemtrader (Arms Dealer, Drone Dealer, Licence Broker, Ship Dealer, Mining Supplier, Junk Dealer, ...).
Create in your mod: \md\NPC_Itemtrader.xml:
For example, for Black Marketeers, you can ask:
This last request gives you the 'middle price' (half of the sum of the selling and the buying price) of the first ware in the inventory of the first Black Marketeers on your platform.
Hope that can help futur modders
Regards,
ybeline
Edit#01:
Example with a picture
Here is also how to get prices of wares of NPCs that have the entitytype of itemtrader (Arms Dealer, Drone Dealer, Licence Broker, Ship Dealer, Mining Supplier, Junk Dealer, ...).
Create in your mod: \md\NPC_Itemtrader.xml:
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<diff>
<add sel="/mdscript/cues/cue[@name='OnPlatformPopulation_Itemtrader']/cues">
<!-- Example structure of $WareList:
[ [ware.inv_hazardouswaste.id, price],
[ware.inv_spaceflies.id , price],
[ ........................ , .... ] ]-->
<cue name="SaveLists_Itemtraders">
<actions>
<set_value name="$actor.$WareList" exact="$WareList" />
</actions>
</cue>
</add>
</diff>
For example, for Black Marketeers, you can ask:
Code: Select all
<find_object_component name="$BlackMarketeers_OnPlatform"
object="player.platform"
multiple="true"
class="class.npc"
entitytype="entitytype.shadyguy" />
Code: Select all
$BlackMarketeers_OnPlatform.{1}.$WareList.{1}.{2}
Hope that can help futur modders

Regards,
ybeline
Edit#01:
Example with a picture
Last edited by ybeline on Sun, 24. Nov 13, 20:29, edited 2 times in total.
-
- Moderator (Script&Mod)
- Posts: 14571
- Joined: Sun, 20. Nov 05, 22:45
i think there are possibly many people who may be interested in that. i think we should make a "library" from this and let Extensions which need these lines of code depend on this.. because i think it would be bad to add this code snippet multiple times to the seme md-script..ybeline wrote:Create in your mod: \md\NPC_Itemtrader.xml:Code: Select all
<?xml version="1.0" encoding="utf-8"?> <diff> <add sel="/mdscript/cues/cue[@name='OnPlatformPopulation_Itemtrader']/cues"> <!-- Example structure of $WareList: [ [ware.inv_hazardouswaste.id, price], [ware.inv_spaceflies.id , price], [ ........................ , .... ] ]--> <cue name="SaveLists_Itemtraders"> <actions> <set_value name="$actor.$WareList" exact="$WareList" /> </actions> </cue> </add> </diff>
if not stated otherwise everything i post is licensed under WTFPL
Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter
I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help
Ich mache keine S&M-Auftragsarbeiten, aber wenn es fragen gibt wie man etwas umsetzen kann helfe ich gerne weiter

I wont do Script&Mod Request work, but if there are questions how to do something i will GLaDly help

-
- Posts: 83
- Joined: Sun, 22. Aug 10, 13:55
Hello,
Here is an example (with a picture) of what can be done:
[ external image ]
By the way, in $WareList, there are every possible items that the NPC can sell, not only those that the NPC has in stock. Indeed, as you can see, in the code, I request for the second item in the list, but in game, it is the first 
Regards,
ybeline
Here is an example (with a picture) of what can be done:
[ external image ]
Code: Select all
<show_help force="true" duration="30s"
custom="'%1,%2,%3,%4,%5'.[$BlackMarketeers_OnPlatform.{4}.name,
ware.{$BlackMarketeers_OnPlatform.{4}.$WareList.{2}.{1}}.name,
$BlackMarketeers_OnPlatform.{4}.inventory.{ware.{$BlackMarketeers_OnPlatform.{4}.$WareList.{2}.{1}}}.count,
$BlackMarketeers_OnPlatform.{4}.$WareList.{2}.{2} * 95 / 10000,
$BlackMarketeers_OnPlatform.{4}.$WareList.{2}.{2} * 105 / 10000]" />

Why would it be bad? And what do you mean by "making a library"?UniTrader wrote:i think there are possibly many people who may be interested in that. i think we should make a "library" from this and let Extensions which need these lines of code depend on this.. because i think it would be bad to add this code snippet multiple times to the seme md-script..
Regards,
ybeline