[GS] New abilities control via xml / lua

__jack__

Warlord
Joined
Dec 29, 2009
Messages
141
Probably for @LeeS

I created a new ability - a debuff.
I want to control it via lua via the changeabilitycount() so that the debug is applied selectively.

problem: it doesn’t work when I apply the change ability on the custom ability the unit doesn’t receive it (no error in lua). If I put an existing ability like ABILiTY_GREAT_GENERAL_MoVement then the lua control works without any problem.

I tested the xml end by putting the custom ability to class_melee and it worked without any trouble: my warriors were getting it by default.

however I would like this ability to be gained (and removed) at will by lua. Is it a limitation of the custom ability?
 
Lua Code:

Code:
function OnGameTurnStarted(player)
    -- Last Move
    if Last_Data ~= nil then
        local pUnit
        for i, row in pairs(Last_Data) do
            if row.player ~= nil and row.unit ~= nil then
                print("OnGameTurnStarted",row.player,row.unit)
                pUnit = UnitManager.GetUnit(row.player, row.unit)
                if pUnit ~= nil then
                    print("OnGameTurnStarted - pUnit",pUnit)
                    local unitAbilities = pUnit:GetAbility()
                    if unitAbilities ~= nil then
                        print("OnGameTurnStarted - unitAbilities",unitAbilities)
                        print("unitAbilities:GetAbilityCount(ABILITY_LAST_MOVED)",unitAbilities:GetAbilityCount("ABILITY_LAST_MOVED"))
                        if (unitAbilities:GetAbilityCount("ABILITY_LAST_MOVED")<1) then
                            unitAbilities:ChangeAbilityCount("ABILITY_GREAT_GENERAL_STRENGTH",1)
                            print("OnGameTurnStarted - Applied Debuff",row.player,row.unit,pUnit)
                            print("unitAbilities:GetAbilityCount(ABILITY_LAST_MOVED) Debuff",unitAbilities:GetAbilityCount("ABILITY_LAST_MOVED"))
                            print("unitAbilities:GetAbilityCount(ABILITY_GREAT_GENERAL_STRENGTH) Debuff",unitAbilities:GetAbilityCount("ABILITY_GREAT_GENERAL_STRENGTH"))
                        end
                    end
                end
            end   
        end
    end
    -- Check

    local pPlayer = Players[0]
    local playerUnits = pPlayer:GetUnits()
    for i, unit in playerUnits:Members() do
        local pUnit = unit
                if pUnit ~= nil then
                    print("OnGameTurnStarted - pUnit",pUnit)
                    local unitAbilities = pUnit:GetAbility()
                    if unitAbilities ~= nil then
                        print("unitAbilities:GetAbilityCount(ABILITY_LAST_MOVED)",unitAbilities:GetAbilityCount("ABILITY_LAST_MOVED"))
                        print("unitAbilities:GetAbilityCount(ABILITY_GREAT_GENERAL_STRENGTH) Debuff",unitAbilities:GetAbilityCount("ABILITY_GREAT_GENERAL_STRENGTH"))   
                    end
                end
    

    end
 
XML Excerpt:

Code:
<GameInfo>
    <Types>
        <Row Type="ABILITY_LAST_MOVED" Kind="KIND_ABILITY"/>
    </Types>
    <UnitAbilities>
        <Row UnitAbilityType="ABILITY_LAST_MOVED" Name="LOC_ABILITY_LAST_MOVED_NAME" Description="LOC_ABILITY_LAST_MOVED_DESCRIPTION"/>
    </UnitAbilities>
    <!--  -->
    <UnitAbilityModifiers>
        <Row>
            <UnitAbilityType>ABILITY_LAST_MOVED</UnitAbilityType>
            <ModifierId>MOD_LAST_MOVED</ModifierId>
        </Row>
    </UnitAbilityModifiers>
    <Modifiers>
        <Row>
            <ModifierId>MOD_LAST_MOVED</ModifierId>
            <ModifierType>UNIT_STRONG_WHEN_ATTACKING</ModifierType>
        </Row>
    </Modifiers>
    <ModifierArguments>
        <Row>
            <ModifierId>MOD_LAST_MOVED</ModifierId>
            <Name>Amount</Name>
            <Value>-20</Value>
        </Row>
    </ModifierArguments>
    <ModifierStrings>
        <Row ModifierId="MOD_LAST_MOVED" Context="Preview" Text="LOC_MOD_LAST_MOVED_DESCRIPTION"/>
    </ModifierStrings>
</GameInfo>
 
Unfortunately none of it makes any sense.

