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

Help fixing this LUA script please?

Discussion in 'Civ5 - Creation & Customization' started by mattpilot, Jan 5, 2012.

  1. mattpilot

    mattpilot Warlord

    Joined:
    Jan 29, 2004
    Messages:
    184
    I tried bumping the old thread ( http://forums.civfanatics.com/showthread.php?t=415499 ), but no luck ;)


    Mylon made an awesome "naval counterattack" mod that worked great many moons ago before i took a break. Not working anymore now. Perhaps a patch changed something? Mylon is awol so i beg thee all for some help :)


    The script is relatively short - perhaps someone can figure out whats wrong with it?


    Spoiler :
    Code:
    -- Lua Script1
    -- Author: Jeff
    -- DateCreated: 16-Mar-11 13:56:17
    --------------------------------------------------------------
    
    print("Naval Counterattack Loaded")
    
    function NavalCounterAttack(iAttackingPlayer, iAttackingUnit, iAttackingUnitDamage, iAttackingUnitFinalDamage, iAttackingUnitMaxHP, iDefendingPlayer, iDefendingUnit, iDefendingUnitDamage, iDefendingUnitFinalDamage, iDefendingUnitMaxHP)
    
    	-- First, let's make sure we're looking at a naval vs naval engagement
    	if iAttackingUnit > 0 and iDefendingUnit > 0 then
    	
    		local AttackingUnit = Players[iAttackingPlayer]:GetUnitByID( iAttackingUnit )
    		local DefendingUnit = Players[iDefendingPlayer]:GetUnitByID( iDefendingUnit )
    
    		if (AttackingUnit:GetDomainType() == DomainTypes.DOMAIN_SEA and DefendingUnit:GetDomainType() == DomainTypes.DOMAIN_SEA) then
    			if (AttackingUnit:GetBaseRangedCombatStrength() > 0 and DefendingUnit:GetBaseRangedCombatStrength() > 0) then
    			
    				--We're in business.  Let's launch a counter-attack.
    				-- Initialize the attack-tracking if this is the first attack of the turn.
    				--if HasAttackedThisTurn == nil then
    					HasAttackedThisTurn = {}
    				--end
    
    				--On an initial attack, neither ship will have the flag, so let's flag the attacker.
    				if HasAttackedThisTurn[DefendingUnit] ~= true and HasAttackedThisTurn[AttackingUnit] ~= true then
    					HasAttackedThisTurn[AttackingUnit] = true
    				end
    
    				--If the defending unit has the flag, then this will prevent a counter-counter attack.
    				if HasAttackedThisTurn[DefendingUnit] ~= true then
    					--print("Qualifies for a counterattack.")
    					DefendingUnit:RangeStrike( AttackingUnit:GetX(), AttackingUnit:GetY() )
    					--Now that the attack has been made, let's reset the defender's attack flag so that it may defend from another attack.
    					DefendingUnit:SetMadeAttack(false)
    					-- By this point, the attacker will already have been checked to make a counter-counter attack, so let's delete our table.
    					HasAttackedThisTurn = nil
    				else
    					--print("This unit is flagged as having attacked already, unable to counter-attack.")
    				end
    			
    			end
    		end
    	end
    end
    
    --function ClearCombatMemory()
    	--HasAttackedThisTurn = nil
    --end
    
    Events.EndCombatSim.Add( NavalCounterAttack )
    --Events.PlayerDoTurn.Add( ClearCombatMemory )



    Thanks
     

Share This Page