Page 1 of 2 12 LastLast
Results 1 to 20 of 21

Thread: Unit count requirement for stances (Partol / Raiding)

  1. #1

    Default Unit count requirement for stances (Partol / Raiding)

    Hi,

    It's been a while since I've last bothered you with my questions but this I can't figure out. All in all DeI scripting mechanisms are quite complex and there must be a line for this too because none can be found in effect bundles So how can I change the unit requirement count for these stances?

  2. #2

    Default Re: Unit count requirement for stances (Partol / Raiding)

    lua_scripts - army_caps.lua
    Code:
    local function OnCharacterSelected(context)
    	if isPlayerTurn() then
    		-- Double time removal
    		local navy_stance_group = scripting.m_root:Find("naval_stance_button_stack");
    		if navy_stance_group then
    			local double_time_stance = UIComponent(navy_stance_group):Find("button_double_time");
    			UIComponent(double_time_stance):SetDisabled(true);
    			UIComponent(double_time_stance):SetVisible(false);
    		end
    	end
    	-- Gets current char
    	curr_character = nil;
    	sel_char, sel_char_name = context:character(), context:character():get_forename();
    
    
    	-- If the character selected is not of the local faction we skip the process
    	if (sel_char:faction():name() ~= curr_local_faction_name) then return end;
    
    
    	Log("Character Selected");
                    if sel_char:has_garrison_residence() then
    		-- Forced March removal
    		local army_stance_group = scripting.m_root:Find("land_stance_button_stack");
    		if army_stance_group then
    			local forced_army_stance = UIComponent(army_stance_group):Find("button_forced_march");
    			UIComponent(forced_army_stance):SetDisabled(true);
    			-- UIComponent(forced_army_stance):SetVisible(false);
    		end
    
    
    
    
                    elseif sel_char:military_force():unit_list():num_items() < 3 then
    		-- Forced March removal
    		local army_stance_group = scripting.m_root:Find("land_stance_button_stack");
    		if army_stance_group then
    			local forced_army_stance = UIComponent(army_stance_group):Find("button_forced_march");
    			UIComponent(forced_army_stance):SetDisabled(true);
    			UIComponent(forced_army_stance):SetVisible(false);
    		end
    
    
                    elseif sel_char:military_force():unit_list():num_items() >= 3 then
    		-- Forced March add
    		local army_stance_group = scripting.m_root:Find("land_stance_button_stack");
    		if army_stance_group then
    			local forced_army_stance = UIComponent(army_stance_group):Find("button_forced_march");
    			UIComponent(forced_army_stance):SetDisabled(false);
    			UIComponent(forced_army_stance):SetVisible(true);
    		end
    
    
    	end
    
    
    	-- Check if the character has units
    	if sel_char:has_military_force() then
    		Log("> Character has a military force, checking what to do >");
    		curr_character = character:get(sel_char) or character:new(sel_char);
    		old_character = curr_character;
    		Log("< Check ended");
    	elseif old_character then old_character = nil end
    end
    
    
    local function OnCharacterSelected2(context)
    	-- Gets current char
    	curr_character = nil;
    	sel_char, sel_char_name = context:character(), context:character():get_forename();
    
    
    	-- If the character selected is not of the local faction we skip the process
    	if (sel_char:faction():name() ~= curr_local_faction_name) then return end;
    
    
    	Log("Character Selected");
                    if sel_char:military_force():unit_list():num_items() < 4 then
    		-- raid
    		local army_stance_group2 = scripting.m_root:Find("land_stance_button_stack");
    		if army_stance_group2 then
    			local forced_army_stance2 = UIComponent(army_stance_group2):Find("button_raid");
    			UIComponent(forced_army_stance2):SetDisabled(true);
    			UIComponent(forced_army_stance2):SetVisible(false);
    		end
    
    
                    elseif sel_char:military_force():unit_list():num_items() >= 4 then
    		-- raid
    		local army_stance_group2 = scripting.m_root:Find("land_stance_button_stack");
    		if army_stance_group2 then
    			local forced_army_stance2 = UIComponent(army_stance_group2):Find("button_raid");
    			UIComponent(forced_army_stance2):SetDisabled(false);
    			UIComponent(forced_army_stance2):SetVisible(true);
    		end
    
    
    	end
    
    
    	-- Check if the character has units
    	if sel_char:has_military_force() then
    		Log("> Character has a military force, checking what to do >");
    		curr_character = character:get(sel_char) or character:new(sel_char);
    		old_character = curr_character;
    		Log("< Check ended");
    	elseif old_character then old_character = nil end
    end
    First function removes fleet double time and also changes forced march (which is patrol region). The second function is for raiding.

    ----> Website -- Patreon -- Steam -- Forums -- Youtube -- Facebook <----

  3. #3

    Default Re: Unit count requirement for stances (Partol / Raiding)

    Quote Originally Posted by MrTimbe68 View Post
    Hi,

    It's been a while since I've last bothered you with my questions but this I can't figure out. All in all DeI scripting mechanisms are quite complex and there must be a line for this too because none can be found in effect bundles So how can I change the unit requirement count for these stances?
    Curious, are you adding the units needed or lowering it?

  4. #4

    Default Re: Unit count requirement for stances (Partol / Raiding)

    Thanks Dresden, you're the best!

    Hi,
    I just felt that the number should be a bit higher, especially for the raiding part. There's lots of changes in 1.2 for the better but I just want to ad up or change these little things a bit
    Last edited by ♔Greek Strategos♔; October 09, 2018 at 06:40 AM. Reason: Merged posts.

  5. #5
    Civis
    Join Date
    Sep 2010
    Location
    Lithuania
    Posts
    153

    Default Re: Unit count requirement for stances (Partol / Raiding)

    Dresden, how does AI function with patrol stance(forced march before) ? Did you script it to function properly ?

  6. #6

    Default Re: Unit count requirement for stances (Partol / Raiding)

    It functions normally - it can raid with less units than the player simply because our restriction is just a UI one (removes the button).

    For patrol region stance, they don't use it and don't need to, its mainly there for the player since garrisoning troops is a PO negative.

    ----> Website -- Patreon -- Steam -- Forums -- Youtube -- Facebook <----

  7. #7

    Default Re: Unit count requirement for stances (Partol / Raiding)

    Quote Originally Posted by Dresden View Post
    It functions normally - it can raid with less units than the player simply because our restriction is just a UI one (removes the button).

    For patrol region stance, they don't use it and don't need to, its mainly there for the player since garrisoning troops is a PO negative.
    This was actually a little disappointment to me because I actually believed that "removing the button" would affect Ai too So theres no real restrictions to these stances whitch would take action both ways. This I believe is something that just have to be accepted.

  8. #8

    Default Re: Unit count requirement for stances (Partol / Raiding)

    Quote Originally Posted by Dresden View Post
    -- Check if the character has units
    if sel_char:has_military_force() then
    Log("> Character has a military force, checking what to do >");
    curr_character = character:get(sel_char) or character:new(sel_char);
    old_character = curr_character;
    Log("< Check ended");
    elseif old_character then old_character = nil end
    end
    [/code]First function removes fleet double time and also changes forced march (which is patrol region). The second function is for raiding.
    Hi Dresden,
    can you help me with something related here ?
    I'm struggling to adapt testudo stances function on number of units in an army (not the classic testudo way), and have this lua:
    --============================
    -- The content of the script belongs to DeI and as such cannot be used elsewhere without express consent.
    -- This in an adaptation of DeI original scripts for TESTUDO Stances by Jake Armitage (DeI submod).
    --================================

    -- Make the script a module one
    module(..., package.seeall);

    -- Used to have the object library able to see the variables in this new environment
    _G.main_env = getfenv(1);

    -- Load libraries
    scripting = require "lua_scripts.EpisodicScripting";
    require "DeI_utility_functions";
    local dev = require "lua_scripts.dev"
    local scripting = require "lua_scripts.EpisodicScripting"
    local world = require "lua_scripts.world"


    --===========================================================
    -- TESTUDO stances
    --===========================================================

    local function TESTUDO_stances(context)
    local army = context:character():cqi();
    if context:character():faction():is_human() == true
    and context:character():has_military_force() == true
    and context:character():has_garrison_residence() == false
    and (char_is_general_with_army(context:character()))
    then
    if context:character():military_force():unit_list():num_items() = 1
    then
    scripting.game_interface:apply_effect_bundle_to_characters_force("TESTUDO_stan_1", army,1);

    if context:character():military_force():unit_list():num_items() = 2
    then
    scripting.game_interface:apply_effect_bundle_to_characters_force("TESTUDO_stan_3", army,1);

    end;
    end;
    end;

    -----------------------------------------
    scripting.AddEventCallBack("CharacterTurnStart", TESTUDO_stances)
    scripting.AddEventCallBack("LoadingGame", Load_Values)
    scripting.AddEventCallBack("SavingGame", Save_Values)

    --------------------------------------------

    local dev = require "lua_scripts.dev"
    local scripting = require "lua_scripts.EpisodicScripting"
    local world = require "lua_scripts.world"

    -- UI check
    local function forcedMarchSet(context)
    local army_stance_group = scripting.m_root:Find("land_stance_button_stack")
    if world.isPlayerTurn() and army_stance_group then
    local button_forcedMarch = UIComponent(army_stance_group):Find("button_forced_march");
    UIComponent(button_forcedMarch):SetDisabled(false);
    UIComponent(button_forcedMarch):SetVisible(true);
    if UIComponent(button_forcedMarch) SetVisible(true) then scripting.AddEventCallBack(''CharacterSelected'', TESTUDO_stances) --------------------here I think it's wrong syntax. All i want is to check if Stance is forced march and if yes then play local function TESTUDO_stances defined here first.
    end

    -- Callbacks
    scripting.AddEventCallBack("CharacterSelected", forcedMarchSet)

    dev.log("TESTUDO_stan.lua loaded").
    The test mod using it is here:https://ufile.io/8mtq6.
    Still not working. The problem I guess is at the code line indicated.
    Please, help.
    Cheers.


    P.S. To test it I only changed rom_general_local_mod_happiness to 100 for 1 unit army and to 200 for 2 unit army

  9. #9

    Default Re: Unit count requirement for stances (Partol / Raiding)

    I don't think thats how event call backs or the UI Component commands work at all. I honestly don't know exactly how to achieve what you are asking.

    ----> Website -- Patreon -- Steam -- Forums -- Youtube -- Facebook <----

  10. #10
    Jake Armitage's Avatar Artifex
    Patrician

    Join Date
    Apr 2011
    Location
    apartment 6
    Posts
    4,694

    Default Re: Unit count requirement for stances (Partol / Raiding)

    @ leo: check the changeCapital.lua, maybe there is something useful there.
    I'll try to use some of its parts for other things but there might be that "something useful", something with "Key" inside if i remember correctly

  11. #11

    Default Re: Unit count requirement for stances (Partol / Raiding)

    Quote Originally Posted by Jake Armitage View Post
    @ leo: check the changeCapital.lua, maybe there is something useful there.
    I'll try to use some of its parts for other things but there might be that "something useful", something with "Key" inside if i remember correctly
    Not found changeCapital.lua, only cap.lua. And there is no any 'key' inside the script.

  12. #12
    Jake Armitage's Avatar Artifex
    Patrician

    Join Date
    Apr 2011
    Location
    apartment 6
    Posts
    4,694

    Default Re: Unit count requirement for stances (Partol / Raiding)

    into DeI's first pack, not Rome's

  13. #13

    Default Re: Unit count requirement for stances (Partol / Raiding)

    Quote Originally Posted by Jake Armitage View Post
    into DeI's first pack, not Rome's
    I checked into a little more old version....yes, you're right. Found it.
    I think whole thing is something related to this syntax example:
    if context.string == "button_encyclopedia" then
    scripting.game_interface:add_time_trigger
    I bet my 50 cents is so easy......but requires a proper lua knowledge, which is missing me.
    But, rudely if context.string == "button_encyclopedia" then ......line can bassically be cloned with a ''stance button''.
    Second line, scripting.game_interface:add_time_trigger, execute an already db defined variables. My problem is how to change this execution with a new function, not a variable (that new function instead is going to define the variables, just like Testudo.lua).

  14. #14

    Default Re: Unit count requirement for stances (Partol / Raiding)

    Hello Jake ! Anything to say ?

  15. #15
    Jake Armitage's Avatar Artifex
    Patrician

    Join Date
    Apr 2011
    Location
    apartment 6
    Posts
    4,694

    Default Re: Unit count requirement for stances (Partol / Raiding)

    no, 'cause i've not begin to mod it.

    2 things have to say
    1) i can't find a "button" list. there are some buttons into UI but some used into vanilla script are not present. So i'm wondering if that button is simply taken from UI image
    2) could be there is another way through one of the script for inv campaign but i'm not sure about

    after i'll begin modding i'll report

  16. #16

    Default Re: Unit count requirement for stances (Partol / Raiding)

    Quote Originally Posted by Jake Armitage View Post
    no, 'cause i've not begin to mod it.

    2 things have to say
    1) i can't find a "button" list. there are some buttons into UI but some used into vanilla script are not present. So i'm wondering if that button is simply taken from UI image
    2) could be there is another way through one of the script for inv campaign but i'm not sure about

    after i'll begin modding i'll report
    meanwhile I made tests.
    I'm stuck at this:
    local function forcedMarchCheck(context)
    local army_stance_group = scripting.m_root:Find("land_stance_button_stack")
    if world.isPlayerTurn() and army_stance_group then
    local button_forcedMarch = UIComponent(army_stance_group):Find("button_forced_march");
    if UIComponent(button_forcedMarch)
    then scripting.game_function TESTUDO_stan.lua
    end
    end
    end

    -- Callbacks
    scripting.AddEventCallBack("CharacterSelected", forcedMarchCheck)

    dev.log("ui.lua loaded")
    And this is ui.lua.
    But not working because I don't know how to call/run a lua code from within another lua. Scripting.game_function It's not recognized. And I don't know where to find the list of the game functions.
    Last edited by leonardusius; October 12, 2018 at 08:38 AM.

  17. #17
    Jake Armitage's Avatar Artifex
    Patrician

    Join Date
    Apr 2011
    Location
    apartment 6
    Posts
    4,694

    Default Re: Unit count requirement for stances (Partol / Raiding)

    welcome to the club of random scripters

    ---

    local function forcedMarchCheck(context)
    local army_stance_group = scripting.m_root:Find("land_stance_button_stack")
    if world.isPlayerTurn() (never used that, dunno) and army_stance_group (i fear putting this way means nothing, seems like an unfinished phrase) then
    local button_forcedMarch = UIComponent(army_stance_group):Find("button_forced_march");
    end (an if needs an end afaik, otherwise use elseif, you can't put another if after a non closed if)
    if UIComponent(button_forcedMarch) (i fear putting this way means nothing, seems like an unfinished phrase)
    then scripting.game_function TESTUDO_stan.lua (never used that, dunno)
    end
    end
    end

    -- Callbacks
    scripting.AddEventCallBack("CharacterSelected", forcedMarchCheck)
    scripting.AddEventCallBack("ComponentLClickUp", forcedMarchCheck); you might need to use the ComponentLClickUp since you want to trigger an effect by pushing a button

    dev.log("ui.lua loaded") (what's this? did you copy that from some script? Which one? Where is that ui.lua?)

    ---

    Form my pov the syntax is mostly incorrect. Could be that following these from changeCapital.lua might be better
    Spoiler Alert, click show to read: 
    local function EncyclopediaButtonTick(context) if context.string == "button_encyclopedia" then
    scripting.game_interface:add_time_trigger("TriggerNewCapital", 0.1);
    return;
    end;
    end;

    local function CapitalTimeTrigger(context)
    if (context.string == "TriggerNewCapital") then CapitalChange()
    end;
    end;

    function CapitalChange()
    if NewCapitalRegionName ~= "none" then
    local regionKey = scripting.game_interface:model():world():region_manager():region_by_key(NewCapitalRegionName)
    local ownerKey = regionKey:owning_faction()
    local ownerName = ownerKey:name()
    local factionName = GetLocalFactionName()
    if isLocalFaction(ownerName)
    and ownerKey:is_human()
    and ownerName == factionName
    and ownerKey:treasury () > 4999
    and NewCapitalRegionName ~= ownerKey:home_region():name() then
    -- in theory we can add a move capital event for every region in the game this way the tooltip and dilemma texts will show the region name correctly
    -- button_encyclopedia will have a tooltip stating that it will only allow changes when money is >= 5000
    scripting.game_interface:trigger_custom_dilemma(ownerName, "move_capital_rome", "payload { set_capital "..NewCapitalRegionName.."; money -5000; }", "", true)
    end;
    end;
    end;

    But i'm absolutely not sure about, really, only trials (or a scripter pro) can tell. My advice is to strictly follow changeCapital.lua and adapt it to your needings, and then pray Holy Mary.
    I've left triggering from UI for now 'cause I really can't find how to "write" a button that's not already inside some existing script.


    list of lua functions (check Litharion's #12): http://www.twcenter.net/forums/showt...functions-list
    there should be a couple more from last update(check DLC capaign packs, like the scripting.lua into invasion.pack)

    Here are some useful links for "how to script". Even if they are for other TW games, since it's lua, should be quite the same, at least the concept:
    http://www.twcenter.net/forums/showthread.php?247053-Modding-The-Script-o-Rama
    http://www.twcenter.net/forums/showt...ed-27-03-2011)
    http://www.twcenter.net/forums/showt...ril-15th-2009)
    http://www.twcenter.net/forums/showt...-Script-o-Rama

    Last edited by Jake Armitage; October 13, 2018 at 05:31 PM.

  18. #18

    Default Re: Unit count requirement for stances (Partol / Raiding)

    Quote Originally Posted by Jake Armitage View Post
    welcome to the club of random scripters
    Thank you !
    Here is, off course, again a real shortage of real samaritean ......scripters.....as always were. Because are full of painted ones...
    Back 30 years ago, on time of Z80, I was real good with qbasic. Trying to make analogies with lua is not going anywhere. Every damn processing language is the expression of its author mentality: with some you're compatible, with others not. Exactly like in real life.
    The Basic (pre)language was indeed lightyear better than most other languages, way better than C+/C++. More intuitive, logic and simple. But 'capitalist' market move cut him down with a one ''economic'' blow. C++ owners were far 'richer' than Basic ones and C++ swallow whole all Basic animal. No more Basic again. Just like the story of the DR-DOS vs. MS-DOS. I used both and DR-DOS was superior in many ways. But with a clever economic movement Bill Gates struck the DR-DOS and discard it to the trash. No more DR-DOS and its bloodline never. Despite it was damn more promising. Maybe if DR-DOS would have survived we would have no more (weak) scores of WINDOWS versions. Good night, capitalist world ! Night is good !
    Basically we need something like that; just plain, short and simple:
    if isPlayerTurn() then
    local army_stance_group = scripting.m_root:Find("land_stance_button_stack");
    if army_stance_group then
    local forced_army_stance = UIComponent(army_stance_group);
    if UIComponent(army_stance_group) = UIComponent(forced_army_stance) then
    dofile ("TESTUDO_stan.lua") --maybe here we must indicate that this is an internal game function. I don't know what should be that function syntax. Or we may use
    local file = assert (loadfile("TESTUDO_stan.lua"))
    file ()
    Last edited by leonardusius; October 14, 2018 at 01:37 PM.

  19. #19
    ♔Greek Strategos♔'s Avatar THE BEARDED MACE
    Artifex Moderator Emeritus

    Join Date
    Feb 2008
    Location
    Athens, Greece
    Posts
    11,588

    Default Re: Unit count requirement for stances (Partol / Raiding)

    Quote Originally Posted by Jake Armitage View Post
    welcome to the club of random scripters
    Random but efficient nonetheless

  20. #20

    Default Re: Unit count requirement for stances (Partol / Raiding)

    Quote Originally Posted by ♔Greek Strategos♔ View Post
    Random but efficient nonetheless
    Sorry pal, but in this club efficiency isn't a requirement....

Page 1 of 2 12 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
  •