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

Thread: [Scripting] Add money to AI controlled carthage

  1. #1

    Default [Scripting] Add money to AI controlled carthage

    Hey guys,

    since AI controlled Carthage keeps constantly dying after some dozens of turns (which is annoying me), I decided to try modding that issue. A money bonus via DB Editing apparently does a quite good job, but you need to set it to a pretty high value in order to get it to work properly. Main disadvantage: human players also receive this bonus, which messes up balancing (as does unit modding i.e. increasing unit values for Carthage).
    In Medieval 2, it was possible to add money to an AI controlled faction (and such factions only) on certain conditions, for example every turn's start or if a cartain region gets lost. I think something similar would help very much with AI Carthage, too without balancing issues. Has someone written some script for that? I'm not a programmer, so I bet I won't be able to write a completely new script at all. Maybe modifying an existing one might work.

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

    Default Re: [Scripting] Add money to AI controlled carthage

    it is possible. Example, this will add 2000 on every Carthage AI turn and 10000 on first turn.

    Spoiler Alert, click show to read: 

    PHP Code:
    function GetTurnNum()
    return 
    scripting.game_interface:model():turn_number();
    end

    local 
    function ScriptCarthage(context)
    turn_num GetTurnNum();
    if 
    context:faction():name() == "rom_carthage" 
    and context:faction():is_human() == false 
    and turn_num == 
    then scripting
    .game_interface:treasury_mod("rom_carthage"10000)
    elseif 
    context:faction():name() == "rom_carthage" 
    and context:faction():is_human() == false 
    then scripting
    .game_interface:treasury_mod("rom_carthage"2000)
    end
    end

    scripting
    .AddEventCallBack("FactionTurnStart"ScriptCarthage
    Last edited by Litharion; September 26, 2014 at 12:53 PM.

  3. #3

    Default Re: [Scripting] Add money to AI controlled carthage

    That's good news! At least it's working...the script itself isn't very complicated and quite easy to understand; however, the game's scripting files themself are definetly not. I haven't found any tutorials on scitping in either Rome 2 nor Shogun 2 which in my opinion should be similar. Do you know any? The point is that you have to get a clue of how the files are built up in order to start scripting.

  4. #4

    Default Re: [Scripting] Add money to AI controlled carthage

    if adding ones for multiple factions apart from changing "rom_carthage" to "rom_xxxxx" is there anything else i need to do?

    i currently have this but can't tell if it's working

    local function ScriptRome()
    if curr_faction:name() == "rom_rome"
    and curr_faction:is_human() == false
    then
    scripting.game_interface:treasury_mod("rom_rome", 1500)
    end
    end

    scripting.AddEventCallBack("FactionTurnStart", ScriptRome);

    local function ScriptCarthage()
    if curr_faction:name() == "rom_carthage"
    and curr_faction:is_human() == false
    then
    scripting.game_interface:treasury_mod("rom_carthage", 1500)
    end
    end

    scripting.AddEventCallBack("FactionTurnStart", ScriptCarthage);

    local function ScriptPtolemaics()
    if curr_faction:name() == "rom_ptolemaics"
    and curr_faction:is_human() == false
    then
    scripting.game_interface:treasury_mod("rom_ptolemaics", 1500)
    end
    end

    scripting.AddEventCallBack("FactionTurnStart", ScriptPtolemaics);

    ...
    Last edited by Balbor; September 25, 2014 at 02:51 PM.
    Balbor

    Former Creative Director
    Former Head Unit Modeller and Texture
    Fourth Age:Total War

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

    Default Re: [Scripting] Add money to AI controlled carthage

    well in theory those functions should work, where in the scripting files have you added them ? The Callbacks can be used at the end of the scripting file.
    You can check the AI money in a save game with ESF under Campaign_Model -> World -> Faction Array -> Faction -> Faction Economics.

    It is also possible to add more starting money to the AI on first turn and continue with smaller payments.
    The AI has usually has enough money later in the game, if you donīt adjust the AI Budget management, so it can spend more.
    Last edited by Litharion; September 26, 2014 at 12:50 PM.

  6. #6

    Default Re: [Scripting] Add money to AI controlled carthage

    The AI has usually has enough money later in the game, if you donīt adjust the AI Budget management, so it can spend more.
    Interesting...in fact I thought the budget management values in the DB tables to be something like "percent of total income to be spend on certain things". Your proposal about connecting additional money and turn numbers is therefor a good idea, since the main goal is to prevent Carthage & Co. from being wiped away by Syracuse around turn 10... Maybe we can use the number of regions controlled by a certain faction instead of turn number, like in MEII?

  7. #7
    Inevitability won
    Patrician Citizen

    Join Date
    Mar 2010
    Posts
    9,594

    Default Re: [Scripting] Add money to AI controlled carthage

    In your scripts you reference curr_faction, but you don't set what that variable is anywhere, so these scripts on their own won't do anything.

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

    Default Re: [Scripting] Add money to AI controlled carthage

    Quote Originally Posted by .Mitch. View Post
    In your scripts you reference curr_faction, but you don't set what that variable is anywhere, so these scripts on their own won't do anything.
    ah true and thank you :=). Forgot about the variable I am using it in the DeI scripts a lot....

    Now I feel pretty stupid but it should work this way in vanilla:

    PHP Code:
    function GetTurnNum()
    return 
    scripting.game_interface:model():turn_number();
    end

    local 
    function ScriptCarthage(context)
    turn_num GetTurnNum();
    if 
    context:faction():name() == "rom_carthage" 
    and context:faction():is_human() == false 
    and turn_num == 
    then scripting
    .game_interface:treasury_mod("rom_carthage"10000)
    elseif 
    context:faction():name() == "rom_carthage" 
    and context:faction():is_human() == false 
    then scripting
    .game_interface:treasury_mod("rom_carthage"2000)
    end
    end

    scripting
    .AddEventCallBack("FactionTurnStart"ScriptCarthage
    here is a working Carthage money script for vanilla http://www.mediafire.com/download/bw...ey_script.pack
    Last edited by Litharion; September 26, 2014 at 12:54 PM.

  9. #9

    Default Re: [Scripting] Add money to AI controlled carthage

    if adding more for other faction do i need the

    function GetTurnNum()
    return scripting.game_interface:model():turn_number();
    end

    at the start of do i just go to the

    local function ScriptCarthage(context)

    bit?
    Balbor

    Former Creative Director
    Former Head Unit Modeller and Texture
    Fourth Age:Total War

  10. #10
    Inevitability won
    Patrician Citizen

    Join Date
    Mar 2010
    Posts
    9,594

    Default Re: [Scripting] Add money to AI controlled carthage

    Here, you can adapt this really easily and it doesn't have a turn limit:

    PHP Code:
    local function ScriptMoney(context)

    if 
    context.string == "rom_rome" then
    scripting
    .game_interface:treasury_mod("rom_rome"2000);
    end

    if context.string == "rom_carthage" then
    scripting
    .game_interface:treasury_mod("rom_carthage"3000);
    end

    if context.string == "rom_ptolemaics" then
    scripting
    .game_interface:treasury_mod("rom_ptolemaics"4000);
    end

    end

    scripting
    .AddEventCallBack("FactionTurnStart"ScriptMoney
    Every start of a turn for every faction this will fire off, if the factions turn is one of these then that faction will receive the input money. Just copy the obvious block to add more factions.

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

    Default Re: [Scripting] Add money to AI controlled carthage

    the function GetTurnNum is only needed once and it needs no callback.

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

    Default Re: [Scripting] Add money to AI controlled carthage

    Quote Originally Posted by .Mitch. View Post
    Here, you can adapt this really easily and it doesn't have a turn limit:

    PHP Code:
    local function ScriptMoney(context)

    if 
    context.string == "rom_rome" then
    scripting
    .game_interface:treasury_mod("rom_rome"2000);
    end

    if context.string == "rom_carthage" then
    scripting
    .game_interface:treasury_mod("rom_carthage"3000);
    end

    if context.string == "rom_ptolemaics" then
    scripting
    .game_interface:treasury_mod("rom_ptolemaics"4000);
    end

    end

    scripting
    .AddEventCallBack("FactionTurnStart"ScriptMoney
    Every start of a turn for every faction this will fire off, if the factions turn is one of these then that faction will receive the input money. Just copy the obvious block to add more factions.
    is this working for the AI only, it seems to add the money to the player as well ?

  13. #13

    Default Re: [Scripting] Add money to AI controlled carthage

    Do we have some kind of Library for the implemented functions? I'm currently asking myself if something like "NumberRegionsControlled" exists in order to check the amount of regions under control of a certain faction (well, apparently)

  14. #14
    Inevitability won
    Patrician Citizen

    Join Date
    Mar 2010
    Posts
    9,594

    Default Re: [Scripting] Add money to AI controlled carthage

    Yes we do: http://www.twcenter.net/forums/showt...functions-list

    I created that, but it's damn ugly and was honestly most a resource for myself as I know the usage of it all already, obviously not very useful to most.

    I've been meaning to do a scripting tutorial that also has usage examples of all the usable functions... it's like 20% written up just haven't had time to get around to it.

    EDIT: To answer your question.. Yes such a thing exists.

    You can via the faction interface use the region_list var to get a list of regions held by a faction and then through the region list interface use the num_items var.

    So to adapt the code above you could do:
    PHP Code:
    local function CountRegions(context)

    if 
    context.string == "rom_rome" then
    local region_count 
    context:faction():region_list():num_items();
    end

    end

    scripting
    .AddEventCallBack("FactionTurnStart"CountRegions
    Here on the start of a factions turn we check if its Romes turn and if so we set region_count to hold the number of regions they have.
    Last edited by .Mitch.; September 30, 2014 at 12:54 PM.

  15. #15

    Default Re: [Scripting] Add money to AI controlled carthage

    Exellent, Mitch, many thanks! Your list looks quite impressive, I've already several ideas in mind for scripts just looking through the items. Now I have to learn more about lua, since I'm absolutely no programming pro. I used to play around with some basics in Java some time ago, but didn't get very deep into it. My knowledge is therefor sufficient to get a basic grasp of the scripts functionality, but the notation is to some extent really unfamiliar.

  16. #16

    Default Re: [Scripting] Add money to AI controlled carthage

    so is it possible to do a money script that only works on the ai?
    Balbor

    Former Creative Director
    Former Head Unit Modeller and Texture
    Fourth Age:Total War

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

    Default Re: [Scripting] Add money to AI controlled carthage

    yes, of course it is.

    Spoiler Alert, click show to read: 
    PHP Code:

    local 
    function ScriptRome(context)
    if 
    context:faction():name() == "rom_rome" 
    and context:faction():is_human() == false
    then
    scripting
    .game_interface:treasury_mod("rom_rome"1500)
    end
    end

    scripting
    .AddEventCallBack("FactionTurnStart"ScriptRome); 
    Last edited by Litharion; October 01, 2014 at 02:43 PM.

  18. #18

    Default Re: [Scripting] Add money to AI controlled carthage

    I looked through some lua tutorials, but didn't find any information on the : operator. I don't really understand the difference between "." and ":". If I get it right, they are both used to get control over some functions in the block before the :?

  19. #19
    Inevitability won
    Patrician Citizen

    Join Date
    Mar 2010
    Posts
    9,594

    Default Re: [Scripting] Add money to AI controlled carthage

    Firstly, only knowing when to use ":" or "." is necessary for modding (unless you plan to make complex functions). Layman rule of thumb is if it begins with context then use ":", otherwise use ".".

    Though to go a bit further, as you say the colon and period operators both give access to the preceding object, all aspects of Lua's object orientation. The colon is used in Lua where you have an implied self parameter passed.

    So...
    context.faction(self).name(self)
    is the same as...
    context:faction():name()

    What self is is basically a way to determine the identity of an object independent of its value, so two objects with the same value are different objects. Really not needed in most modding though.

    Further reading: http://www.lua.org/pil/16.html

  20. #20

    Default Re: [Scripting] Add money to AI controlled carthage

    Awesome! Think I got it, thank you! +rep

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
  •