Page 2 of 5 FirstFirst 12345 LastLast
Results 21 to 40 of 92

Thread: [scripting] The "does this code work" - Thread

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default Re: [scripting] The "does this code work" - Thread

    Apologies for duoble-post!
    Continuing this thought, something like the following should work - as long as i'ts really possible to add new effect_bundles (effects seem to be not that important):
    Code:
    function addSqualor(context)
        if context:faction():imperium_level() >=4 and context:faction():is_human() == true then
        scripting.game_interface:apply_effect_bundle("name_of_added_bundle", "faction id", "1");
        end
    end
    scripting.addEventCallBack("FactionTurnStart", addSqualor);
    It's very simple, but plainly it should apply the effect of the selected bundle (for example a negative effect on public order) every single turn, as long as the imperium level is above or equal four. The effect continues just one turn, but the game should check the conditions again at the start of every new turn, so the whole thing can re-apply.

  2. #2
    Litharion's Avatar Artifex
    Join Date
    Sep 2013
    Location
    Germany
    Posts
    2,622

    Default Re: [scripting] The "does this code work" - Thread

    Quote Originally Posted by Fridericus Secundus View Post
    It's very simple, but plainly it should apply the effect of the selected bundle (for example a negative effect on public order) every single turn, as long as the imperium level is above or equal four. The effect continues just one turn, but the game should check the conditions again at the start of every new turn, so the whole thing can re-apply.
    the problem is that the apply effect bundle only seems to work with a "faction ID". If I could add the effect bundle to an individual character, I could use it instead of the "set_public_order_of_province_for_region" script. Your small script will work as the Imperium effects are faction wide. If I use the apply_effect_bundle script all characters/armies will cause the same PO negative like we currently have in DeI using a DB entry.

  3. #3

    Default Re: [scripting] The "does this code work" - Thread

    Quote Originally Posted by Litharion View Post
    the problem is that the apply effect bundle only seems to work with a "faction ID". If I could add the effect bundle to an individual character, I could use it instead of the "set_public_order_of_province_for_region" script. Your small script will work as the Imperium effects are faction wide. If I use the apply_effect_bundle script all characters/armies will cause the same PO negative like we currently have in DeI using a DB entry.
    I see. Most effects affect the whole faction, but you are implementing something like the public order bonus for an army while garrisoned. Tricky... But there must be some way since agents and armies can all provide such boni.
    Btw: my script causes a crash at the end of the loading bar, so something still is wrong. Maybe I used the factionID incorrectly, not "rom_rome" but "0", foe example.

  4. #4
    Litharion's Avatar Artifex
    Join Date
    Sep 2013
    Location
    Germany
    Posts
    2,622

    Default Re: [scripting] The "does this code work" - Thread

    Quote Originally Posted by Fridericus Secundus View Post
    I see. Most effects affect the whole faction, but you are implementing something like the public order bonus for an army while garrisoned. Tricky... But there must be some way since agents and armies can all provide such boni.
    Btw: my script causes a crash at the end of the loading bar, so something still is wrong. Maybe I used the factionID incorrectly, not "rom_rome" but "0", foe example.
    no the faction ID is right, but the number of turns is not a string so donīt use "Number", only the number is required.

  5. #5

    Default Re: [scripting] The "does this code work" - Thread

    That's what I did, however, it still crashes:
    Spoiler Alert, click show to read: 
    Code:
    function addSqualor(context)
        if context:faction():imperium_level() <=4 and context:faction():is_human() == true then
        scripting.game_interface:apply_effect_bundle("festive_delphi", "rom_macedon", "1");
        end
    end
    scripting.AddEventCallBack("FactionTurnStart", addSqualor)

    I didn't get Mitch's logging script to work either (simply doesn't put out any results), really frustrating.

  6. #6

    Default Re: [scripting] The "does this code work" - Thread

    Quote Originally Posted by Fridericus Secundus View Post
    That's what I did, however, it still crashes:
    Spoiler Alert, click show to read: 
    Code:
    function addSqualor(context)
        if context:faction():imperium_level() <=4 and context:faction():is_human() == true then
        scripting.game_interface:apply_effect_bundle("festive_delphi", "rom_macedon", "1");
        end
    end
    scripting.AddEventCallBack("FactionTurnStart", addSqualor)

    I didn't get Mitch's logging script to work either (simply doesn't put out any results), really frustrating.
    I'm not sure if you're active anymore Fridericus but I tried your code here on both grand campaign and empire divided campaign but I cannot get it to work. So I'm just wondering if you ever got this to actually work about 9 years ago haha.

    Here is my full code so you (or someone looking at this thread) know what I did:


    -- Load libraries
    local scripting = require "lua_scripts.EpisodicScripting"
    events = require "data.lua_scripts.events"
    module(..., package.seeall)


    function addSqualor(context)
    if context:faction():imperium_level() <=2 and context:faction():is_human() == true then
    scripting.game_interface:apply_effect_bundle("3c_plague_region", "3c_marcomanni", 1);


    end
    end
    scripting.AddEventCallBack("FactionTurnStart", addSqualor)


    Anyone know why this isn't working? Maybe the log is just not compatible with empire divided, or possibly the effect bundle just doesn't work with it. Who knows lol

  7. #7
    Litharion's Avatar Artifex
    Join Date
    Sep 2013
    Location
    Germany
    Posts
    2,622

    Default Re: [scripting] The "does this code work" - Thread

    it will work this way

    scripting.game_interface:apply_effect_bundle("festive_delphi", "rom_macedon", 1);

  8. #8

    Default Re: [scripting] The "does this code work" - Thread

    Ah yes, the string vs. integer thing... EPIC fail, sorry.

  9. #9
    Litharion's Avatar Artifex
    Join Date
    Sep 2013
    Location
    Germany
    Posts
    2,622

    Default Re: [scripting] The "does this code work" - Thread

    does anybody know how we can apply effects to specific regions via scripting ? In past lua based games it was possible to add region traits like effect.trait(Trait, "region", level, 100, context) but there are no region traits in Rome 2. The apply_effect_bundle only works for factions.

    If I want for example script a disease in Rom, I am unable to do it because I can not find a single command/effect that can be applied to the region only.

    I have similar problems with characters. The big issue with the effect.trait or scripting.game_interface:force_add_trait is that we only have 3 trait slots per character. The scripting.game_interface:force_add_skill could be a better solution, but unfortunately I have not found a way to remove a skill after adding one, this is required to simulate effects only for a limited period of time.

  10. #10
    Litharion's Avatar Artifex
    Join Date
    Sep 2013
    Location
    Germany
    Posts
    2,622

    Default Re: [scripting] The "does this code work" - Thread

    just to answer my question from above and let you know. I managed to apply and remove effects from armies with a new command I found in the Wrath of Sparta scripts.

    local char = context:character():cqi()
    scripting.game_interface:apply_effect_bundle_to_characters_force("effect_bundle_key", char, integer);
    scripting.game_interface:remove_effect_bundle_from_characters_force("effect_bundle_key", char);

  11. #11

    Default Re: [scripting] The "does this code work" - Thread

    Ok, I'm pretty certain that the code itself is correct in this pack because its created by Litharion in this thread.(I heard he's really good) The problem I think is implementation on my part. I am completely new to any form of scripting in R2 so I think I must have missed a basic step or something when it comes to scripting because I can't get this code to work for any faction. I include the back I use the script in but you can delete the db edits as they have nothing to do with the script.
    Attached Files Attached Files

  12. #12

    Default Re: [scripting] The "does this code work" - Thread

    I can't edit but I did change this line of code
    and context:faction():is_human() == false
    to
    and context:faction():is_human() == true.

    As well as rom_rome to rom_liguria for testing purposes.(Both didn't work) I use VV overhaul.

  13. #13
    Litharion's Avatar Artifex
    Join Date
    Sep 2013
    Location
    Germany
    Posts
    2,622

    Default Re: [scripting] The "does this code work" - Thread

    Quote Originally Posted by SquirrelP0acher View Post
    Ok, I'm pretty certain that the code itself is correct in this pack because its created by Litharion in this thread.(I heard he's really good) The problem I think is implementation on my part. I am completely new to any form of scripting in R2 so I think I must have missed a basic step or something when it comes to scripting because I can't get this code to work for any faction. I include the back I use the script in but you can delete the db edits as they have nothing to do with the script.
    okay.

    you created a new lua script

    money.lua

    but you did not add the script to a campaign or a libary used by the game.

    There are bascially two options, you can either add the script directly to the main_rome scripting.lua or you can add an external script like yours to a with:

    local money= require "lua_scripts.money"; (into scripting.lua)

    Quote Originally Posted by Col.KanKrusha View Post
    apologies for this question. If i make changes to campaign script will it load in a current game or do i need to start a new game. i have modified an effect to increase upkeep as empire expands and it doesnt seem to be doing anything in an already running game. here is the script
    local function kk_count_regions(context)
    local regioncount = context:faction():region_list():num_items()
    return regioncount
    end


    try this:

    local function increase_upkeep(context)
    if context:faction():is_human() == true then
    local region_count = context:faction():region_list():num_items()
    local faction = context:faction():name()
    if region_count >= 75 then
    scripting.game_interface:apply_effect_bundle("kk_growth_army_upkeep_3" ,faction, 2)
    scripting.game_interface:remove_effect_bundle("kk_growth_army_upkeep_1" ,faction)
    scripting.game_interface:remove_effect_bundle("kk_growth_army_upkeep_2" ,faction)
    end
    if region_count >= 40 and region_count < 75 then
    scripting.game_interface:apply_effect_bundle("kk_growth_army_upkeep_2" ,faction, 2)
    scripting.game_interface:remove_effect_bundle("kk_growth_army_upkeep_3" ,faction)
    scripting.game_interface:remove_effect_bundle("kk_growth_army_upkeep_1" ,faction)
    end
    if region_count >= 15 and region_count < 40 then
    scripting.game_interface:apply_effect_bundle("kk_growth_army_upkeep_1" ,faction, 2)
    scripting.game_interface:remove_effect_bundle("kk_growth_army_upkeep_2" ,faction)
    scripting.game_interface:remove_effect_bundle("kk_growth_army_upkeep_3" ,faction)
    end
    end
    end

    ------------
    -- Kankrusha custom callbacks
    --------------------------------------------------------------------------------------
    scripting.AddEventCallBack("FactionTurnStart", increase_upkeep)
    Last edited by Litharion; February 05, 2015 at 06:42 AM.

  14. #14
    Linke's Avatar Hazarapatish
    Join Date
    Apr 2014
    Location
    Stockholm
    Posts
    1,800

    Default Re: [scripting] The "does this code work" - Thread

    Code:
    ~~~<<make.Roman.Ai.not.die>>~~~

  15. #15
    Semisalis
    Join Date
    Sep 2011
    Location
    New Zealand
    Posts
    412

    Default Re: [scripting] The "does this code work" - Thread

    apologies for this question. If i make changes to campaign script will it load in a current game or do i need to start a new game. i have modified an effect to increase upkeep as empire expands and it doesnt seem to be doing anything in an already running game. here is the script

    Code:
    local function kk_count_regions(context)
            local regioncount = context:faction():region_list():num_items()
            return regioncount
    end
    
    
    local function increase_upkeep(context)
        if context:faction():is_human() == true then
    			local region_count = kk_count_regions(context)
                       if region_count >= 75 then
                 scripting.game_interface:apply_effect_bundle("kk_growth_army_upkeep_3" ,context, 1)
             end
    	if region_count >= 40 and region_count < 75 then
                scripting.game_interface:apply_effect_bundle("kk_growth_army_upkeep_2" ,context, 1)
            end
    	if region_count >= 15 and region_count < 40 then
                scripting.game_interface:apply_effect_bundle("kk_growth_army_upkeep_1" ,context, 1)
             end
        end
    end
    
    
    
    
    --------------------------------------------------------------------------------------------------------------------
    -- Add event callbacks
    -- For a list of all events supported create a "documentation" directory in your empire directory, run a debug build of the game and see
    -- the events.txt file
    --------------------------------------------------------------------------------------------------------------------
    
    
    scripting.AddEventCallBack("NewCampaignStarted", OnNewCampaignStarted)
    scripting.AddEventCallBack("UICreated", OnUICreated)
    
    
    scripting.AddEventCallBack("AdviceIssued", OnAdviceIssued)
    scripting.AddEventCallBack("AdviceDismissed", OnAdviceDismissed)
    scripting.AddEventCallBack("CameraMoverFinished", OnCameraMoverFinished)
    scripting.AddEventCallBack("FactionTurnStart", OnFactionTurnStart)
    scripting.AddEventCallBack("ComponentLClickUp", OnComponentLClickUp)
    
    
    scripting.AddEventCallBack("TimeTrigger", OnTimeTrigger)
    
    
    --------------------------------------------------------------------------------------
    -- Kankrusha custom callbacks
    --------------------------------------------------------------------------------------
    scripting.AddEventCallBack("FactionTurnStart", increase_upkeep)
    ~ Too soon old, too late smart ~

  16. #16

    Default Re: [scripting] The "does this code work" - Thread

    Ok, I tried running vanilla with just the external script and command in scripting.lua but still zilch lol. I changed the target faction to iceni
    Attached Files Attached Files

  17. #17

    Default Re: [scripting] The "does this code work" - Thread

    Tried moving the command to the end of the scripting.lua but no effect.

  18. #18
    Semisalis
    Join Date
    Sep 2011
    Location
    New Zealand
    Posts
    412

    Default Re: [scripting] The "does this code work" - Thread

    You didn't create the file in word pad or word did you?

    and thanks to litharion. Should it be :

    factionname=context.string ?

    edit - arrggh been fighting this function all day. Just shut down my computer and I started wondering if the problem was trying to use context instead of context:faction():name() for the region count
    Last edited by Col.KanKrusha; February 06, 2015 at 12:46 AM.
    ~ Too soon old, too late smart ~

  19. #19
    Litharion's Avatar Artifex
    Join Date
    Sep 2013
    Location
    Germany
    Posts
    2,622

    Default Re: [scripting] The "does this code work" - Thread

    Quote Originally Posted by Col.KanKrusha View Post
    You didn't create the file in word pad or word did you?

    and thanks to litharion. Should it be :

    factionname=context.string ?

    edit - arrggh been fighting this function all day. Just shut down my computer and I started wondering if the problem was trying to use context instead of context:faction():name() for the region count
    with the small adjustments to your function it will work perfectly. As far as I can tell the scripting command apply_effect_bundle needs the faction name and not the id or something, this is why I made sure the name is given to the command.

    local faction = context:faction():name()
    another option
    local faction = context.string;

    scripting.game_interface:remove_effect_bundle("BUNDLE_NAME" ,faction)
    Last edited by Litharion; February 06, 2015 at 07:23 PM.

  20. #20
    Semisalis
    Join Date
    Sep 2011
    Location
    New Zealand
    Posts
    412

    Default Re: [scripting] The "does this code work" - Thread

    Okay I figured out apply_effect_bundle requires a numerical arguement at the end but I have no idea what value to use as i have seen everything from -1 to 100 or 400 used in various scripts


    any ideas?
    ~ Too soon old, too late smart ~

Page 2 of 5 FirstFirst 12345 LastLast

Posting Permissions

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