Normaly, you can't have the sell button check for requirements the same way you can for availability.
Say in your scenario, you have special class of long range weapons. In order to use them, you must first purchase an upgrade outfit. Say, a long range targeting system. But you only need one, and it will allow you to have as many long range weapons as you can hold.
The point is that the player shouldn't be able to sell the targeting system as long as he has the weapons.
There are a couple ways around this that I can see.
1) Use the limited ammo function that prevents you from selling a weapon if it has ammo left to act as the control.
The weapon outfits have a test condition (or require bit) to see if you have the targeting system in order for you to buy them.
The targeting system is actually placeholder weapon that has an ammo limit (in the weap resource) The weapon does not actually fire. (fire only with key carried, and never give a key carried)
When you buy any long range weapon, have it also Gxxx an ammo outfit for the placeholder weapon. When you sell it, Dxxx a placeholder weapon ammo.
Give this ammo outfit a player info name of "long range weapon"
So, when you try to sell the targeting system and you still have long rage weapons, Nova will prevent you and tell you that you have to sell a "long range weapon" first.
Pros: Looks very clean in the outfitter.
Cons: Uses extra weap and outf resources. Adds complexity to the ship resource. Need to set up the extra weapons and ammo in case the player captures or buys a ship that stocks them.
Also requires the player to sell items in a particular order - could be annoying to find them all.
2) Make it so you can't sell the targeting system. And instead use a another outfit to sell it. Such as "Sell Long Range Targeting System" outfit. This way you can use the buy button functionality to test for the presence of the weapons first.
Give this item a negative cost (I don't remember if negative cost works. If not, simply start an auto-aborting mission that gives credits)
Pros: Less resource usage. Simpler to set up (especially so in NPC ships)
Cons: Very cluttered looking in the outfitter. You can hide and show bassed on availability, or use the supress higher RIDs for the same display weight to cover up uneeded buttons. But this will have the effect of the outtfitter re-scrolling to the top every time the layout changes. Very annoying with lots of outfits.
Also, you still have to hunt for the items you need to sell off first.
3) Use the targeting system's onSell field to set a bit and start a mission that dateposts. The set bit starts a series of crons that check for the presence of the weapons. Then, if no weapons are present it will Dxxx the targeting system, then run a credit giving misn.
If weapons are detected it doesn't Dxxx the item and presents a dialogue. You could have this run a mission that tells the player he needs to sell off the weapons first. In theory, a misn could run asking if they should automatically be sold now. This can lead to a series of iterative crons (one for each weapon) that Dxxx and grant credits.
I thought this was going to be the winning soluting. As it is both clean in the outfitter, and the extra resource usage is placed in the misns and crons. There is extra complexity there, but also makes the ship resources much cleaner.
The problem is that the item is sold off instantly when you click sell. Not a problem itself, since you can Gxxx item in the onSell field and take away the refunded credits as you begin the misn/cron sequence.
The problem is that Nova gives you full credit for the item if you haven't left the outfitter yet. But only gives you half credit later on. (Dateposting in the outfitter doesn't affect this)
This being the case, I can't see how i'm going to use misns to take back the credits, since there's no way to tell how much Nova automatically refunded.
I could make the items cost 0, and charge money using misns, but that will allow the player to go into massive debt. Very possibly abusive debt. (Also means the cost needs to be in the description field.)
Right now, I'm using a combination of options 1 and 2, depending on the nature of the outfits.
Have I been dumb and missed a simpler way of doing this?
Does anyone else have usefull thoughts here?