Skip to content

Instantly share code, notes, and snippets.

@keyz182
Last active August 30, 2025 16:29
Show Gist options
  • Save keyz182/0637bab4571e69151c86b6612b763552 to your computer and use it in GitHub Desktop.
Save keyz182/0637bab4571e69151c86b6612b763552 to your computer and use it in GitHub Desktop.
`ContrabandDef` wiki page for VEF

The contraband system allows for Chemicals (Drugs), Things, or even entire ThingCategories to be made illegal to trade.

How do I use this?

To make something illegal, you'll need a VEF.Factions.ContrabandDef. A ContrabandDef allows you to specify which factions consider the trading or gifting illegal, what specifically is illegal, the chance that they'll catch you, along with the related strings.

ContrabandDef

<?xml version="1.0" encoding="UTF-8" ?>
<Defs>
    <VEF.Factions.ContrabandDef>
        <defName>Contraband_Alcohol</defName>
        <label>Alcohol</label>
        
        <!-- The faction finding things illegal -->
        <factions>
            <li>TribeCivil</li>
        </factions>
        
        <!-- History events to register on gifted/sold -->
        <giftedHistoryEvent>Contraband_GiftedAlcohol</giftedHistoryEvent>
        <soldHistoryEvent>Contraband_SoldAlcohol</soldHistoryEvent>
        
        <!-- Optional, but at least one needs to be populated -->

        <!-- ChemicalDefs to make illegal -->
        <chemicals> 
            <li>Alcohol</li>
        </chemicals>

        <!-- ThingDefs to make illegal -->
        <things> 
            <li>Beer</li>
        </things>

        <!-- ThingCategories to make illegal -->
        <thingCategories> 
            <li>Drugs</li>
        </thingCategories>
        
        <!-- Fully optional -->
        
        <!-- A list of factions that it's illegal to sell/gift to. Selling/gifting to other factions is allowed -->
        <illegalFactions> 
            <li>TradersGuild</li>
        </illegalFactions>
        
        <!-- The chance to get caught in a transaction -->
        <chanceToGetCaught>0.5</chanceToGetCaught>
        
        <!-- Multiplier on the impact. With a positive number and appropriate strings, this would allow for positive goodwill on with faction A when trading with B. -->
        <impactMultiplier>-1</impactMultiplier>
        
        <!-- The LetterDef of the letter to send when discovered -->
        <letterType>ThreatSmall</letterType>
        
        <!-- Random range from which to pick for the days until the faction discovers the illegal trade -->
        <daysToImpact>1~2</daysToImpact>
        
        
        <!-- string definitions -->

        <!-- 
            A warning message shown when selecting contraband as a gift. 
            Gets passed:
            - ILLEGALTHING - the thingdef of the contraband being selected
            - FACTION - the faction that considers it contraband
            - ILLEGALFACTION - the faction being gifted to 
        -->
        <giftWarningKey>Contraband_Contraband_Booze_GiftWarning</giftWarningKey>

        <!--
            A warning message shown when selecting contraband to sell
            Gets passed:
            - ILLEGALTHING - the thingdef of the contraband being selected
            - FACTION - the faction that considers it contraband
            - ILLEGALFACTION - the faction being traded with 
        -->
        <sellWarningKey>Contraband_Contraband_Booze_SellWarning</sellWarningKey>

        <!-- 
            A warning message shown when selecting contraband as a gift to an illegal faction. 
            Gets passed:
            - ILLEGALTHING - the thingdef of the contraband being selected
            - FACTION - the faction that considers it contraband
            - ILLEGALFACTION - the faction being gifted to 
        -->
        <giftIllegalFactionWarningKey>Contraband_Contraband_Booze_GiftIllegalFactionWarning</giftIllegalFactionWarningKey>

        <!--
            A warning message shown when selecting contraband to sell to an illegal faction
            Gets passed:
            - ILLEGALTHING - the thingdef of the contraband being selected
            - FACTION - the faction that considers it contraband
            - ILLEGALFACTION - the faction being traded with
        -->
        <sellIllegalFactionWarningKey>Contraband_Contraband_Booze_SellIllegalFactionWarning</sellIllegalFactionWarningKey>

        <!-- 
            The label of the letter sent when discovered
            Gets passed:
            - FACTION - the faction that considers it contraband
        -->
        <letterLabelKey>Contraband_Contraband_Booze_LetterLabel</letterLabelKey>

        <!--
            The description of the letter sent when discovered gifting contraband
            Gets passed:
            - ILLEGALTHING - the thingdef of the contraband being selected
            - FACTION - the faction that considers it contraband
        -->
        <letterDescGiftKey>Contraband_Contraband_Booze_LetterDescGift</letterDescGiftKey>

        <!--
            The description of the letter sent when discovered selling contraband
            Gets passed:
            - ILLEGALTHING - the thingdef of the contraband being selected
            - FACTION - the faction that considers it contraband
        -->
        <letterDescSoldKey>Contraband_Contraband_Booze_LetterDescSold</letterDescSoldKey>
        
        <!--
            An extra string shown in the letter describing the relation change
            Gets passed:
            - FACTION - the faction that considers it contraband
            - {1} - the updated goodwill with the faction
            - {2} - the change in goodwill
        -->
        <relationInfoKey>Contraband_Contraband_Booze_RelationInfo</relationInfoKey>
    </VEF.Factions.ContrabandDef>
    
    <HistoryEventDef>
        <defName>Contraband_GiftedAlcohol</defName>
        <label>gifted alcohol</label>
    </HistoryEventDef>
	
    <HistoryEventDef>
        <defName>Contraband_SoldAlcohol</defName>
        <label>sold alcohol</label>
    </HistoryEventDef>
