1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Question about multiple attacks and lua

Discussion in 'Civ5 - Creation & Customization' started by AzraelZephyrian, Apr 24, 2019.

  1. AzraelZephyrian

    AzraelZephyrian Chieftain

    Joined:
    Apr 11, 2019
    Messages:
    72
    Sooo. I've been trying to set up a lua script to give a unit as many attacks as there are adjacent units (for a "war wagon", basically a mobile fort). My code compiles fine. I've tried for loops setting "isoutofattacks" to false for a given number of attacks, setting "blitzcount" to a custom value, and setting "isblitz" to true.

    Nothing works. Do I have to figure out .dll modification if I want to do this? Is there any workaround anyone can think of?

    Here's the current code (wherein I attempted to set the blitzcountt)


    Spoiler :

    Code:
    function CallPolyPttack(iUnit)
        local bCanPoly = iUnit:GetIsCombatUnit()
        local bIsHigh = iUnit:GetIsSelected()
        if bCanPoly == true
        and bIsHigh == true then
            local iExtraAttacks = iUnit:GetNumEnemyUnitsAdjacent()
            if (not iExtraAttacks() == 0) then
                local iBlitzStock = iUnit:GetBlitzCount()
                local iBlitzTot = iBlitzStock() + iExtraAttacks()
                iUnit:SetBlitzCount(iBlitzTot())
                iUnit:SetMoves(iBlitzTot())
            end
        end
    end
    GameEvents.PreGamestart.Add(CallPolyAttack)
    Events.SerialEventHexHighlight.Add(CallPolyAttack)
    
    --Also tried this--
    
    function CallPolyPttack(iUnit)
        local bCanPoly = iUnit:GetIsCombatUnit()
        local bIsHigh = iUnit:GetIsSelected()
        if bCanPoly == true
        and bIsHigh == true then
            local iExtraAttacks = iUnit:GetNumEnemyUnitsAdjacent()
            local iTiles = iUnit:GetMoves()
            local iTotalAttacks = iExtraAttacks() + iTiles()
            if (not iExtraAttacks() == 0) then
                for i=iTotalAttacks(),0,-1
                do
                    iUnit:SetMadeAttack(false)
                    while iUnit:GetMadeAttack() == true
                    do
                        local iTimesink = 1 + 1                   
                    end
                end
            end
        end
    end
    GameEvents.PreGamestart.Add(CallPolyAttack)
    Events.SerialEventHexHighlight.Add(CallPolyAttack)
    
    
     
    Last edited: Apr 25, 2019
  2. LeeS

    LeeS Imperator Supporter

    Joined:
    Jul 23, 2013
    Messages:
    7,176
    Location:
    Illinois, USA
    lua API hooks never send an object variable to a listener. They send ID numbers.

    Events.SerialEventHexHighlight never sends any data regarding any unit to any listener assigned to it: http://modiki.civfanatics.com/index.php?title=Events.SerialEventHexHighlight_(Civ5_API)

    GameEvents.PreGameStart() first is not spelled correctly in your code, and second passes no known argument data whatever: http://modiki.civfanatics.com/index.php?title=GameEvents.PreGameStart_(Civ5_API) No listener assigned to it can therefore attempt to use an argument such as you are attempting. Further, anything that is "PreGame" in any way is pretty much useless to mod-makers who are not specifically attempting to re-engineer the manner in which game loading and the like are conducted.

    Thee are no reliable pre-combat lua hook events. Serial Events that may seem like they ought to work for such do not actually do so primarily because they do not fire if the human player cannot see the action, or if quick combat is turned on, etc.


    Unit:SetBlitzCount() does not exist as part of the BNW Firaxis-Made API. Sure you did not get that method off the CP forum ? Or from one of William Howard's mods ? There is a Unit:GetBlitzCount() but not a "Set" method.
     
    Last edited: Apr 25, 2019
  3. AzraelZephyrian

    AzraelZephyrian Chieftain

    Joined:
    Apr 11, 2019
    Messages:
    72
    Welp, I messed up quite a bit. I'm very new to programming in general...and lua mods with respect to civ 5. Thanks for the pointers.
     

Share This Page