Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Need help creating a macro for a game modder..

2. Help
David Hill
2014-03-09
2014-07-08
  • David Hill
    David Hill
    2014-03-09

    Hi,

      I have been using  NP++ for 3 years now to edit game files for the
    

    Men Of War series of WW2 RTS games....

    I can create simple macros by using the record and playback feature but
    i now need to create more advanced macros..

    From my research the game uses Ostfront scripting language which is
    similar to C++ or Java..

    I would like some help creating a macro that would clear the inventories
    of units from the mission file... instead of having to manually remove
    lines by hand....

    Regards,

              David
    
     
  • Loreia2
    Loreia2
    2014-03-09

    Hi David,

    please share a code sample, and explain which changes you need to make in the code. Regular expressions should be enough to solve this.

    BR,
    Loreia

     
  • David Hill
    David Hill
    2014-03-10

    awesome, thanks.. I don't think message space here will be enough for a full mission script and the syntax is quite specific..... Below is a mediafire link to a sample file..

    http://www.mediafire.com/view/8ttoory16dk18a7/0.mi

    I have found out from one of the developers of the game that it is C language / syntax.

    NOTE: The mission file has a "{" character to denote start of file and a "}" to denote end of file and the structure is important or game will crash....

    I would like to be able to remove the inventory entries using a macro and and a code example is below.

    {Inventory 0x801d
        {box
            {clear}
            {item "valter" filled {cell 0 0}}
            {item "pistol" "ammo" 100 {cell 2 0}}
            {item "tank_cap2_ger" {cell 4 0}{user "head"}}
        }
    }
    

    In the sample file the inventory entries start at line number 4143 and go to line 8123

    These line numbers will change as every mission file is different depending on number of units, inventories and mission size.....

    In order for it work successfully the above 8 lines all need to b removed without affecting the order or syntax of the preceeding or folwwing lines...

    each block of code always starts with { and ends with }

    Regards,

       David Hill ( aka modder for Men of War: Assault Squad 2 ) WW2 RTS game
    
     
  • David Hill
    David Hill
    2014-03-10

    In order for it work successfully all inventory entries need to b removed without affecting the order or syntax of the preceeding or following lines...

     
  • Loreia2
    Loreia2
    2014-03-11

    Hi David,

    start search/replace dialog (CTRL+H):

    Find what: "\s+{Inventory.*?\s+}\s+}" (without quotes)
    Replace with: <nothing>

    Tick Regular expression, tick dot matches newline, tick Match case, tick Wrap around.

    BR,
    Loreia

     
  • Loreia2
    Loreia2
    2014-03-11

    Previous solution presumes that each Inventory starts with:
    "<whitespace>{Inventory", curly brace is glued to word Inventory (which starting with capital I), and ends with two lines that contain just whitespace followed by closing curly brace.

    If your scripts contain more variety, paste those examples here so we could extend this regex.

    BR,
    Loreia

     
  • David Hill
    David Hill
    2014-03-13

    Thanks Loreia, But when i search using the string provided \s+{Inventory.*?\s+}\s+}

    NP++ finds nothing matching.... and I ticked the extra search option boxes as instructed...

     
  • Loreia2
    Loreia2
    2014-03-13

    HI David,

    there should be a backslash in front of every curly brace. Damn SF requires to escape backslashes.

    \s+\{Inventory.*?\s+\}\s+\}
    

    BR,
    Loreia

     
  • David Hill
    David Hill
    2014-03-14

    Thanks Loreia,

    That works great,

    How do i tell NP++ to extend the same selection to ALL entries in the opened file. ( it highlighted the first entry only, i just need it do the same for all )

     
    Last edit: David Hill 2014-03-14
  • Loreia2
    Loreia2
    2014-03-14

    Hi David,

    you don't need to select them all at once, just hit "Replace all" to delete all instances of "Inventory" blocks.

    BR,
    Loreia

     
  • David Hill
    David Hill
    2014-07-07

    Hi Loreia2,

    Thanks again for the macro help previously.....

    I now find i need to remove some soldier health boost entries from the mission file.. Its similar to the inventory cleaner but its syntax is:

    Code Sample:

    {Human "mp/ger/oficer" 0x8061
    {Position 2298.18 468.93}
    {xform zl -41.65}
    {Extender "vitality"
    {Health
    {max 200}
    {current 200}
    }
    }
    {Discovered 0}
    {Player 1}
    {MID 52}
    {NameId 5 115}
    {FsmState "stand"}
    }

    The part that needs to be removed is:

    {Extender "vitality"
    {Health
    {max 200}
    {current 200}
    }
    }

    Kind regards,

             David Hill
    
     
  • Loreia2
    Loreia2
    2014-07-07

    Hi David,

    isn't the same regex good enough?

    \\s+\\{Extender.*?\\s+\\}\\s+\\}
    

    Regards,
    Loreia

     
  • David Hill
    David Hill
    2014-07-07

    For some reason it doesnt work, I had to remove the \ at start for it to work and it only hilighted the {Extender part of the mission file but ignored the rest...

    I suspect when i pasted the sample here it messed up the line spacing / tabs and end of line and these are important....

    I manually spaced the entries below so they are alligned correctly with the previous line

    {Human "mp/ger/rifle" 0x8068
    {Position 1903.12 443.78}
    {xform zl -86.71}
    {Extender "vitality"
    {Health
    {max 200}
    {current 200}
    }
    }
    {Player 1}
    {MID 56}
    {NameId 125 10}
    {LastItem "mauzer"}
    }

    The whole section that starts with {Extender and continues to the } above {player 1} entry needs to be hilighted by the regex

    {Extender "vitality"
    {Health
    {max 200}
    {current 200}
    }
    }

     
  • THEVENOT Guy
    THEVENOT Guy
    2014-07-08

    Hello David,

    Let's try to find out a general syntax of the regex, to cover all your needs !

    The text you would like to delete :

    • begins with a header ( Inventory, Extender,...), in the exact case, immediately preceded with an opened curly brace

    • ends with two consecutive closed curly braces

    Moreover, I suppose that :

    • Every line, in your blocks, may begin with space(s) and/or tabulation(s)

    • The two final closed braces may be preceded with space(s) and/or tabulations(s) and/or EOL(s) character(s)


    If so, just follow the method below :

    • Open the Find / Replace dialog ( CTRL+H )

    • Checked the three options Match case, Wrap around and . matches newline

    • Select the Regular expression search mode

    • Type, in the Find what zone, \h*\{Extender.+?\s\}\s*\}

    • Don't type anything in the Replace with zone

    • Click on the Replace all button

    Et voilà !


    NOTES :

    • The form \h = a single Space ( \x20 ), Tabulation ( \x09 ) or No-Break Space ( \xa0 )

    • The form \s = a single Horizontal Blank ( \h ), New Line ( \x0a ), Carriage Return ( \x0d ), Vertical Tabulation ( \x0b ) or Form Feed ( \x0c )

    • The two curly brace characters must be escaped with an \, as they have special signification, in regexes

    • The star, after the \h or \s forms, means any number of consecutive \h or \s, even 0

    Then, the regex must begin with \h*\{Extender or with \h*\{Inventory

    As the closed curly brace, before the last brace, is, at least, preceded by one EOL, the regex must end with \s\}\s*\}

    And between these two boundaries, we should match the shortest string, so the form .+?

    So the final search regex is \h*\{Extender.+?\s\}\s*\}


    Remark :

    It's important to see the difference between the two simple regexes below :

    a.+b and a.+?b

    Let's consider the subject string aaabbbaaaaabaabbbbaa. Then, if the . matches newline is NOT checked, in the search dialog :

    • The regex a.+b matches the string aaabbbaaaaabaabbbb ( the longest non empty string between a and b )

    • The regex a.+?b matches the string aaab ( the shortest non empty string between a and b )


    Hope that this will help you, somehow :-)

    Best regards,

    guy038

    P.S. :

    You'll find good documentation, about the new Boost C++ Regex library ( similar to the PERL Regular Common Expressions ) used by Notepad++, since the 6.0 version, at the TWO addresses below :

    http://www.boost.org/doc/libs/1_48_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html

    http://www.boost.org/doc/libs/1_48_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html

    • The FIRST link explains the syntax, of regular expressions, in the SEARCH part

    • The SECOND link explains the syntax, of regular expressions, in the REPLACEMENT part

     
    Last edit: THEVENOT Guy 2014-07-08
  • David Hill
    David Hill
    2014-07-08

    Thanks for the help, I managed to get it working with the following..

    \s+{Extender "vitality".*?\s+}\s+}

    Your advice and help is appreciated..... :)