Results 1 to 10 of 10

Thread: Trait triggers?

  1. #1
    valerius karamanus's Avatar Civis
    Join Date
    Dec 2018
    Location
    Constantinopolis
    Posts
    126

    Icon5 Trait triggers?

    So I've been trying to create trait triggers with multipel outcomes but I have come to a dead end. Issue is, effect.trait("...", "...", x, x, context) simply does not fire when there are more then one, which is interesting because in Attila lua code I'm seeing lots of trait triggers parented by same functions. Lua structure of Rome2 and Attila seems pretty much same to my novice eyes, which leads me to believe either I'm doing something dumb or I'm straightforward dumb to think they are similar...

    Here is an example to make it more clear, this is from Attila. Upon creation, script assigns a character "humble" or "arrogant" trait by chance.
    Code:
    function att_trig_general_parent_has_trait_personality_all_innate_arrogant_impl (context) 
         return char_is_general(context:character()) and context:character():has_father() and context:character():father():has_trait("att_trait_general_personality_all_innate_arrogant")
    end 
    
    
    events.CharacterCreated[#events.CharacterCreated+1] =
    function (context)
        if att_trig_general_parent_has_trait_personality_all_innate_arrogant_impl(context) then
            effect.trait("att_trait_general_personality_all_innate_humble", "agent", 3, 40, context)
            effect.trait("att_trait_general_personality_all_innate_arrogant", "agent", 3, 40, context)
            return true
        end
        return false
    end
    Attempting to mimic the code in Rome2 however, results in absence of whole function.
    Code:
    function dei_physical_att_trait_impl (context) 
        return char_is_general(context:character()) and not context:character():has_trait("dei_physical_young_frail") and not context:character():has_trait("dei_physical_young_vigorous")
    end
    
    
    events.CharacterCreated[#events.CharacterCreated+1] =
    function (context)
        if dei_physical_attri_trait_impl(context) then
            effect.trait("dei_physical_young_frail", "agent", 1, 50, context)
            effect.trait("dei_physical_young_vigorous", "agent", 1, 50, context)
            return true
        end
        return false
    end
    In any case how would it be possible to implement this concept of assigning random traits via events? Tried Kankrusha's method of creating a table and assigning with math.random but I haven't had any luck.

  2. #2
    Jake Armitage's Avatar Artifex
    Patrician

    Join Date
    Apr 2011
    Location
    apartment 6
    Posts
    4,694

    Default Re: Trait triggers?

    Do you want to trigger a trait (chosed between more than one) with a dice roll?
    DeI used to have this but it was removed since it's not multiplayer friendly.

    Use the method I'm using for PIGS (DeI political overhaul)
    Here's part of the script, I'm using a different event to trigger custom politcal incidents but the concept/structure should be the same.
    It works 100% and I'm using it quite a lot lately.

    Code:
    -- 000---------------------
     --******* Current script and concepts modded by: Jake Armitage and ivanpera from TWC
     --******* Mod "PIGS INTRIGUES" - for DeI
     --******* June 2019
     -- 000---------------------
      
     module(..., package.seeall)
     _G.main_env = getfenv(1);
      
     -- ###------------------------- START *******
     -- LIBRARIES REQUIRED  ---------------------------------------------------------------------
     -- ###-------------------------
      
     events = require "data.lua_scripts.events"
     require "data.lua_scripts.lib_export_triggers"
     require "data.lua_scripts.politics" -- this isn't needed in you case
      
     -- ###---------------------------------- END*
      
     -- ###------------------------- START *******
     -- RANDOMSEED  ---------------------------------------------------------------------
     -- ###-------------------------
      
     local function PIGS_Intr_CallMathRandom(cont) 
    
     local i = cont;
         while ( i > 0 ) 
         do
         math.random(1,100);
         i = i - 1;
    
         end
     end
      
     local function PIGS_Intr_Random_seed(context)
    
         if context:faction():is_human() == true
         then        
         faction_name = context:faction():name();
         math.randomseed(os.clock());
    
         end
     end
      
     -- ###---------------------------------- END*    
      
     -- ###------------------------- START *******
     -- TRIGGER DECLARATIONS  ---------------------------------------------------------------------
     -- ###-------------------------
      
     --########################
     --######## GREEN INTRIGUES
     --########################
      
     -- *** PROMOTE POLITICIAN
      
     events.CharacterPoliticalPromotion[#events.CharacterPoliticalPromotion+1] =
     function (context)
    
         if conditions.FactionIsHuman(context)
         then
         local random_number = math.random(1, 100)
      
             if random_number >= 1 and random_number <= 2
             then
             scripting.game_interface:trigger_custom_incident(tostring(faction_name), "PIGS_Intr_PoliticalPromotion_inc_-3_VB_pop")
      
             elseif random_number >= 3 and random_number <= 4
             then
             scripting.game_interface:trigger_custom_incident(tostring(faction_name), "PIGS_Intr_PoliticalPromotion_inc_-3_VB_mil")
             
             elseif random_number >= 5 and random_number <= 6
             then
             scripting.game_interface:trigger_custom_incident(tostring(faction_name), "PIGS_Intr_PoliticalPromotion_inc_-3_VB_rul")
      
             elseif random_number >= 7 and random_number <= 8
             then
             scripting.game_interface:trigger_custom_incident(tostring(faction_name), "PIGS_Intr_PoliticalPromotion_inc_-3_VB_oth")
      
             elseif random_number >= 9 and random_number <= 15
             then
             scripting.game_interface:trigger_custom_incident(tostring(faction_name), "PIGS_Intr_PoliticalPromotion_inc_-2_B_oth")
      
             elseif random_number >= 16 and random_number <= 30
             then
             scripting.game_interface:trigger_custom_incident(tostring(faction_name), "PIGS_Intr_PoliticalPromotion_inc_-1_SB_oth")
      
             elseif random_number >= 31 and random_number <= 70
             then
             scripting.game_interface:trigger_custom_incident(tostring(faction_name), "PIGS_Intr_PoliticalPromotion_inc_0_AV")
      
             elseif random_number >= 71 and random_number <= 85
             then
             scripting.game_interface:trigger_custom_incident(tostring(faction_name), "PIGS_Intr_PoliticalPromotion_inc_1_SG_oth")
      
             elseif random_number >= 86 and random_number <= 92
             then
             scripting.game_interface:trigger_custom_incident(tostring(faction_name), "PIGS_Intr_PoliticalPromotion_inc_2_G_oth")
      
             elseif random_number >= 93 and random_number <= 94
             then
             scripting.game_interface:trigger_custom_incident(tostring(faction_name), "PIGS_Intr_PoliticalPromotion_inc_3_VG_pop")
      
             elseif random_number >= 95 and random_number <= 96
             then
             scripting.game_interface:trigger_custom_incident(tostring(faction_name), "PIGS_Intr_PoliticalPromotion_inc_3_VG_mil")
      
             elseif random_number >= 97 and random_number <= 98
             then
             scripting.game_interface:trigger_custom_incident(tostring(faction_name), "PIGS_Intr_PoliticalPromotion_inc_3_VG_rul")
       
             elseif random_number >= 99 and random_number <= 100
             then
             scripting.game_interface:trigger_custom_incident(tostring(faction_name), "PIGS_Intr_PoliticalPromotion_inc_3_VG_oth")
             
             end
         end    
     end
    
    -- .....
    
    -- ###---------------------------------- END*    
      
     -- ###------------------------- START *******
     -- CALLBACKS ---------------------------------------------------------------------
     -- ###-------------------------
      
     scripting.AddEventCallBack("FactionTurnStart", PIGS_Intr_Random_seed);
    
     -- ###---------------------------------- END*
    Btw, one of these days I'm gonna open a closed group for scripters, me and other 4/5 guys.
    Would you be interested?
    Last edited by Jake Armitage; July 01, 2019 at 12:43 PM.

  3. #3
    valerius karamanus's Avatar Civis
    Join Date
    Dec 2018
    Location
    Constantinopolis
    Posts
    126

    Default Re: Trait triggers?

    Quote Originally Posted by Jake Armitage View Post
    Do you want to trigger a trait (chosed between more than one) with a dice roll?
    DeI used to have this but it was removed since it's not multiplayer friendly.

    Use the method I'm using for PIGS (DeI political overhaul)
    Here's part of the script, I'm using a different event to trigger custom politcal incidents but the concept/structure should be the same.
    It works 100% and I'm using it quite a lot lately.
    Yes that's what I wanted, I tried your script and it worked like magic! Very flexible code, allows many traits to be assigned at once and also with adjustable chances. It's a pity we can't make it multiplayer friendly though, I suppose dice rolls giving different numbers in different scripts would cause conflicts indeed. Pity because primary reason behind my script customizations is to play with my cousins :/

    If I share the mod someday, I will surely write your name on top of credits. Huge thanks!

    Btw, one of these days I'm gonna open a closed group for scripters, me and other 4/5 guys.
    Would you be interested?
    I'll PM you about this.

  4. #4
    Jake Armitage's Avatar Artifex
    Patrician

    Join Date
    Apr 2011
    Location
    apartment 6
    Posts
    4,694

    Default Re: Trait triggers?

    Good.

    Could be that one of the last lua functions released (with the political patch) might work with MP.
    Honestly I don't know but Litharion (the guy who did many scripts for DeI) hypotized that.

    function is: MODEL_SCRIPT_INTERFACE > random_number (check latest lua functions list)

    An example for the MODEL_SCRIPT_INTERFACE is: "scripting.game_interface:model():turn_number()"
    so this should work with: "scripting.game_interface:model():random_number()"
    Maybe you'll have to put something like: "scripting.game_interface:model():random_number(1, 100)"
    Maybe not, maybe is already set to roll a 100 dice.
    Really don't know.

    I would be really interested about that mod since I like the idea and I don't care about MP at all.
    Are you doing it for DeI or vanilla?
    Last edited by Jake Armitage; July 02, 2019 at 12:13 PM.

  5. #5
    valerius karamanus's Avatar Civis
    Join Date
    Dec 2018
    Location
    Constantinopolis
    Posts
    126

    Default Re: Trait triggers?

    DeI of course, I don't think I'll ever return to vanilla.

    My plan was to remove "brawler/commander/scholar" traits and implement "physical(age&health)/mental(intelligence&selfishness)/influental(popularity&wealth) attributes" traits instead. Partly inspired by EB2 trait system and partly inspired by General's Status feature from your submod PIGS. After some thoughts, I agreed with your ideas of "randomness instead of arcadey levelling up characters", and tried to find a way to combine random upbringings with improvable aspects. With your code working just like I wanted, things are looking good.

    Nowadays I wonder about those "pietas", "libertas", "fortunas" etc. traits. I can't find effect.skill function so I assume they are classified traits as well, but why are they assigned to skill table?
    I will investigate those once I'm finished with traits. I would really like to assign some traits like "wounded" after battles to characters with low health trait for example.

  6. #6
    Jake Armitage's Avatar Artifex
    Patrician

    Join Date
    Apr 2011
    Location
    apartment 6
    Posts
    4,694

    Default Re: Trait triggers?

    there is a "force_add_skill" into GAME
    should be something like:
    if....
    then
    scripting.game_interface:force_add_skill("skillname", character) - not sure 100%

    character comes from:
    local character = context:character():cqi()
    cqi is a key identifier for the character

    then there is
    "has_skill" under CHARACTER_SCRIPT_INTERFACE if it's needed as a condition
    should be something like:
    if context:character():has_skill("skillname")
    then...

    Idea seems good and I remember you were talking about something similar where I suggested using an incident/dilemma condition (which I still have to verify how/if it works)

    That's exactly the reason why I would like to open that group for scripters. Consider it.
    We can lend a hand each other, avoid having similar submods and so unique and better ones done by a group and keep all infos inside one place instead of having them around various forums.
    Last edited by Jake Armitage; July 03, 2019 at 05:22 AM.

  7. #7
    valerius karamanus's Avatar Civis
    Join Date
    Dec 2018
    Location
    Constantinopolis
    Posts
    126

    Default Re: Trait triggers?

    Trying to force a skill to chars for two whole days, with different char lookups, skill keys and other stuff in many possible ways, and result is frustratingly zero. I was not able to add a second skill alongside the background one.

    We are unlucky for not having good examples about these skills and traits section. It is basically an unexplored frontier.

  8. #8
    Jake Armitage's Avatar Artifex
    Patrician

    Join Date
    Apr 2011
    Location
    apartment 6
    Posts
    4,694

    Default Re: Trait triggers?

    You have to paste what you've done otherwise I have no idea where to start for an answer.

  9. #9
    valerius karamanus's Avatar Civis
    Join Date
    Dec 2018
    Location
    Constantinopolis
    Posts
    126

    Default Re: Trait triggers?

    Okay for example this was one of my first tries;
    Spoiler Alert, click show to read: 
    Code:
    function testskillassign_impl(context)
    return char_is_general(context:character()) and context:character():has_garrison_residence() 
    end
    
    
    function TestSkillAssign(context)
        if context:character():faction():is_human() == true
        then
        local character = context:character():cqi()
            if testskillassign_impl(context)
            then
            scripting.game_interface:force_add_skill("general_background_non_roman_personal_prudence", character)
            end
        end
    end
    
    scripting.AddEventCallBack("CharacterTurnEnd", TestSkillAssign);
    Changed order of skill_key and char identifier, didn't work. Then thought skill_key being one of the background skills could be the problem, so I created a new one, but to no avail.

    This was one another try.
    Spoiler Alert, click show to read: 
    Code:
    function testskillassign_impl(context)    return char_is_general(context:character()) and context:character():has_garrison_residence() 
    end
    
    
    function TestSkillAssign(context)
            local char_cqi = context:character():cqi()
            local char_lookup_str = cm:char_lookup_str(char_cqi)
                if testskillassign_impl(context)
                then
                cm:force_add_skill(char_lookup_str, "general_test_skill")
        end
    end
    
    scripting.AddEventCallBack("CharacterTurnEnd", TestSkillAssign);


    Another try was with the other identify system with :faction and :name with help of one of your char death scripts.
    Spoiler Alert, click show to read: 
    Code:
     function testskillassign_impl(context)    return char_is_general(context:character()) and context:character():has_garrison_residence() 
    end
    
    
    function TestSkillAssign(context)
        faction = "faction:"..tostring(context:character():faction():name())
        forename = context:character():get_forename()
        forename = "forename:"..string.gsub(forename,"names_name_","")
        target = faction..","..forename
                if testskillassign_impl(context)
                then
                scripting.game_interface:force_add_skill(target, "general_test_skill")
        end
    end


    How would be your method for adding a skill to character in the ongoing campaign? I know that there are problems with removing it afterwards, but it really is not a worry for my case. I just want those to pile up.

  10. #10
    Jake Armitage's Avatar Artifex
    Patrician

    Join Date
    Apr 2011
    Location
    apartment 6
    Posts
    4,694

    Default Re: Trait triggers?

    Ok, I'll try to make it work

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •