Ok, so here is... let's call it version v0.5.This is basic, and doesn't consider mission cargo yet, but I wanted to let people have a look at it, as it is at the moment. This will work perfectly well if you are only doing trading or pirating or scavenging (or should do anyway).
Create four new scripts:-
CargoLog_Add
Code:{_ CargoLog_Add} {_ Add commodities to the Cargo Log} {if state.eddi_context_cargo_initialised != "yes": {F("CargoLog_Initialise")}} {_ Setup arrays} {set cargo_commodity_array to split(state.eddi_context_cargo_commodity, "+=")} {set cargo_amount_array to split(state.eddi_context_cargo_amount, "+=")} {set cargo_power_array to split(state.eddi_context_cargo_power, "+=")} {if state.eddi_context_last_action = "collect": {set amount to 1} |else: {set amount to event.amount} } {if event.power: {set power to event.power} |else: {set power to ""}} {set position to find(cargo_commodity_array, event.commodity, 0)} {if position > -1: {set amount to amount + cargo_amount_array[position]} {_ Update array} {set cargo_amount_array to union(cargo_amount_array, [position:amount])} |else: {set cargo_commodity_array to cat(cargo_commodity_array, [event.commodity])} {set cargo_amount_array to cat(cargo_amount_array, [amount])} {set cargo_power_array to cat(cargo_power_array, [power])} } {_ Set State variable string seperator} {if len(cargo_commodity_array) < 2: {set sep to ""} |else: {set sep to "+="}} {_ Add new item to State variable strings } {SetState('eddi_context_cargo_commodity', join(cargo_commodity_array, sep))} {SetState('eddi_context_cargo_amount', join(cargo_amount_array, sep))} {SetState('eddi_context_cargo_power', join(cargo_power_array, sep))}
CargoLog_Delete
Code:{_ CargoLog_Delete} {_ Delete sold or ejected cargo from the log} {if state.eddi_context_cargo_initialised != "yes": {F("CargoLog_Initialise")}} {_ Setup arrays} {set cargo_commodity_array to split(state.eddi_context_cargo_commodity, "+=")} {set cargo_amount_array to split(state.eddi_context_cargo_amount, "+=")} {set cargo_power_array to split(state.eddi_context_cargo_power, "+=")} {if state.eddi_context_last_action = "eject": {set position to find(cargo_commodity_array, event.name, 0)} |else: {set position to find(cargo_commodity_array, event.commodity, 0)} } {if position > -1: {if cast(cargo_amount_array[position], "n") = event.amount: {_ Rebuild array strings} {if len(cargo_commodity_array) < 3: {set sep to ""} |else: {set sep to "+="}} {set cargo_commodity_array to join(except(cargo_commodity_array, [position:""]), sep)} {set cargo_amount_array to join(except(cargo_amount_array, [position:""]), sep)} {set cargo_power_array to join(except(cargo_power_array, [position:""]), sep)} {_ Rewrite State variable strings} {SetState('eddi_context_cargo_commodity', cargo_commodity_array)} {SetState('eddi_context_cargo_amount', cargo_amount_array)} {SetState('eddi_context_cargo_power', cargo_power_array)} |else: {if len(cargo_commodity_array) < 2: {set sep to ""} |else: {set sep to "+="}} {set amount to cargo_amount_array[position] - event.amount} {set cargo_amount_array to union(cargo_amount_array, [position:amount])} {SetState('eddi_context_cargo_amount', join(cargo_amount_array, sep))} } |else: Cargo not found in database to delete. }
CargoLog_Initialise
Code:{_ CargoLog_Initialise} {_ Setup Cargo Log 'database'} {SetState('eddi_context_cargo_name', "")} {SetState('eddi_context_cargo_amount', "")} {SetState('eddi_context_cargo_power', "")} {SetState('eddi_context_cargo_initialised', "yes")} Cargo Log Initialised.
CargoLog_Report
Code:{_ CargoLog_Report} {_ Report current cargo manifest} {_ Setup arrays} {set cargo_commodity_array to split(state.eddi_context_cargo_commodity, "+=")} {set cargo_amount_array to split(state.eddi_context_cargo_amount, "+=")} {set cargo_power_array to split(state.eddi_context_cargo_power, "+=")} You are carrying {ship.cargocarried} tonnes, from a total of {ship.cargocapacity} {Occasionally ("tonnes")}. {if len(cargo_commodity_array) > 0: Cargo Manifest is as follows. {set position to 0} {for cargo in cargo_commodity_array: {cargo_amount_array[position]} tonnes of {cargo}. {set position to position + 1} } }
To use them...
Add {F("CargoLog_Add")} to the following events:-
Commodity Collected
Commodity Purchased
Power Commodity Obtained
Add {F("CargoLog_Delete")} to the following events:-
Commodity Ejected
Commodity Sold
Power Commodity Delivered
I've only tested these with the EDDI test button so far, but my testing seems to show that it will work in-game OK.
Next up is working on mission cargo!
-=] Darkcyde [=-
EDIT: Forgot to say, CargoLog_Report must be called manually as I haven't created a VA command for it yet. I was using it for testing mainly, but it works well enough for a basic report.
Very good job on the mission script so far.
One problem I'm having is that it always reports as having 0 cargo. The ship.cargocarried variable always seems to return 0. I believe that this variable was broken with latest updates to ED.
Is there a way to substitute your cargo carried total amount for this variable?
And now for the wish list LOL. Is there a way to add limpets to the cargo script?