Page 3 of 5 FirstFirst 12345 LastLast
Results 41 to 60 of 92

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

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Inevitability won
    Patrician Citizen

    Join Date
    Mar 2010
    Posts
    9,594

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

    The number is for how many turns the effect is applied. -1 equals infinite.

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

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

    Thanks, I think the errors must be in my tables then. Back to the tutorial!
    ~ Too soon old, too late smart ~

  3. #3

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

    Anyone know if it is even possible to script treaties after start turn or after so many turns? I was thinking of 3 instances were I might use this type of script. 1. turning Cimmeria into a client kingdom of Pontus around probably 200 BC like it was historically at first. 2. Creating a confederacy or a similar function(defensive alliance and military access pact) between Gaul(Averni, Pictones, Namnetes, Carnutes) around 120 BC for Caesar's invasion. 3. Another "confederacy/ similar function for Germania around 25 BC.

  4. #4

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

    Looks like it mess up the format just pasting it from my program...

  5. #5

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

    Actually I'd rather it not be based on turn number but only if they come into contact with one another. So I think this would be the layout. You think either is possible? I noticed that there is a lua function to force_make_vassal could even go with that being vassals of arverni instead of the confederation, i'd just change up the satrapy text. I could even go with a military alliance between all of them. I just want them united in some way to make Gaul alot harder to take. If this can work I'd definitely also make this for some of the German factions.




    PHP Code:

    local gaul 
    false


    function Gallic Confederation    if arverni and rome faction_exist and arverni are not human and are visible/in contact to each other   
    (set variable gaul to true)    Else continue to check each turnend

    function confederationif gaul true    
    namnetes force_make_confederation
    /force_diplomcy condefederation  with arverni    pictones force_make_confederation/force_diplomcy condefederation  with arverni    carnutes force_make_confederation/force_diplomcy condefederation  with arverni    arverni treasury_mod 10,000 per turnend 

  6. #6

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


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

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

    hi poacher

    Some of what you want to do is possible but I dont think there is a way to force confederacy. Do you own Caesar in Gaul? There is script there that changes the AI's stance towards themselves and towards a mutual enemy to kind of produce what you want. In the end, it is better to copy what has been done before but you can try to do it in a new way

    the CiG script uses this
    scripting.game_interface:cai_strategic_stance_manager_promote_specified_stance_towards_target_faction(value:name(), nearby_factions_dislike_target[i]:name(), "CAI_STRATEGIC_STANCE_FRIENDLY")

    and this
    scripting.game_interface:cai_strategic_stance_manager_promote_specified_stance_towards_target_faction(nearby_factions_dislike_target[i]:name(), target_faction:name(), "CAI_STRATEGIC_STANCE_BITTER_ENEMIES")

    Otherwise you can force_diplomacy an alliance

    You need to look at the following pages:
    Mitch has listed the currently active Lua commands here http://www.twcenter.net/forums/showt...functions-list

    This Napoleon page has some of the arguments you need for force diplomacy http://www.twcenter.net/forums/showt...pting-Commands

    I find the shogun 2 script o rama a fantastic resource http://www.twcenter.net/forums/showt...-Script-o-Rama
    Last edited by Col.KanKrusha; February 28, 2015 at 07:42 PM.
    ~ Too soon old, too late smart ~

  8. #8

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

    Thanks a lot. I'm definitely about to attempt it.

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

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

    Have you scripted with Lua before? I am not sure from looking at what you have written. If you have not then be warned, it can be very frustrating finding why code doesn't work (usually a very hard to spot typo)

    edit- if you haven't get a program called Scite for Lua (Google). It will check your code for errors
    Last edited by Col.KanKrusha; March 01, 2015 at 11:50 AM.
    ~ Too soon old, too late smart ~

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

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

    Okay, my turn. This does not work - cant see why (sigh). It is pasted in at the bottom of my scripting.lua

    Code:
    local function kk_helpcarthage(context)                   
                  if conditions.FactionIsLocal(context) and  conditions.TurnNumber (context) == 1 then
                         scripting.game_interface:force_make_trade_agreement ("rom_carthage", "rom_rome")
                         scripting.game_interface:force_make_trade_agreement ("rom_carthage", "rom_etruscan")
                         scripting.game_interface:force_make_trade_agreement ("rom_carthage", "rom_epirus")
                 end
    end
    
    
    scripting.AddEventCallBack("FactionTurnStart", kk_helpcarthage)
    I originally was trying to do an Iceni-carthage-rhodes-pergamon trade route but then I wondered if it didnt work because of fog of war. above still does not work
    Last edited by Col.KanKrusha; March 22, 2015 at 02:45 AM.
    ~ Too soon old, too late smart ~

  11. #11

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

    Hi, Kankrusha. I think maybe you miss ";" at the end of these commonds. Otherwise you can try the commonds like this "cm:force_make_trade_agreement ("rom_carthage", "rom_rome");".I'm not sure and I haven't played it for a while so I couldn't test it for you now but more advice for you from me is that using the existing scripts as many as possible and try finding them in the other *.lua, official or mod it doesn't matter. Sometimes it's very hard to create new commonds for us self-taught.

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

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

    Has anyone a good idea on how we could determine if the current season is for example "summer" in a 4 turns per year campaign ?

    We know:
    Spring = turn number 1
    Summer = turn number 2
    Autumn = turn number 3
    Winter = turn number 4

    currently I am using this:


    WIP example
    PHP Code:
    function Summer()  
      if 
    turn_number 2 then     
     
    if last_summer == turn_number     
       then last_summer 
    turn_number           
     
    return true   
    elseif turn_number == 2 then       
       then last_summer 
    turn_number        
      
    return true     
     end   
    end
    end 


    any better ideas ?

  13. #13
    Inevitability won
    Patrician Citizen

    Join Date
    Mar 2010
    Posts
    9,594

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

    Use the season function from the model interface.

    scripting.game_interface:model():season()

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

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

    oh ....

    Thank you !


    edit
    interesting:

    scripting.game_interface:model():season()

    returns integer

    1 for Summer
    2 for Autumn
    3 for Winter
    0 for Spring
    Last edited by Litharion; June 08, 2015 at 10:45 AM.

  15. #15

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

    Anyone know if its possible to script a name change? For example, having rom_parthia's name set to "Parni" in the text files. Then, if they ever take control of the other 3 regions in Parthia, the script changes their name to "Arsacid Empire". Would something like this be possible?

  16. #16
    VINC.XXIII's Avatar Retired
    Join Date
    Mar 2009
    Location
    Oxybian hills
    Posts
    4,642

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

    Hello, I would like to create a Defense script similar to ones of Hannibal at Gates DLC, thats kind of scripted garrisons. At the lone difference the script should be enabled not matter if the attackers/defenders are humans or AI and not matter if they're a minor or major faction.


    I've duplicated a fragment and changed locations and units, but I guess this do not work because of the function Spawn_Minor_Faction_Defenses(). Advice in the script says these scripts only apply when a minor faction human attack Rome AI or Carthage AI: "-- This script spawns and manages defenders in Carthage and Rome if the player plays as one of the minor factions, to prevent them rolling over the big cities too easily"

  17. #17
    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 VINC.XXIII View Post
    Hello, I would like to create a Defense script similar to ones of Hannibal at Gates DLC, thats kind of scripted garrisons. At the lone difference the script should be enabled not matter if the attackers/defenders are humans or AI and not matter if they're a minor or major faction.
    I've duplicated a fragment and changed locations and units, but I guess this do not work because of the function Spawn_Minor_Faction_Defenses(). Advice in the script says these scripts only apply when a minor faction human attack Rome AI or Carthage AI: "-- This script spawns and manages defenders in Carthage and Rome if the player plays as one of the minor factions, to prevent them rolling over the big cities too easily"
    The function Spawn_Minor_Faction_Defenses() will work, if you call it on campaign start for example. Take a look at main_punic/factions/pun_arevaci.lua

    function faction_each_sp_game_startup()
    output("faction_each_sp_game_startup() called");

    -- put stuff here to be initialised each time a singleplayer game loads
    Start_Minor_Faction_Defenses();
    end;


    In HatG the function is called for the faction you play, if it is a minor one the script starts. The function itself does not contain any restrains.

    Quote Originally Posted by lnrd907 View Post
    Anyone know if its possible to script a name change? For example, having rom_parthia's name set to "Parni" in the text files. Then, if they ever take control of the other 3 regions in Parthia, the script changes their name to "Arsacid Empire". Would something like this be possible?
    This is probably only possible, if you change the UI elements containing the faction name, pretty complicated.

    something like this

    UIComponent(COMPOMENT containing the name):SetStateText(NEW name);

    but you would need to to it for all Components containing the name...

  18. #18
    VINC.XXIII's Avatar Retired
    Join Date
    Mar 2009
    Location
    Oxybian hills
    Posts
    4,642

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

    Quote Originally Posted by Litharion View Post
    In HatG the function is called for the faction you play, if it is a minor one the script starts. The function itself does not contain any restrains.
    its work fine now, I've changed both pun_minor_faction_defense and pun_rome.lua, just duplicating lusitani.lua. Thanks and +rep Litharion.

  19. #19

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

    Hi all,
    Anyone knows the correct parameters for " force_rebellion_in_region " or "set_event_generation_enabled" in GAME interface?
    I mean if for "force_declare_war" the correct syntax would be (as an example) : scripting.game_interface:force_declare_war ("rom_carthage", "rom_rome")
    How we should syntax the above commands?
    Thanks in advance for any answer.
    Cheers.

    EDIT
    1) I found a workaround for the first.You can give a low PO for a region with "set_public_order_of_province_for_region" and the rebellion happens as a result in the next turn.
    2)I think the "set_event_generation_enabled" does not enable a desired event.I think it only enables event generation.What i would really like is a way to force an event happening.You think ForceEvent in FACTION_LIST_SCRIPT_INTERFACE does that? and how?
    thanks.
    Last edited by Phalangitis; September 02, 2015 at 08:46 PM.

  20. #20

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

    Hi,
    has someone any experiences with the create_agent function and its parameters? I've written this in order to get a debug spy in Sicily, so I can check out how AI recruits and composes its armies:
    Code:
    local function createDebugSpy(context)
        local player_faction = context.string;
    if context:faction():is_human()==true then
        scripting.game_interface:create_agent(player_faction, "Spy", "rom_lilybaion",X-Koordinate,Y-Koordinate,true)--Schreibweise überprüfen von Lilybaion, Spy, Koordinaten einsetzen
        end --end if
        end --end function
    scripting.AddEventCallBack("FactionTurnStart", createDebugSpy);
    If this works, I intend to set his actionpoints to unlimited, so I have a really universal "tool" for observation of AI behaviour
    PS: please note that I just trew this together during my lunch break without access to my game files. So maybe there are some typos in it, my condern is mainly the general functionality of the script.
    Last edited by Fridericus Secundus; November 20, 2015 at 05:09 AM.

Page 3 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
  •