UNIT_STRONG_WHEN_ATTACKING is a ModifierId taken from file UnitAbilities.xml. It is not a ModifierType as defined within table DynamicModifiers:
Code:
	<UnitAbilityModifiers>
		<Row>
			<UnitAbilityType>ABILITY_BERSERKER_RAGE</UnitAbilityType>
			<ModifierId>UNIT_STRONG_WHEN_ATTACKING</ModifierId>
		</Row>
	</UnitAbilityModifiers>
	<Modifiers>
		<Row>
			<ModifierId>UNIT_STRONG_WHEN_ATTACKING</ModifierId>
			<ModifierType>MODIFIER_UNIT_ADJUST_COMBAT_STRENGTH</ModifierType>
			<SubjectRequirementSetId>UNIT_STRONG_WHEN_ATTACKING_REQUIREMENTS</SubjectRequirementSetId>
		</Row>
	</Modifiers>
	<ModifierArguments>
		<Row>
			<ModifierId>UNIT_STRONG_WHEN_ATTACKING</ModifierId>
			<Name>Amount</Name>
			<Value>10</Value>
		</Row>
	</ModifierArguments>
	<RequirementSets>
		<Row>
			<RequirementSetId>UNIT_STRONG_WHEN_ATTACKING_REQUIREMENTS</RequirementSetId>
			<RequirementSetType>REQUIREMENTSET_TEST_ALL</RequirementSetType>
		</Row>
	</RequirementSets>
	<RequirementSetRequirements>
		<Row>
			<RequirementSetId>UNIT_STRONG_WHEN_ATTACKING_REQUIREMENTS</RequirementSetId>
			<RequirementId>UNIT_STRONG_WHEN_ATTACKING_REQUIREMENT</RequirementId>
		</Row>
	</RequirementSetRequirements>
	<Requirements>
		<Row>
			<RequirementId>UNIT_STRONG_WHEN_ATTACKING_REQUIREMENT</RequirementId>
			<RequirementType>REQUIREMENT_PLAYER_IS_ATTACKING</RequirementType>
		</Row>
	</Requirements>

The lua code also makes no sense, unfortunately.
 
@LeeS
The lua code does work as intented for granting pUnit with ABILITY_GREAT_GENERAL_STRENGTH.
However substituing
unitAbilities:ChangeAbilityCount("ABILITY_GREAT_GENERAL_STRENGTH",1) with
unitAbilities:ChangeAbilityCount("ABILITY_LAST_MOVED",1) doesn't work.

I am much more confident with the lua part than the xml one as I built most of my mods only using lua.

Could you clarify the DynamicModifiers part ? - yes I did pick
UNIT_STRONG_WHEN_ATTACKING from the BERSEKER and I want them to have -20 str debuff when affected by the ability.

I would then used a LuaEvent tied to the timer to trigger the gameplay script from the UI end to remove the debuff after a certian period of time
 
@LeeS Fixed it - just needed to add:
<Row Type="ABILITY_LAST_MOVED" Tag="CLASS_NAVAL_MELEE"/>
and Inactive="true" to the xml :)
 
Column ModifierType in table Modifiers must reference to a valid entry for a "ModifierType" in table "DynamicModifiers". Table "DynamicModifiers" defines via the settings of "CollectionType" and "EffectType" what a given ModifierType does.

Even though the database definition of table "Modifiers" does not directly specify the reference of column "ModifierType" back to table "DynamicModifiers" the game will not actually do anything with a "ModifierType" that is not present in table "DynamicModifiers". You will not get errors in the logs for bad references, you will just get nothing happening.

UNIT_STRONG_WHEN_ATTACKING is not a "ModifierType": it is a specific "ModifierId". A "ModifierId" can be called anything we wish, such as "CHEESEBURGERS" so long as the row that defines the "ModifierId" in table "Modifiers" uses a valid setting for "ModifierType". You do not want to use a "ModifierType" called UNIT_STRONG_WHEN_ATTACKING, you want to use a "ModifierType" of MODIFIER_UNIT_ADJUST_COMBAT_STRENGTH.

Nor do you want to use a "ModifierId" called UNIT_STRONG_WHEN_ATTACKING if you are going to make it have a different value in table ModifierArguments than the one already used for the Berserker ability -- doing so would essentially kill off the Berserker's extra power when attacking.

-------------------

The lua code as quoted is missing at least one "end" command and does not show to what game hook it is tied. Your function also is being passed an argument value which you are then not using.

"Last_Data" appears to be an lua table but nowhere in your quoted code is it defined, so just adds to the confusion of what it is you are asking when asking whether the code ought to do "X".
 
Column ModifierType in table Modifiers must reference to a valid entry for a "ModifierType" in table "DynamicModifiers". Table "DynamicModifiers" defines via the settings of "CollectionType" and "EffectType" what a given ModifierType does.

Even though the database definition of table "Modifiers" does not directly specify the reference of column "ModifierType" back to table "DynamicModifiers" the game will not actually do anything with a "ModifierType" that is not present in table "DynamicModifiers". You will not get errors in the logs for bad references, you will just get nothing happening.

UNIT_STRONG_WHEN_ATTACKING is not a "ModifierType": it is a specific "ModifierId". A "ModifierId" can be called anything we wish, such as "CHEESEBURGERS" so long as the row that defines the "ModifierId" in table "Modifiers" uses a valid setting for "ModifierType". You do not want to use a "ModifierType" called UNIT_STRONG_WHEN_ATTACKING, you want to use a "ModifierType" of MODIFIER_UNIT_ADJUST_COMBAT_STRENGTH.

Nor do you want to use a "ModifierId" called UNIT_STRONG_WHEN_ATTACKING if you are going to make it have a different value in table ModifierArguments than the one already used for the Berserker ability -- doing so would essentially kill off the Berserker's extra power when attacking.

I see your point, I haven t been meddling with XML edits much as most of what I do is in Lua. Not sure why it managed to work somehow i nthe first place

The lua was working fine fro mthe start - the game simply generate no error when requested to assign an impossible promotion
 
Last edited:
Back
Top Bottom