Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: A station:AddEquipmentPrice(equip,money) #2654

Closed
impaktor opened this issue Jan 15, 2014 · 5 comments
Closed

Feature request: A station:AddEquipmentPrice(equip,money) #2654

impaktor opened this issue Jan 15, 2014 · 5 comments

Comments

@impaktor
Copy link
Member

I've been working on implementing something I call "News Events", that will affect prices (and stock) of specific commodities in some system based on some News reported (on the BBS) from there. I'm almost done, but I find I need to actually be able to change the price of some commodity at a station, i.e. I need a station:AddEquipmentPrice(equp,money) to go with the already implemented station:AddEquipmentStock(equp,stock).

I've looked a bit in EquipmentTradeWidgets.lua and CommodityMarket.lua, but could not see any obvious way to do it, with my current (lacking) understanding of the code.

(it does not have to persist across hyperjumps.)

Alternatively a SetCommodityBasePriceAlterations would probably also work.

@lwho
Copy link
Contributor

lwho commented Jan 15, 2014

As far as I can tell from a short view at the code, EquipmentTradeWidgets determines the prices by calling SpaceStation:GetEquipmentPrice which is defined in Lua (libs/SpaceStation.lua) and thus should be moddable to change the price.

@robn
Copy link
Member

robn commented Jan 16, 2014

Branch robn/set-equip-price has a single commit (@9c1cd059) that adds a SetEquipmentPrice method. Using it will set the price for the commodity at the given station and ignore the base price and any import/export alteration. Setting a price to nil will remove the overridden price and restore the original. Example:

> station:GetEquipmentPrice("PLASTICS")
13.92
> station:SetEquipmentPrice("PLASTICS", 123.45)
> station:GetEquipmentPrice("PLASTICS")
123.45
> station:SetEquipmentPrice("PLASTICS", nil)
> station:GetEquipmentPrice("PLASTICS")
13.92

@impaktor can you please take a lok and tell me if this is suitable? If it is I'll get it cleaned up and documented and tneh push it.

@impaktor
Copy link
Member Author

Awesome. Will try it out. Thanks.

@impaktor
Copy link
Member Author

Thanks!

I've tested it and it works for both when increasing and decreasing price (not surprisingly).

However, I thought it wise to see if it would persist in saves from a station where I make a price change.

"Error: Lua serializer 'SpaceStation' tried to serialize an invalid 'SpaceStation' object"

Also, I'm not using the nil functionality of it, but maybe it will be handy to have in the future. (I get the price, then change it with some factor.)

EDIT: I will have something runnable in my NewsEvent branch in 5-6 hours (~09:00 AEDT) if you need to test.

@robn robn closed this as completed in 5bdd402 Jan 18, 2014
@robn
Copy link
Member

robn commented Jan 18, 2014

Yeah, the save thing was me not clearing the table out at system destruction, so it still had refs to stations in the previous system that no longer existed. Thanks for reporting that. Fixed and merged the whole thing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants