If it were me (which it's not but hey
) to keep things simple intially I'd be keen to get the basic fetch & carry working for the TSs home base when it's a TL (or M1). Surely a simple check seeing if the homebase of the TS running your script is dockable is all that's needed, isn't there a simple script command that does that for you? Obviously for a station the goods collected have to be relevent, but I'm sure you already have that covered. If the homebase is a TL I would have though the script would in many ways be somewhat simpler as ANY wares can be specified & transported physical space & funds permitting.
Also I would certainly consider adding an Amount of ware to wait for before returning to base "full". I.e. your Dolphin may have 2000 cargo, but you may decide a "full" run would be when you've got 208 silicon to prime your new Crystal Fab with. This combined with the buying price you've already included would enable your TS to sit in a Silicon Mine (once again for example) & wait til it's fully stocked (the price drops to 227) & load the entire stock of 208 into the TS & return to base. Obviously setting the Amount to 0 would be requesting a "full hold" for the TS in question. Additionallly if the number specified is too large for current cargo capacity it would be supplimented for max cargo size (amount / volume).
Next I'd phase in use of the JumpDrive to speed things along a bit, the ship taking the required E Cells from its homebase (which you'll need calculate based on ship type IF you allow this command to run on Fighters as well as TS, which would be good!).
As for coding a "pilot" who would charge you for this service I'd say maybe not. Reasoning that this script is in many ways a Hoarder script or to enable you to get the maximum load of wares, possibly irrespective of price, so it's not necessarily a money making script, more of a convenience script & I'd certainly be using it mainly in conjunction with a TL as factory supplies are pretty much covered already with the likes of BPH.
I think the real power of this script of yours will be the ability to use it with TLs/M1s. Just imagine, fleets of TS sat in all the Weapon and shield fabs across the universe, stocking up at the best price & then automatically ferrying them to your TL mobile warehouse base using their jump-drives! You could even have ships getting the ecells you need using this method...at totally automated mobile warehouse! Hmm, maybe the pilots should charge after all eh?
Err, you're welcome for the "help" but just reckon I'm ginin you more work!
Scoob.