[How to] Get each specific NPC (on platform) inventory prices?

The place to discuss scripting and game modifications for X Rebirth.

Moderators: Moderators for English X Forum, Scripting / Modding Moderators

User avatar
ybeline
Posts: 83
Joined: Sun, 22. Aug 10, 13:55
x4

[How to] Get each specific NPC (on platform) inventory prices?

Post by ybeline »

Hello,



Edit#03
Example of solution for Mechanic
Example of solution for NPCs that have the entitytype of itemtrader



Edit#02

Here is the solution, kindly offered by Xenon_Slayer (aka Owen Lake) from [ external image ] by PM :)
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:

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>
These lists are made up of a list containing the ware id and price. e.g.
[ [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


Edit#01

I invite you to go directly to this post.



Original post

I'm writing a bit of code to get this information:

- each time I dock to a landing platform, display the list of the NPCs inside (name/inventory/prices)

Code: Select all

<mdscript name="ATIS" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="C:\Users\Tim\Desktop\X Rebirth - Modding\My Mods\md.xsd">

  <cues>
    
    <cue name="Test_ATIS" 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="$NPCs_OnPlatform" object="player.platform" multiple="true" class="class.npc" />
        <show_help force="true" custom="'%1'.[$NPCs_OnPlatform]" />
        <remove_value name="$NPCs_OnPlatform"/>
      </actions>
    </library>

  </cues>
  
</mdscript>

This is what is displayed onscreen once docked:

Code: Select all

[component.{0xa59L}, component.{0xa62L}, ...]
Where '...' is a lot of 'component'.



What is the syntax to get all the info attached to each of those components?



Thanks,

Regards,

ybeline
Last edited by ybeline on Sun, 24. Nov 13, 01:36, edited 10 times in total.
User avatar
Jack08
Posts: 2993
Joined: Sun, 25. Dec 05, 10:42
x3tc

Post by Jack08 »

use the scriptproperty.html file to get the variable names, to retrieve them you use $component.variable, for example, $component.ship would give you the ship that component a part of.

makes sure you open that html in IE, apparently Firefox works too. chrome does not.

also, the value you have there is a list, you need to iterate over it if you want to do something for each component.
User avatar
ybeline
Posts: 83
Joined: Sun, 22. Aug 10, 13:55
x4

Post by ybeline »

Hello Jack08,
Jack08 wrote:use the scriptproperty.html file to get the variable names
This is a tool that I always have open :-)

So, for example:
We have: $NPCs_OnPlatform = [component.{0xa59L}, component.{0xa62L}, ...]
If I want to access to 'component.{0xa59L}', I simply ask for: $NPCs_OnPlatform.{1}, true?

Thanks,

Regards,

ybeline
User avatar
Jack08
Posts: 2993
Joined: Sun, 25. Dec 05, 10:42
x3tc

Post by Jack08 »

Yes, exactly.

<set_value name="$AnNPC" exact="$NPCs_OnPlatform.{1}"/>
User avatar
ybeline
Posts: 83
Joined: Sun, 22. Aug 10, 13:55
x4

Post by ybeline »

I have difficulties to access the list of wares and their prices/quantities.

<show_help force="true" custom="'%1'.[$NPCs_OnPlatform.{1}.typename]" />
This gives me the type of the first NPC in the list: it's a mechanic.

A mechanic sells a lot of wares.

Well, if I ask for:
<show_help force="true" custom="'%1'.[$NPCs_OnPlatform.{1}.inventory.list]" />
Nothing appears :-(
UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader »

what does it return for .inventory only without list?
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 ;)
User avatar
ybeline
Posts: 83
Joined: Sun, 22. Aug 10, 13:55
x4

Post by ybeline »

<show_help force="true" custom="'%1'.[$NPCs_OnPlatform.{1}.inventory]" /> returns: null
Xenon_Slayer
EGOSOFT
EGOSOFT
Posts: 13124
Joined: Sat, 9. Nov 02, 11:45
x4

Post by Xenon_Slayer »

.inventory alone will not return anything.
Come watch me on Twitch where I occasionally play several of the X games
User avatar
ybeline
Posts: 83
Joined: Sun, 22. Aug 10, 13:55
x4

Post by ybeline »

$NPCs_OnPlatform.{1}: OxA59 (or 0xA59, I can't easily read)
$NPCs_OnPlatform.{1}.typename: Mechanic
$NPCs_OnPlatform.{1}.inventory: null
$NPCs_OnPlatform.{1}.inventory.{1}: null
$NPCs_OnPlatform.{1}.inventory.list: no display
$NPCs_OnPlatform.{1}.inventory.list.{1}: Equalized Engine Mk1

I'm using <show_help /> for display purposes.
UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader »

ah, ok.. well in this case my usual approch of shortening if something doeesnt work until i get something that makes sense doesnt work..

and @ybeline i think you need .inventory.list.count
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 ;)
User avatar
ybeline
Posts: 83
Joined: Sun, 22. Aug 10, 13:55
x4

Post by ybeline »

Well, I've done some tests:

$NPCs_OnPlatform.{1}: 0xA59
$NPCs_OnPlatform.{1}.id: null
$NPCs_OnPlatform.{1}.name: Haruka Lieberwitz
$NPCs_OnPlatform.{1}.knownname: Haruka Lieberwitz
$NPCs_OnPlatform.{1}.description: null
$NPCs_OnPlatform.{1}.primaryrace: null
$NPCs_OnPlatform.{1}.type: upgradetrader
$NPCs_OnPlatform.{1}.typename: Mechanic
$NPCs_OnPlatform.{1}.race: Terran
$NPCs_OnPlatform.{1}.page: 10104
$NPCs_OnPlatform.{1}.isitemtrader: 0
$NPCs_OnPlatform.{1}.money: 123158226767
$NPCs_OnPlatform.{1}.minbudget: 0
$NPCs_OnPlatform.{1}.maxbudget: 0
$NPCs_OnPlatform.{1}.combinedskill: 0
$NPCs_OnPlatform.{1}.inventory.random: Steady Shield Mk3
$NPCs_OnPlatform.{1}.inventory: null
$NPCs_OnPlatform.{1}.inventory.count: 21 (possibility to ask for a specific ware)
$NPCs_OnPlatform.{1}.inventory.{1}: null
$NPCs_OnPlatform.{1}.inventory.list: no display
$NPCs_OnPlatform.{1}.inventory.list.{1}: Equalized Engine Mk1
$NPCs_OnPlatform.{1}.inventory.list.{1,1}: no display
$NPCs_OnPlatform.{1}.inventory.list.{1}.price: null
$NPCs_OnPlatform.{1}.inventory.list.{1}.unitprice: null
$NPCs_OnPlatform.{1}.inventory.list.{1}.relativeprice: null



By the way, here is $NPCs_OnPlatform.{1} information inside the save file:

<connections>
<connection connection="connection01">
<component class="npc" macro="character_ar_female_dv_b_macro" connection="commandroomslot" name="Haruka Lieberwitz" owner="canteran" page="10104" id="[0xa59]">
<offset>
<position x="-0.419776" y="-0.885464" z="9.39339"/>
<rotation yaw="-135"/>
</offset>
<skills>
<skill type="boarding" value="1"/>
<skill type="engineering" value="2"/>
<skill type="management" value="2"/>
<skill type="navigation" value="2"/>
</skills>
<entity type="upgradetrader" customconversation="1"/>
<inventory>
<ware ware="upg_pla_engine_bal_mk1"/>
<ware ware="upg_pla_engine_spe_mk2"/>
<ware ware="upg_pla_engine_man_mk2"/>
<ware ware="upg_pla_engine_spe_mk3"/>
<ware ware="upg_pla_engine_bal_mk4"/>
<ware ware="upg_pla_shield_bal_mk1" amount="2"/>
<ware ware="upg_pla_shield_cap_mk2" amount="2"/>
<ware ware="upg_pla_shield_cap_mk3" amount="2"/>
<ware ware="upg_pla_shield_bal_mk3" amount="2"/>
<ware ware="upg_pla_shield_rec_mk3" amount="2"/>
<ware ware="upg_pla_shield_cap_mk4" amount="2"/>
<ware ware="upg_pla_shield_bal_mk4" amount="2"/>
<ware ware="upg_pla_weapon_ie_mk1"/>
<ware ware="upg_pla_weapon_pe_mk1"/>
<ware ware="upg_pla_weapon_sg_mk1"/>
<ware ware="upg_pla_weapon_mg_mk1"/>
<ware ware="upg_pla_weapon_ml_mk1"/>
<ware ware="upg_pla_scanner_mk1"/>
<ware ware="upg_pla_scanner_mk2"/>
<ware ware="upg_pla_scanner_mk3"/>
<ware ware="upg_pla_software_tc_mk1"/>
</inventory>
<blackboard>
<value name="$TopicID" type="integer"/>
<value name="$TopicTimeout" type="time"/>
</blackboard>
<npcseed bodyparts="1801748878" bonescales="925550092" morphtargetweights="2482427743"/>
<npcanimation currentsequenceid="110" currentanimation="idleaa01"/>
<connections/>
</component>
</connection>
</connections>



I can't find how to get the selling and buying prices.

Any idea?
UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader »

scriptproperties.html#ware ;)

you are entering the wrong values. bet you wanted to know
minprice
averageprice
maxprice
pricerange
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 ;)
User avatar
ybeline
Posts: 83
Joined: Sun, 22. Aug 10, 13:55
x4