</Defs>

Translation strings

<?xml version="1.0" encoding="utf-8"?>
<LanguageData>
    <Contraband_Contraband_Booze_GiftWarning>Gifting {ILLEGALTHING_label} is against {FACTION_name} law. This may or may not affect your relations with them in the future</Contraband_Contraband_Booze_GiftWarning>
    <Contraband_Contraband_Booze_SellWarning>Selling {ILLEGALTHING_label} is against {FACTION_name} law. This may or may not affect your relations with them in the future</Contraband_Contraband_Booze_SellWarning>
    <Contraband_Contraband_Booze_GiftIllegalFactionWarning>Gifting {ILLEGALTHING_label} to {ILLEGALFACTION_name} is against {FACTION_name} law. This may or may not affect your relations with them in the future</Contraband_Contraband_Booze_GiftIllegalFactionWarning>
    <Contraband_Contraband_Booze_SellIllegalFactionWarning>Selling {ILLEGALTHING_label} to {ILLEGALFACTION_name} is against {FACTION_name} law. This may or may not affect your relations with them in the future</Contraband_Contraband_Booze_SellIllegalFactionWarning>
    <Contraband_Contraband_Booze_LetterLabel>{FACTION_name} angered</Contraband_Contraband_Booze_LetterLabel>
    <Contraband_Contraband_Booze_LetterDescGift>{FACTION_name} caught wind that you have been gifting {ILLEGALTHING_label} behind their back. They consider it to be against the law, and your relations have degraded</Contraband_Contraband_Booze_LetterDescGift>
    <Contraband_Contraband_Booze_LetterDescSold>{FACTION_name} caught wind that you have been selling {ILLEGALTHING_label} behind their back. They consider it to be against the law, and your relations have degraded</Contraband_Contraband_Booze_LetterDescSold>
    <Contraband_Contraband_Booze_RelationInfo>Goodwill with {FACTION_name} is now {1}. (Reduced by {2})</Contraband_Contraband_Booze_RelationInfo>
</LanguageData>

Trading items gives positive relations

To configure contraband items to generate positive goodwill with a faction upon trade, set <impactMultiplier> to a positive value (e.g., 1), change <letterType> to PositiveEvent, and update the associated strings accordingly. This setup will cause trading these items to have a chance of increasing your goodwill with the targeted faction.

How does it work?

When an item matching a ContrabandDef is traded to a faction that's not in <factions>, then a GoodwillImpactDelayed is registered with the WorldComponent_FactionGoodwillImpactManager. The manager will check it's registered impacts each tick to see if any are due to trigger. If they are, GoodwillImpactDelayed.DoImpact() is called, which will make the goodwill change and send a letter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment