• We have updated our Community Code of Conduct. Please read through the new rules for the forum that are an integral part of Paradox Interactive’s User Agreement.

Drosofeelsia

Private
55 Badges
May 31, 2016
14
0
  • Crusader Kings II: Charlemagne
  • Stellaris: Synthetic Dawn
  • Europa Universalis IV: Third Rome
  • Stellaris
  • Cities: Skylines - Snowfall
  • Europa Universalis IV: Cossacks
  • Cities: Skylines - After Dark
  • Warlock 2: The Exiled
  • Europa Universalis IV: Res Publica
  • Majesty 2 Collection
  • Magicka
  • Impire
  • Europa Universalis IV: Wealth of Nations
  • Crusader Kings II: Sons of Abraham
  • Crusader Kings II: Legacy of Rome
  • Crusader Kings II
  • Crusader Kings II: The Old Gods
  • Crusader Kings II: Rajas of India
  • Crusader Kings II: The Republic
  • Europa Universalis IV: Art of War
  • Europa Universalis IV
  • Europa Universalis IV: Conquest of Paradise
  • Crusader Kings II: Sword of Islam
  • Crusader Kings II: Sunset Invasion
  • Dungeonland
  • Cities: Skylines - Parklife Pre-Order
  • Cities: Skylines - Green Cities
  • Stellaris: Necroids
  • Stellaris: Humanoids Species Pack
  • Stellaris: Apocalypse
  • Europa Universalis IV: Rule Britannia
  • Cities: Skylines - Campus
  • Cities: Skylines - Parklife
  • Stellaris: Distant Stars
  • Stellaris: Ancient Relics
  • Stellaris: Megacorp
  • Prison Architect
  • Europa Universalis IV: Mandate of Heaven
  • Cities: Skylines - Mass Transit
  • Stellaris - Path to Destruction bundle
  • Cities: Skylines - Natural Disasters
  • Stellaris: Leviathans Story Pack
  • Stellaris: Digital Anniversary Edition
  • Europa Universalis IV: Rights of Man
  • Europa Universalis IV: Mare Nostrum
  • Europa Universalis IV: Common Sense
  • Pillars of Eternity
  • Crusader Kings II: Way of Life
  • Europa Universalis IV: El Dorado
  • Cities: Skylines
I have an event where I would like to give different result options for the player, depending on their current researched technologies and government ethos. To keep it simple, let's say I'm only interested in whether the player is a materialist or fanatic materialist, and whether they have discovered tech_thrusters_2.

Taking the problem at face value, it seems to me like I would need to make a series of separate options that each trigger on every different possible combination of those values. So, for example:

Code:
option = {
     name = anomaly.1.a
     trigger = {
        owner = {
           has_ethic = ethic_materialist
           has_technology = tech_thrusters_2
          }
     }
}
option = {
     name = anomaly.1.b
     trigger = {
        owner = {
           has_ethic = ethic_fanatic_materialist
           has_technology = tech_thrusters_2
          }
     }
}
option = {
     name = anomaly.1.b
     trigger = {
        owner = {
         not = {
           has_ethic = ethic_fanatic_materialist
          }
         has_technology = tech_thrusters_2
       }
     }
}

and so on for each possibility where the player doesn't have tech_thrusters_2 as well. That seems like it will take up a truly massive amount of space with a lot of room for snarled code, and if I want to add more conditions then the number of code lines will inflate rapidly. Does anyone with more experience have any syntax tips and tricks for condensing a large number of conditions to trigger separate effects?
 
You can solve a bit of the snarl by move a bit of the nesting to a new event, triggered from an option. Thus creating an event tree.
Sometimes I have seen clever use of <if> also.
 
I think you may be able to nest them in an if, so like
if = {
trigger = { has_ethic = fanatical_materialist }
option = {
trigger = { has tech whatever }
Effect
}
Option = {
trigger = { not has tech whatever }
Effect
}
}

But I've not tried that directly myself. It's also questionable if it's less snarly.
 
You might check out the syntax in:
C:\Steam\steamapps\common\Stellaris\common\policies\00_policies.txt

For example lines 374 through 398
Code:
    option = {
        name = "purge_allowed_xenos_only"
      
        policy_flags = {
            purge_allowed_xenos_only
        }
        modifier = {}
      
        potential = {
            num_communications > 0
        }
      
        valid = {
            OR = {
                has_ethic = "ethic_xenophobe"
                has_ethic = "ethic_fanatic_xenophobe"
                has_ethic = "ethic_collectivist"
                has_ethic = "ethic_fanatic_collectivist"
                has_government = "military_dictatorship"
                has_government = "martial_empire"
                has_government = "military_junta"
            }
        }

I added the last three "has_government" expressions, just based on inferred proper construction from other files, and it works. It may be that something like has_tech = "foo" would work too.
 
You might check out the syntax in:
C:\Steam\steamapps\common\Stellaris\common\policies\00_policies.txt

That doesn't really help with the question he asked, tbh. He wants separate options depending on which ethics they have, not multiple ethics to unlock the same option.

A switch = {} might help, though. They're mostly used in desc fields in the vanilla events, so I don't know if they'll work here, but something like

trigger = {
switch = {
trigger = has_ethic
ethic_materialist = {some effect }
ethic_xenophobe = { some effect }
ethic_collectivist = { some effect }
}
has_technology = tech_thrusters_2
}

In theory, the above should fire when you have thruster_2, and you can put a different effect in each ethic. That way, you only need 2 lists - one for 'has the tech', and one for 'doesn't have the tech', but can have upto 32 different effects from the one event.

I've not tested this in any way whatsoever, and I've no doubt it'd require some debugging... but it's probably the best bet in terms of code clarity. Have a look at the bottom few events in leader_events_1.txt for examples of it in use.
 
  • 1
Reactions:
"To keep it simple, let's say I'm only interested in whether the player is a materialist or fanatic materialist, and whether they have discovered tech_thrusters_2."

Maybe something like:

if = {
AND = {
has _technology = tech_thrusters_2
OR = {
has_ethic = ethic_materialist
has_ethic = ethic_fanatic_materialist
}}
# do stuff
}

To check if the tech is there, AND either materialist or fanatic materialist? The OR returns true if the empire has either ethic, and the AND requires both the tech and the OR to return true.
 
That doesn't really help with the question he asked, tbh. He wants separate options depending on which ethics they have, not multiple ethics to unlock the same option.

A switch = {} might help, though. They're mostly used in desc fields in the vanilla events, so I don't know if they'll work here, but something like

trigger = {
switch = {
trigger = has_ethic
ethic_materialist = {some effect }
ethic_xenophobe = { some effect }
ethic_collectivist = { some effect }
}
has_technology = tech_thrusters_2
}

In theory, the above should fire when you have thruster_2, and you can put a different effect in each ethic. That way, you only need 2 lists - one for 'has the tech', and one for 'doesn't have the tech', but can have upto 32 different effects from the one event.

I've not tested this in any way whatsoever, and I've no doubt it'd require some debugging... but it's probably the best bet in terms of code clarity. Have a look at the bottom few events in leader_events_1.txt for examples of it in use.

There's switch functionality in the scripts?

Thank you for pointing this out.
 
There's switch functionality in the scripts?

Thank you for pointing this out.

Yes, but again I'm not sure how far that functionality goes. As I say, it's mostly used just to swap out text fields in the vanilla files.
 
Yes, but again I'm not sure how far that functionality goes. As I say, it's mostly used just to swap out text fields in the vanilla files.
How far the functionality goes is certainly a question, but looking at country.999 in country_events_2 (the comet sighted event), switch actually unlocks qualified options each with different effects. So, at least in this case, it's effectively doing more than just unlocking text fields.
 
How far the functionality goes is certainly a question, but looking at country.999 in country_events_2 (the comet sighted event), switch actually unlocks qualified options each with different effects. So, at least in this case, it's effectively doing more than just unlocking text fields.

Was intrigued and had a look... and no, it doesn't. The switch in 999 is in the desc field, and just swaps the text description (like in many other events). The options are unlocked by trigger = { condition} on each individual option.
 
Was intrigued and had a look... and no, it doesn't. The switch in 999 is in the desc field, and just swaps the text description (like in many other events). The options are unlocked by trigger = { condition} on each individual option.
Ah, you're right. I guess I'm thrown by the variations of each options still being "a" options. Still plenty to learn, thanks.