Post by ybeline »

Hello UniTrader,

I am aware of those suffixes:

$NPCs_OnPlatform.{1}.inventory.list.{1}.minprice: 11 000,00
$NPCs_OnPlatform.{1}.inventory.list.{1}.averageprice: 12 000,00
$NPCs_OnPlatform.{1}.inventory.list.{1}.maxprice: 13 000,00
$NPCs_OnPlatform.{1}.inventory.list.{1}.pricerange: 2 000,00

This NPC ($NPCs_OnPlatform.{1}) is a mechanic.
The first item this NPC sells/buys ($NPCs_OnPlatform.{1}.inventory.list.{1}) is an 'Equalized Engine Mk1'.

And what I am looking for, is the prices of THIS particular NPC.
For example, if I go meet her, she will buy my 'Equalized Engine Mk1' for 11 353,10 Cr.

This is those prices that I am looking for :)
User avatar
Jack08
Posts: 2993
Joined: Sun, 25. Dec 05, 10:42
x3tc

Post by Jack08 »

from what i can tell, the prices are generated as a random number between min and max, and stored in a local variable within the MD cue OnPlatformPopulation_Itemtrader, file NPC_ItemTrader, i do not know how to retrieve them.
UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader »

ah, ok now i get you..

seems this is done by MD Code, not by the Engine so we probably have to fiddle with Variable Names a bit..

