Space Engineers

Space Engineers

Not enough ratings
Cargo Shop Script
   
Award
Favorite
Favorited
Unfavorite
File Size
Posted
Updated
1.476 KB
Mar 5, 2015 @ 8:19pm
Apr 13, 2015 @ 1:26pm
6 Change Notes ( view )

Subscribe to download
Cargo Shop Script

Description
I'm a beginner at C# as I'm more of a web developer so I can admit this is probably very wrong. I was inspired to create this after seeing AutoShop by GamesOmatic. The script there however worked with multiple containers and connectors so it didn't really suit my needs.

In short this script allows you to trade out of cargo containers, you store items selling in a container and you store traded items in another. A public container is used to handle the trading. No naming requirements. No connectors. Fairly easy to setup and configure.

My code is based on code from PilotError42 and Borg.

You need:
3 containers (names must be unique and configured)
1 Program Block (name doesn't matter)
1 Timer Block (name doesn't matter)
and the containers linked

You can also use a LCD panel to display trade details.

Your first container is shared with all or faction, it is the input container which takes ShopVendorAmount of gold. In the default code 10. It is called in the default setup "Shop_Iron_Vendor". Your other containers are the gold storage, where collected gold is stored and Iron storage (from default) named "Shop_Iron_Storage". This is where the iron is taken from.

The vendor item and type is what you are selling. The require item and type is what you are asking for. In the default setup it is iron ingot for vendor and requires gold ingot.

Timer setup is simple, run at any interval and actions set to run the programming block and "Start" the timer itself.

Update 1:
* Added custom traded item.
* Added check for custom traded item.
* Cleaned up the code a bit.

Update 2:
* Enables multiple item for trades. (thanks to suggestion)
7 Comments
Teddy  [author] Apr 13, 2015 @ 1:17pm 
I'll change that later tonight to ">=". Thanks!
Kip Wilson Apr 9, 2015 @ 10:58am 
So after going through the script (Im not a great C# programmer) I noticed that your if statement has a condition if (sourceItems.Count == 1) {. So the IF statement only runs if the sourceItems container count equals 1. As soon as you deposit the trade item in the container, sourceItems.Count becomes greater than one and the IF statement no longer runs.
Kip Wilson Apr 5, 2015 @ 5:14pm 
Not a problem, thanks! :)
Teddy  [author] Apr 5, 2015 @ 5:07pm 
@Kip - I'm a little busy with work and some other projects but when I grab a free moment I can take a look.
Kip Wilson Apr 4, 2015 @ 8:33pm 
I really like your script and plan on using it on my dedicated server. I did notice one thing however. You cant make multiple trades until you remove the item that's being traded for out of the Shop_Iron_Vendor container. Is there any way we can fix that? I'd like to be able to trade every run of the script :)
r Cubed3 Mar 11, 2015 @ 5:40am 
i'm setting up my trade house now, if i'm feeling inspired i'll link up a video when it's done. -cheers
a Mar 8, 2015 @ 4:38pm 
This is a pretty cool idea, I can't wait until space engineers gets big enough that PVE servers will benefit from trading/economies, then scripts like this will be insanely useful.