Results 1 to 10 of 10

Thread: Lua code snippets in etwng repository

  1. #1
    Artifex
    Patrician

    Join Date
    Oct 2008
    Location
    London, UK
    Posts
    1,308

    Default Lua code snippets in etwng repository

    I put snippets of commonly used lua code to etwng repository. You can grab them here.
    Copy-pasting them will speed up scripting.lua customization somewhat.

  2. #2

    Default Re: Lua code snippets in etwng repository

    Is there a resource for scripting basics for ETW?

    I've noticed now a few examples of lua usage, in the scripting.lua and also loading other lua files.

    But I'm puzzled as to how and where these programmers / modders found references to game functions.

    For instance, you use 'force_diplomacy' in your snippet. Is this from seeing it in an existing scripting.lua, or do you have some reference for game functions?

    Thanks.
    Last edited by jtravers88; March 02, 2011 at 10:31 AM.

  3. #3
    Artifex
    Patrician

    Join Date
    Oct 2008
    Location
    London, UK
    Posts
    1,308

    Default Re: Lua code snippets in etwng repository

    Quote Originally Posted by jtravers88 View Post
    Is there a resource for scripting basics for ETW?

    I've noticed now a few examples of lua usage, in the scripting.lua and also loading other lua files.

    But I'm puzzled as to how and where these programmers / modders found references to game functions.

    For instance, you use 'force_diplomacy' in your snippet. Is this from seeing it in an existing scripting.lua, or do you have some reference for game functions?

    Thanks.
    There's no official reference.

    There are a few tutorial and references threads in forums.

    There are also examples of .lua in ETW and in various mods (especially APE:TI).

    There is also .lua which came from decompiling .luac files.

    And lua has debug features that allow listing of all commands - the only thing left then is figuring out what they mean (and how to make sure they don't crash).

    Anything in particular you'd like to see?

  4. #4

    Default Re: Lua code snippets in etwng repository

    Quote Originally Posted by jtravers88 View Post
    Is there a resource for scripting basics for ETW?

    I've noticed now a few examples of lua usage, in the scripting.lua and also loading other lua files.

    But I'm puzzled as to how and where these programmers / modders found references to game functions.

    For instance, you use 'force_diplomacy' in your snippet. Is this from seeing it in an existing scripting.lua, or do you have some reference for game functions?

    Thanks.
    Look at my sig. There's a link for the NTW script-o-rama, but there is little there that isn't in ETW, as well as a bit of an introduction to Lua. There's also other links to Lua related stuff in my links, including a list just like taw mentioned in his post
    My Tools, Tutorials and Resources

    Was running out of space, so see the full list here!

    Consider the postage stamp: its usefulness consists in the ability to stick to one thing till it gets there.- Josh Billings
    The creatures outside looked from pig to man, and from man to pig, and from pig to man again; but already it was impossible to say which was which.- George Orwell

  5. #5

    Default Re: Lua code snippets in etwng repository

    Hello!
    Excuse me if I am not on the topic. I do not know whom to address. (I know English badly I asked my friends to write the message).

    The questions are
    1. Have anybody decompiled the files luac games ETW? Ie luac ->lua.
    I am
    especially interested in the files technology.luac and so on. If somebody have done them, download them on the site, please
    or inform me about the files.
    2. There are good lua files in mod APE_TI. How to make them work in Vanilla ETW without mod APE_TI?
    Thanks a lot.
    Last edited by Vyacheslav; March 28, 2011 at 12:05 PM.

  6. #6
    Artifex
    Patrician

    Join Date
    Oct 2008
    Location
    London, UK
    Posts
    1,308

    Default Re: Lua code snippets in etwng repository

    Quote Originally Posted by Vyacheslav View Post
    Hello!
    Excuse me if I am not on the topic. I do not know whom to address. (I know English badly I asked my friends to write the message).

    The questions are
    1. Have anybody decompiled the files luac games ETW? Ie I am especially interested in the files technology.luac and so on. If somebody have done them, download them on the site, please or inform me about the files.
    Yes, decompiler can be build using scripts from etwng repository.
    I don't know if anyone managed to build decompiler on Windows, it works on Linux and OSX fine.

    Here's technology.lua from ETW:

    Code:
    -- Decompiled using luadec 2.0 UNICODE by sztupy (http://winmo.sztupy.hu)
    -- Command line was: samples_etw/campaign ui/technology_scripts/technology.luac 
    
    local utils = require("Utilities")
    local core = (require("CoreUtils"))
    local CampaignUI, Localisation = nil, nil
    local root = UIComponent(Component.Root())
    local stealing = core.NamespaceFile("technology_stealing")
    local researching = (core.NamespaceFile("technology_researching"))
    local techmode = nil
    ZoomToEntity = function()
      techmode.ZoomToEntity()
    end
    
    ResearchingMode = function()
      return techmode == researching
    end
    
    Refresh = function(l_3_0, l_3_1)
      out.shane("* technology.lua - Refresh: residence = " .. tostring(l_3_0) .. ", character = " .. tostring(l_3_1))
      if techmode == stealing then
        local details = CampaignUI.TechnologyStealingDetails(l_3_1, l_3_0)
        if details ~= nil then
          Initialise(details, CampaignUI, Localisation, true)
        else
          panel_manager.ClosePanel("technology")
        end
      else
        local details = CampaignUI.TechnologyResearchingDetails(l_3_1, l_3_0)
        if details ~= nil then
          Initialise(details, CampaignUI, Localisation, false)
        else
          panel_manager.ClosePanel("technology")
        end
      end
    end
    
    Reinitialise = function(l_4_0, l_4_1)                                                                                                                       
      out.shane("* Reinitialising technology *")                                                                                                                
      Initialise(l_4_0, CampaignUI, Localisation, l_4_1)                                                                                                        
    end                                                                                                                                                         
                                                                                                                                                                
    Initialise = function(l_5_0, l_5_1, l_5_2, l_5_3)                                                                                                           
      out.shane("* Initialising technology *")                                                                                                                  
      CampaignUI = l_5_1                                                                                                                                        
      upvalue_512 = l_5_2                                                                                                                                       
      if l_5_3 == true then                                                                                                                                     
        upvalue_1024 = stealing                                                                                                                                 
      else                                                                                                                                                      
        upvalue_1024 = researching                                                                                                                              
      end                                                                                                                                                       
      techmode.Initialise(l_5_0, Address, Component.Root(), CampaignUI, Localisation)                                                                           
    end                                                                                                                                                         
                                                                                                                                                                
    OnEntityLClickUp = function(l_6_0)                                                                                                                          
      techmode.SelectEntity(l_6_0)                                                                                                                              
    end                                                                                                                                                         
                                                                                                                                                                
    OnEntityRClickUp = function(l_7_0)                                                                                                                          
      techmode.ShowEntityDetails(l_7_0)                                                                                                                         
    end                                                                                                                                                         
                                                                                                                                                                
    TechLeftClicked = function(l_8_0)                                                                                                                           
      techmode.TechLeftClicked(l_8_0)                                                                                                                           
    end                                                                                                                                                         
                                                                                                                                                                
    TechRightClicked = function(l_9_0)                                                                                                                          
      techmode.TechRightClicked(l_9_0)                                                                                                                          
    end                                                                                                                                                         
                                                                                                                                                                
    TurnsToResearchOrChanceToSteal = function(l_10_0)                                                                                                           
      return techmode.TurnsToResearchOrChanceToSteal(l_10_0)                                                                                                    
    end                                                                                                                                                         
                                                                                                                                                                
    SelectedEntityProgessingTech = function(l_11_0)                                                                                                             
      return techmode.SelectedEntityProgessingTech(Key)                                                                                                         
    end                                                                                                                                                         
                                                                                                                                                                
    HasFacilities = function()                                                                                                                                  
      return techmode.HasFacilities()                                                                                                                           
    end                                                                                                                                                         
                                                                                                                                                                
    CreateTechEntry = function(l_13_0, l_13_1, l_13_2)                                                                                                          
      return Component.CreateComponentFromTemplate("tech_entry", l_13_0, l_13_1, 0, 0, l_13_2)                                                                  
    end                                                                                                                                                         
                                                                                                                                                                
    SelectTab = function(l_14_0)                                                                                                                                
      out.shane("SelectTab called with " .. tostring(l_14_0))                                                                                                   
      techmode.SelectTab(l_14_0)                                                                                                                                
    end                                                                                                                                                         
                                                                                                                                                                
    TechAvailable = function(l_15_0)                                                                                                                            
      return techmode.TechAvailable(l_15_0)                                                                                                                     
    end                                                                                                                                                         
                                                                                                                                                                
    TechCompleted = function(l_16_0)
      return techmode.TechCompleted(l_16_0)
    end
    
    TechInProgress = function(l_17_0)
      return techmode.TechInProgress(l_17_0)
    end
    If you have troubles setting up decompiler yourself,
    PM me your email address and I'll send you an archive of all decoded lua files.

    Quote Originally Posted by Vyacheslav View Post
    2. There are good lua files in mod APE_TI. How to make them work in Vanilla ETW without mod APE_TI?
    Thanks a lot.
    It's a lot of effort, and you need a fairly good understanding of lua if you hope to succeed.

  7. #7

    Default Re: Lua code snippets in etwng repository

    Quote Originally Posted by taw View Post
    Yes, decompiler can be build using scripts from etwng repository.
    I don't know if anyone managed to build decompiler on Windows, it works on Linux and OSX fine.

    Here's technology.lua from ETW:

    Code:
    -- Decompiled using luadec 2.0 UNICODE by sztupy (http://winmo.sztupy.hu)
    -- Command line was: samples_etw/campaign ui/technology_scripts/technology.luac 
    
    local utils = require("Utilities")
    local core = (require("CoreUtils"))
    local CampaignUI, Localisation = nil, nil
    local root = UIComponent(Component.Root())
    local stealing = core.NamespaceFile("technology_stealing")
    local researching = (core.NamespaceFile("technology_researching"))
    local techmode = nil
    ZoomToEntity = function()
      techmode.ZoomToEntity()
    end
    
    ResearchingMode = function()
      return techmode == researching
    end
    
    Refresh = function(l_3_0, l_3_1)
      out.shane("* technology.lua - Refresh: residence = " .. tostring(l_3_0) .. ", character = " .. tostring(l_3_1))
      if techmode == stealing then
        local details = CampaignUI.TechnologyStealingDetails(l_3_1, l_3_0)
        if details ~= nil then
          Initialise(details, CampaignUI, Localisation, true)
        else
          panel_manager.ClosePanel("technology")
        end
      else
        local details = CampaignUI.TechnologyResearchingDetails(l_3_1, l_3_0)
        if details ~= nil then
          Initialise(details, CampaignUI, Localisation, false)
        else
          panel_manager.ClosePanel("technology")
        end
      end
    end
    
    Reinitialise = function(l_4_0, l_4_1)                                                                                                                       
      out.shane("* Reinitialising technology *")                                                                                                                
      Initialise(l_4_0, CampaignUI, Localisation, l_4_1)                                                                                                        
    end                                                                                                                                                         
                                                                                                                                                                
    Initialise = function(l_5_0, l_5_1, l_5_2, l_5_3)                                                                                                           
      out.shane("* Initialising technology *")                                                                                                                  
      CampaignUI = l_5_1                                                                                                                                        
      upvalue_512 = l_5_2                                                                                                                                       
      if l_5_3 == true then                                                                                                                                     
        upvalue_1024 = stealing                                                                                                                                 
      else                                                                                                                                                      
        upvalue_1024 = researching                                                                                                                              
      end                                                                                                                                                       
      techmode.Initialise(l_5_0, Address, Component.Root(), CampaignUI, Localisation)                                                                           
    end                                                                                                                                                         
                                                                                                                                                                
    OnEntityLClickUp = function(l_6_0)                                                                                                                          
      techmode.SelectEntity(l_6_0)                                                                                                                              
    end                                                                                                                                                         
                                                                                                                                                                
    OnEntityRClickUp = function(l_7_0)                                                                                                                          
      techmode.ShowEntityDetails(l_7_0)                                                                                                                         
    end                                                                                                                                                         
                                                                                                                                                                
    TechLeftClicked = function(l_8_0)                                                                                                                           
      techmode.TechLeftClicked(l_8_0)                                                                                                                           
    end                                                                                                                                                         
                                                                                                                                                                
    TechRightClicked = function(l_9_0)                                                                                                                          
      techmode.TechRightClicked(l_9_0)                                                                                                                          
    end                                                                                                                                                         
                                                                                                                                                                
    TurnsToResearchOrChanceToSteal = function(l_10_0)                                                                                                           
      return techmode.TurnsToResearchOrChanceToSteal(l_10_0)                                                                                                    
    end                                                                                                                                                         
                                                                                                                                                                
    SelectedEntityProgessingTech = function(l_11_0)                                                                                                             
      return techmode.SelectedEntityProgessingTech(Key)                                                                                                         
    end                                                                                                                                                         
                                                                                                                                                                
    HasFacilities = function()                                                                                                                                  
      return techmode.HasFacilities()                                                                                                                           
    end                                                                                                                                                         
                                                                                                                                                                
    CreateTechEntry = function(l_13_0, l_13_1, l_13_2)                                                                                                          
      return Component.CreateComponentFromTemplate("tech_entry", l_13_0, l_13_1, 0, 0, l_13_2)                                                                  
    end                                                                                                                                                         
                                                                                                                                                                
    SelectTab = function(l_14_0)                                                                                                                                
      out.shane("SelectTab called with " .. tostring(l_14_0))                                                                                                   
      techmode.SelectTab(l_14_0)                                                                                                                                
    end                                                                                                                                                         
                                                                                                                                                                
    TechAvailable = function(l_15_0)                                                                                                                            
      return techmode.TechAvailable(l_15_0)                                                                                                                     
    end                                                                                                                                                         
                                                                                                                                                                
    TechCompleted = function(l_16_0)
      return techmode.TechCompleted(l_16_0)
    end
    
    TechInProgress = function(l_17_0)
      return techmode.TechInProgress(l_17_0)
    end
    If you have troubles setting up decompiler yourself,
    PM me your email address and I'll send you an archive of all decoded lua files.



    It's a lot of effort, and you need a fairly good understanding of lua if you hope to succeed.
    That one won't work, I can see at a glance it's replaced local variables with upvalues. There's only two, so it should be easy to fix.
    My Tools, Tutorials and Resources

    Was running out of space, so see the full list here!

    Consider the postage stamp: its usefulness consists in the ability to stick to one thing till it gets there.- Josh Billings
    The creatures outside looked from pig to man, and from man to pig, and from pig to man again; but already it was impossible to say which was which.- George Orwell

  8. #8

    Default Re: Lua code snippets in etwng repository

    Taw
    It is so kind of you. Thanks a lot!!!

  9. #9
    Artifex
    Patrician

    Join Date
    Oct 2008
    Location
    London, UK
    Posts
    1,308

    Default Re: Lua code snippets in etwng repository

    Quote Originally Posted by Vyacheslav View Post
    Taw
    It is sokind of you. Thanks a lot!!!
    I sent you the files.

  10. #10

    Default Re: Lua code snippets in etwng repository

    Taw
    Archive received. Thank you very much. I'm happy!
    You're a good man and a great master.
    T.C.
    Thank you!
    Last edited by Vyacheslav; March 28, 2011 at 07:07 PM.

Posting Permissions

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