look in the md/NPC_Itemtrader.xml the prices are regulated there ;) currently looking through it to find out whats necesary to read this one out ^^

EDIT: ok, no idea for sure yet but i would try it with:

$NPCs_OnPlatform.{1}.$WareList.{$i}.{2}
(where $i is the number of the ware in the trade list)
Last edited by UniTrader on Thu, 21. Nov 13, 22:49, edited 1 time in total.
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 ;)
User avatar
ybeline
Posts: 83
Joined: Sun, 22. Aug 10, 13:55
x4

Post by ybeline »

From what I have read in md\NPC_Itemtrader.xml, I am now looking at md\Setup.xml and more precisely, the cue "Start".
UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader »

UniTrader wrote: EDIT: ok, no idea for sure yet but i would try it with:

$NPCs_OnPlatform.{1}.$WareList.{$i}.{2}
(where $i is the number of the ware in the trade list)
quoting myself since you probably will miss this otherwise ^^
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 ;)
User avatar
ybeline
Posts: 83
Joined: Sun, 22. Aug 10, 13:55
x4

Post by ybeline »

Thanks UniTrader,



Just as a reminder:
The variable $NPCs_OnPlatform is created with:
<find_object_component name="$NPCs_OnPlatform" object="player.platform" multiple="true" class="class.npc" />



Well, using $NPCs_OnPlatform.{1}.$WareList.{1}.{2} to get the price of the first ware of the inventory of the first NPC on platform, isn't working.

I have tested it and have gotten a 'null'.

In fact, as I am currently working with a Mechanic on my example, we have to work with md\NPC_Upgradetrader.xml instead of md\NPC_Itemtrader.

Indeed, md\NPC_Upgradetrader.xml deals with Engines/Shields/Weapons/Scanners/Softwares found at a Mechanic.



The inventory frame of each type of trader is in fact some kind of a constant, defined in md\Setup.xml at the <cue name="Start">.

Here is the definition of the inventory frame for a Mechanic:

Code: Select all

