Page 4 of 5 FirstFirst 12345 LastLast
Results 61 to 80 of 92

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

Hybrid View

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

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

    It is a guessing game. With the parameters you use the game will likely crash. I couldn't find to right parameters for the function yet.

  2. #2

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

    create_agent("faction_key", "agent_key", x_position, y_position, "id", true)

    First parameter is the faction key, second the agent key, third and fourth the X/Y coordinates, fourth is a string identifier likely useless to you, last parameter sets whether the command happens immediately (false) or at the next best moment (true, should always be true for modders).
    The formal disclaimer: Any views or opinions expressed here are those of the poster and do not necessarily represent the views or opinions of The Creative Assembly or SEGA.

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

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

    Thank you for dropping by.

    So the region was not needed, actually haven't tried it without the region name...

  4. #4

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

    Thank you Mitch. I tried this in order to get a spy in sicily for debugging reasons (see what Syracuse AI will do an which units they recruit):
    Code:
    local function CreateDebugSpy(context)
    local current_faction = context.string;
        if context:faction():is_human() == true 
        and conditions.TurnNumber(context) == 2 then
        scripting.game_interface:create_agent(current_faction,"dignitary",295,574,"001S",true);
        end
    end
    scripting.AddEventCallBack("OnFactionTurnStart", CreateDebugSpy);
    However, it doesn't work. Note that I used a dignitary instead of a spy to exclude agent limit as a possible bug.

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

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

    conditions.TurnNumber(context) ? Don't think this works.

  6. #6

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

    Well, I took it from the CiG scripts, where something similar is actually working:
    Code:
    if conditions.TurnNumber(context) == 1 and not CampaignUI.IsMultiplayer() and conditions.FactionIsLocal(context) then

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

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

    I hope people are still around who are able to help. I have pored over and over this code. I am not sure the code is the problem so I am going to attach the whole mod in case I have missed something in the db tables.

    This is a really simple supply script. But basically nothing happens. Originally I had the code as a separate file but in desperation I have now tried adding it to the end of the campaign script

    Here is the code:
    Code:
    -- KANKRUSHA'S SIMPLIFIED SUPPLY SCRIPT
    
    
    -- There are 4 levels of supply from very good which grants benefits to very poor which inflicts penalties
    -- Moving will lower supply.
    -- Keeping stationary while in your own region will improve supply
    
    
    -- Make the script a module one
    -- module(..., package.seeall);                     -- commented out now
    
    
    
    
    -- load libraries
    scripting = require "lua_scripts.EpisodicScripting"
    events = require "data.lua_scripts.events"
    require "data.lua_scripts.lib_export_triggers"
    
    
    
    
    local function kk_supply_script(context)
    
    
        if not char_is_general_with_army(context:character()) then
            return false
        end
    
    
        -- Remove all previous effects
        scripting.game_interface:remove_effect_bundle_from_characters_force("rom_supply_1", context:character():cqi())
        scripting.game_interface:remove_effect_bundle_from_characters_force("rom_supply_2", context:character():cqi())
        scripting.game_interface:remove_effect_bundle_from_characters_force("rom_supply_3", ccontext:character():cqi())
        scripting.game_interface:remove_effect_bundle_from_characters_force("rom_supply_4", context:character():cqi())
    
    
    
    
        -- Siege has its own system so don't want that here
        if character:has_garrison_residence() and character:garrison_residence():is_under_siege() then
            return
        end
    
    
        -- Increase supply if stationary
        if context:character():action_points_remaining_percent() >= 90 then
                if context:character():turns_in_own_regions() >= 2 then
                    scripting.game_interface:apply_effect_bundle_to_characters_force("rom_supply_4", context:character():cqi(),-1)
                elseif context:character():turns_in_own_regions() >= 1 then
                    scripting.game_interface:apply_effect_bundle_to_characters_force("rom_supply_3", context:character():cqi(),-1)
                elseif  context:character():turns_in_enemy_regions() >= 5 then
    
    
                    -- Supply always poor if in enemy territory too long
                    scripting.game_interface:apply_effect_bundle_to_characters_force("rom_supply_1", context:character():cqi(),-1)
                else scripting.game_interface:apply_effect_bundle_to_characters_force("rom_supply_2", context:character():cqi(),-1)
                end
        end
    
    
        -- Decrease supply if moved this turn
        if context:character():action_points_remaining_percent() < 90 then
            if context:character():turns_in_enemy_regions() >= 2 then
                scripting.game_interface:apply_effect_bundle_to_characters_force("rom_supply_1", context:character():cqi(),-1)
            elseif  context:character():turns_in_enemy_regions() >= 1 then
                scripting.game_interface:apply_effect_bundle_to_characters_force("rom_supply_2", context:character():cqi(),-1)
            else scripting.game_interface:apply_effect_bundle_to_characters_force("rom_supply_3", context:character():cqi(),-1)
            end
        end
    
    
        return true
    
    
    end
    
    
    scripting.AddEventCallBack("CharacterTurnEnd",  kk_supply_script)
    Attached Files Attached Files
    Last edited by Col.KanKrusha; April 26, 2016 at 03:07 PM.
    ~ Too soon old, too late smart ~

  8. #8
    Foederatus
    Join Date
    Apr 2010
    Location
    Russia, Volgograd
    Posts
    27

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

    EncylopediaEntryRequested, CharacterSelected and others events does not work

  9. #9
    Foederatus
    Join Date
    Apr 2010
    Location
    Russia, Volgograd
    Posts
    27

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

    Hi All!, please help me with this script:

    function OnLEFUI(context)
    if context:faction():name() == "rom_roxolani" and context:faction():is_human() == false then
    scripting.game_interface:create_force("rom_roxolani", "Ste_Royal_Horse_Archers", "rom_scythia_scythia",510,430, "patrol1", true)
    end;
    end;

    scripting.AddEventCallBack("SavingGame", OnLEFUI);

    --more saves - more troops to AI

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

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

    Hi

    In the "context" of saving a game I think you would have to first identify the player

    player_faction = GetPlayerFaction();

    if player_faction ==
    ~ Too soon old, too late smart ~

  11. #11
    Foederatus
    Join Date
    Apr 2010
    Location
    Russia, Volgograd
    Posts
    27

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

    local function OnSavingGame(context)
    scripting.game_interface:create_force("rom_roxolani", "Ste_Royal_Horse_Archers", "rom_scythia_scythia",510,430, "patrol1", true)
    end;

    this code create army ? but then appear window about violation of boarders and UI freeze. How to fix it?

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

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

    Where did you get the co-ordinates? Are they correct?

    also I would Add a check that the faction still exists

    I am worried this is going to run at the end of every turn with autosave
    ~ Too soon old, too late smart ~

  13. #13
    Foederatus
    Join Date
    Apr 2010
    Location
    Russia, Volgograd
    Posts
    27

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

    Ok, I want spawn AI forces with events, but not with "FactionTurnStart". I try "SettlementSelected" but that no work. Coordinates is correct.

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

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

    How about when settlement attackied? If you have Caesar in Gaul DLC there is a function In the campaign script that you could copy to main campaign

    or whenever the human player spawns a new general (oncharactercreated) then you could have AI spawn one to match
    ~ Too soon old, too late smart ~

  15. #15
    Foederatus
    Join Date
    Apr 2010
    Location
    Russia, Volgograd
    Posts
    27

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

    onCharacterCreated work, thanks. How i can get cursor or settlement coordinates?

  16. #16
    Foederatus
    Join Date
    Apr 2010
    Location
    Russia, Volgograd
    Posts
    27

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

    ok, all done

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

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

    Well done. You should feel a sense of achievement, my own script which looks perfect to me is still dead in the water.
    ~ Too soon old, too late smart ~

  18. #18
    Foederatus
    Join Date
    Apr 2010
    Location
    Russia, Volgograd
    Posts
    27

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

    hmmm, someone else working command - create_agent?
    I used this func, but not worked.
    local function OnGenerateSpy(context)
    if not CampaignUI.IsMultiplayer() then
    scripting.game_interface:create_agent("rom_roxolani","spy",750,530,"dbspy",true)
    end
    end

  19. #19
    Foederatus
    Join Date
    Apr 2010
    Location
    Russia, Volgograd
    Posts
    27

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

    and how i can get a settlement name from function context?

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

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

    Have a look at page 1 of this thread

    I think this will work (but haven't looked through code to check)

    if context:region():name()== "rom_rome"
    (from wrath of Sparta script)

    there is is also a region_in_region_list function. Take this. It's dangerous to go alone
    http://pastebin.com/GF4ubMMm
    Last edited by Col.KanKrusha; May 09, 2016 at 02:31 PM.
    ~ Too soon old, too late smart ~

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