Storing and accessing data in other systems query

Freeform discussion about anything related to modding Transcendence.
Post Reply
relanat
Militia Commander
Militia Commander
Posts: 435
Joined: Tue Nov 05, 2013 9:56 am

Tue Nov 29, 2016 4:57 am

I've been reworking Betel's broken storage station mod for a while now. I'm looking for some guidance on how to handle the station inventories when the playership is in another system.

Basic setup is you store items you want later in a storage station in a particular system. Once you reach another system wth a storage station, after paying the relevant amount, you can get the items you left behind shipped to you in the present system (like in Corp Trading Post freighters).

But I'm not sure if a station inventory can be accessed unless the player is in the same system as the station.

If this is the case then does the player/ship need to carry around that info and update stations as it enters a system? And what is the best or easiest way to do this? Is some sort of global data store needed or a virtual ship or item? Grateful for any advice on this.

And if examples of doing this are out there can someone point me to them? Much appreciated.

NMS
Militia Commander
Militia Commander
Posts: 399
Joined: Tue Mar 05, 2013 8:26 am

Wed Nov 30, 2016 12:27 am

Generally, I think the logical way to way to store data that you want to be accessible anywhere is with typSetData, in this case on the station type. For instance, you could store a struct where the field names are the node IDs of systems where the stations are located (if there's at most one per system), or some unique identifier for each station, and each field is a list of items on that station.

Presumably you want the items to actually exist on the station in case it gets destroyed or something, so you don't have to update the list every time items are transferred on or off the current station, only when items are ordered from another system and when the player enters or leaves the system. So you could use something like this:

Code: Select all

<OnPlayerLeftSystem>
	(typSetData &shippingStationType; 'storedItemsStruct
		([email protected] (typGetData &shippingStationType; 'storedItemsStruct)
			(sysGetNode)
			(if (objGetProperty gSource 'abandoned)
				nil
				(objGetItems gSource 'U)
			)
		)
	)
</OnPlayerLeftSystem>

<OnPlayerEnteredSystem>
	(if (not (objGetProperty gSource 'abandoned))
		(block nil
			(enum (objGetItems gSource 'U) theItem
				(objRemoveItem gSource theItem)
			)
			(enum (@ (typGetData &shippingStationType; 'storedItemsStruct) (sysGetNode)) theItem
				(objAddItem gSource theItem)
			)
		)
	)
</OnPlayerEnteredSystem>
Then you just have to write or fix the code that lets the player transfer items to and from the station, view the items in other systems, and order those items shipped (removing them from the list in the process)...

relanat
Militia Commander
Militia Commander
Posts: 435
Joined: Tue Nov 05, 2013 9:56 am

Thu Dec 08, 2016 3:38 am

Its taking me a while but I've nearly got this. This is excellent info and exactly what I need (I think)! I didn't have any idea on how to do it though.

Within a system the station inventory gets handled like in any normal station. Only one station per system max.

Then use typSet/GetData to handle the changes because the changes can't happen until in the same system.

It doesn't help that I haven't worked out exactly what I want to happen either! :lol:

Many thanks. Great explanation, too.

relanat
Militia Commander
Militia Commander
Posts: 435
Joined: Tue Nov 05, 2013 9:56 am

Tue Feb 21, 2017 1:39 am

Beautiful work, NMS. It works a treat using typSetData. I've also used typSet/GetData elswhere successfully. Triple thanks.

OK. In the next system that has a storage station the struct contains this, which is 7 items of 3 different types.

Code: Select all

{ SE:((1851395 -16777214) (16717 -16777213) (1851404 -16777214)) }
Does anyone know how to get this info into an itempicker list in the station.

I've tried a number of code variations in the <ListOptions> area but no success.
Somthing like:

Code: Select all

dataFrom= "=(map or enum (@ (typGetData &stStation 'storedItems) (nodeID)) etc)"
might work but I don't know enough about ListOptions to know which format or functions will do anything.

'Enum'ing the items into a virtual station and then creating the virtual station will work.

Code: Select all

dataFrom= "=(setq nonStation (sysCreateStation &stVirtualStation; Nil))"
has worked before (and I'll do this if nothing else works), but seems a bit long winded.

Anyone know enough about ListOptions to work out how to get the items in the struct into an itempicker list? TIA.

And can anyone decipher the number stuff inside the struct? The last number appears to indicate quantity somehow but that's all I've worked out.

relanat
Militia Commander
Militia Commander
Posts: 435
Joined: Tue Nov 05, 2013 9:56 am

Tue Mar 14, 2017 1:14 am

OK, it's working beautifully if the goods are dumped straight into the station on entering the next system, but...

The station will store and transfer goods no problem.
The transfer between systems only happens if you select 'Freight Service' inside the station. This sets 'transferCond' to 'True'. Set it to 'Nil' and you can leave the system and return to add more goods.

If transferring, the station gets emptied and the items stored in the struct. The glitch is if you then return to the system and store and transfer more items before you enter the next system with a storage station (and therefore empty the struct) the struct gets overridden and the first lot of goods disappear.

I found

([email protected] struct-var struct) -> merged structs

in the function list and assume that it adds more items to a struct but, as always, without a few examples somewhere to dissect I can't work out the format and get the structs to add to each other.

Here one lot of code that doesn't work; "Too many arguments";

Code: Select all

<OnGlobalPlayerLeftSystem>
	(block Nil
		(if (and (sysFindObject Nil "t +unid:&stD789storageStation;") (eq (typGetData &stD789StorageStation; 'transferCond) True))
			(block Nil
				(setq stationToEmpty (@ (sysFindObject Nil "t +unid:0xD7892102") 0))
				(setq transferNodeID (sysGetNode))
				(if (not (objGetProperty stationToEmpty 'abandoned))
					(block Nil
						(if (typGetData &stD789StorageStation; 'storedItems)
							(block Nil
								(printTo 'console "Cond met left")
								(typSetData &stD789StorageStation; 'storedItems
									([email protected] (typGetData &stD789StorageStation; 'storedItems)
											transferNodeID
											(list (objGetItems stationToEmpty '*U)
											(typGetData &stD789StorageStation; 'storedItems 'transferNodeID))
									)
								)
							)
							(typSetData &stD789StorageStation; 'storedItems
								([email protected] (typGetData &stD789StorageStation; 'storedItems)
										transferNodeID
										(objGetItems stationToEmpty '*U)
								)
							)
						)
					)
				)
				(enum (objGetItems stationToEmpty '*U) itemsToRemove (objRemoveItem stationToEmpty itemsToRemove))
				(printTo 'console "Inv stored and station emptied")
				(setq transferSystemListPos (find allNodeIDList (sysGetNode)))
				(printTo 'console "Node ID pos stored")
			)
		)
	)
</OnGlobalPlayerLeftSystem>
Anyone got any ideas on how to format the code to add more items to the struct?

relanat
Militia Commander
Militia Commander
Posts: 435
Joined: Tue Nov 05, 2013 9:56 am

Sun Oct 22, 2017 8:45 am

Sorted.

How to add info to existing structs is covered in this topic

https://forums.kronosaur.com/viewtopic.php?f=8&t=8376

Post Reply