<set_value name="md.$EngineUpgradetraderLists" exact="
            [
                [
                    [ware.upg_pla_engine_bal_mk1, 1, 1, 100],
                    [ware.upg_pla_engine_spe_mk2, 1, 1, 80],
                    [ware.upg_pla_engine_man_mk2, 1, 1, 80],
                    [ware.upg_pla_engine_spe_mk3, 1, 1, 60],
                    [ware.upg_pla_engine_bal_mk3, 1, 1, 60],
                    [ware.upg_pla_engine_man_mk3, 1, 1, 60],
                    [ware.upg_pla_engine_spe_mk4, 1, 1, 40],
                    [ware.upg_pla_engine_bal_mk4, 1, 1, 40],
                    [ware.upg_pla_engine_man_mk4, 1, 1, 40],
                    [ware.upg_pla_engine_spe_mk5, 0, 0, 0],
                    [ware.upg_pla_engine_bal_mk5, 0, 0, 0],
                    [ware.upg_pla_engine_man_mk5, 0, 0, 0]
                ]
            ]
        "/>
Here is the pattern of md.$EngineUpgradetraderLists:

Code: Select all

[[ [ware1, minimum volume, maximum volume, chance to be in stock],
   [ware2, ... , ... , ...],
   [ware3, ... , ... , ...],
   ... ]]
Then, if we go back to md\NPC_Upgradetrader.xml, at the <cue name="OnPlatformPopulation_Trader">, each time a Mechanic is created by the 'Platform Population System' engine, a temporary variable $EngineUpgradesDefinition is created and takes the value of md.$EngineUpgradetraderLists that was defined just previously in md\Setup.xml.

Inside <actions> ... </actions>, the cue then creates an important list variable: $EngineUpgradesList. An iteration through all the wares of this now particular Mechanic then adds those wares to its inventory with a random volume (remember the "chance" to have a ware in stock and the range of the possible volume). The needed data comes from $EngineUpgradesDefinition. This iteration also creates a random price for each ware, between the minimum and maximum value defined in libraries\wares.xml.

The iteration finally appends [$EngineUpgradesDefinition.{$i}.{1}.id, $Price] to the list $EngineUpgradesList, where $i is the number of the ware in the Mechanic's inventory. It also destroys the temporary variable $EngineUpgradesDefinition.

So, as you said UniTrader, it's probably this that is to use to get the exact price of the ware for this particular NPC:
$NPCs_OnPlatform.{1}.$EngineUpgradesList.{1}.{2}.

But it's not working either, I have also gotten a 'null'.



So, I got further into the code of md\NPC_Upgradetrader.xml.

Inside the same cue, after <actions> ... </actions>, there is 2 cues inside a <cues> ... </cues>, just before the initial cue closes:

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"/>
        </cue>
        
        <cue name="Platform_RemoveValues">
          <delay exact="1s"/>
          <actions>
            <remove_value name="$EngineUpgradesList"/>
            <remove_value name="$ShieldUpgradesList"/>
            <remove_value name="$WeaponUpgradesList"/>
            <remove_value name="$ScannerUpgradesList"/>
            <remove_value name="$SoftwareUpgradesList"/>
          </actions>
        </cue>
      </cues>
This explains why $NPCs_OnPlatform.{1}.$EngineUpgradesList.{1}.{2} doesn't work: because it has been deleted.

But my knowledge is not sufficient enough to understand how to use the <param name="EngineUpgradesList" value="$EngineUpgradesList"/>.



Any idea?

Thanks,

Regards,

ybeline
Last edited by ybeline on Fri, 22. Nov 13, 02:04, edited 2 times in total.
UniTrader
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 14571
Joined: Sun, 20. Nov 05, 22:45
x4

Post by UniTrader »

ybeline wrote:But my knowledge is not sufficient enough to understand how to use the <param name="EngineUpgradesList" value="$EngineUpgradesList"/>.
same here. just guessing me through this Me.. erm.. MD Code. never liked MD, and dont think i will like it.
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 ;)
User avatar
ybeline
Posts: 83
Joined: Sun, 22. Aug 10, 13:55
x4

Post by ybeline »

Hello,
UniTrader wrote:same here. just guessing me through this Me.. erm.. MD Code.
Well, I hope it's still possible to get those prices.

Any idea, anybody?

Thanks,

Regards,

ybeline

Return to “X Rebirth - Scripts and Modding”