Hey, thanks for taking the time to read my thread and trying to help out.
FYI: I am quite new to Lua and map development (Huge thanks to this incredible guide!).
So I would like to create a simple item system, in which I use code as much as possible, and rely on Object Editor as little as possible.
I was able to figure out how to have only one item created in Object Editor, and then manipulate that item ingame via code (changing name, description, icon, adding/removing abilities etc). That makes things very dynamic and simple.
My issue is with the abilities of the item. To avoid creating an item ability for each stat, I want to create one (or a few if required) item ability and manipulate it ingame via code (same as item logic).
The thing is, it seems like what I do doesn't do anything.
For our example, I created a dummy item (based of "Ring of Protection +2", "rde1"), and a dummy item ability (based of "Item Hero Stat Bonus (+10 Agility)", "AIaz") to have something to work with.
The code:
So what I also tried, is refreshing the ability on the item in a few different ways, but none worked.
What I also tried is; before adding this ability item to the manipulated item, adding the ability to a different dummy item, manipulating the ability stat on that item, and only then adding it to the original manipulated item, but the ability stat still gives +10 instead of +44.
I also tried (after the item ability stat manipulation) to remove the item from the hero and giving it a new one, but that didn't help either.
Not sure what I am doing here wrong, or perhaps it's just buggy, but I would appreciate getting some help on this.
If we can't figure this one, I will have to resort to creating item ability in Object Editor for each stat, which is a big overhead..
The second reason it is important for me, is because I plan to create ability system and dynamically changing the abilities will be amazing, as I don't want to have to create all the abilities and their stats in Object Editor.
One more thing regarding changing abilities dynamically ingame (via code), I would also like to change the ability hotkey (not related to item ability).
I read that people are simply creating the same ability with different hotkey multiple times, and then dynamically ingame (via code) assigning the needed ability. It sounds like it will work fine, but it's also a big overhead. I just couldn't find any documentation on how to change hotkey through code ingame. I even tried to guess native functions (BlzSetAbilityCharacterLevelField, since hotkey is a character field.. But yeah that failed
) based on str/int native functions (e.g BlzSetAbilityIntegerLevelField).
Any help will be much appreciated!
FYI: I am quite new to Lua and map development (Huge thanks to this incredible guide!).
So I would like to create a simple item system, in which I use code as much as possible, and rely on Object Editor as little as possible.
I was able to figure out how to have only one item created in Object Editor, and then manipulate that item ingame via code (changing name, description, icon, adding/removing abilities etc). That makes things very dynamic and simple.
My issue is with the abilities of the item. To avoid creating an item ability for each stat, I want to create one (or a few if required) item ability and manipulate it ingame via code (same as item logic).
The thing is, it seems like what I do doesn't do anything.
For our example, I created a dummy item (based of "Ring of Protection +2", "rde1"), and a dummy item ability (based of "Item Hero Stat Bonus (+10 Agility)", "AIaz") to have something to work with.
The code:
Lua:
function test()
unit = CreateUnit(Player(0), FourCC("Hpal"), -550, -850, 0) -- Hero that will pickup the item that will be manipulated.
local item = CreateItem(FourCC("I000"), -550, -850) -- Item that will be picked up and manipulated.
end
function triggerItem()
local trig = CreateTrigger()
TriggerRegisterAnyUnitEventBJ(trig, EVENT_PLAYER_UNIT_PICKUP_ITEM) -- Trigger that will fire when the hero picks up the item.
TriggerAddAction(trig, function ()
itemManipulation(GetManipulatedItem()) -- Function that will run to manipulate the item after it was picked. FYI: manipulating some of the item fields seems to only work if the item is inside a hero inventory, this is why I am working this way.
end)
end
function itemManipulation(item)
BlzSetItemName(item, "new name") -- Works
BlzSetItemDescription(item, "new description") -- Works
BlzSetItemExtendedTooltip(item, "new extended tooltip") -- Works
BlzItemRemoveAbility(item, FourCC("AId2")) -- Works. Removing item ability (+2 armor).
BlzItemAddAbility(item, FourCC("AIt6")) -- Works. Adding item ability (+6 damage bonus).
BlzSetItemIconPath(item, "ReplaceableTextures\\CommandButtons\\BTNLionHorn.blp") -- Works.
BlzItemAddAbility(item, FourCC("A000")) -- Works. Adding item ability (+10 agility).
local itemAbility = BlzGetItemAbility(item, FourCC("A000")) -- Seems to work. This will be used for the next function, so it's required to get it.
BlzSetAbilityIntegerLevelField(itemAbility, ABILITY_ILF_AGILITY_BONUS, 0, 44) -- Doesn't seems to work or do anything. Trying to change the new dummy stat ability ("A000") from 10 agility to 44 agility.
end
OnInit.final(function()
test()
triggerItem()
end)
So what I also tried, is refreshing the ability on the item in a few different ways, but none worked.
Lua:
-- After manipulating the ability (BlzSetAbilityIntegerLevelField line).
BlzItemRemoveAbility(item, FourCC("A000"))
BlzItemAddAbility(item, FourCC("A000"))
-- The ability still gives +10 agility. nothing changed.
What I also tried is; before adding this ability item to the manipulated item, adding the ability to a different dummy item, manipulating the ability stat on that item, and only then adding it to the original manipulated item, but the ability stat still gives +10 instead of +44.
I also tried (after the item ability stat manipulation) to remove the item from the hero and giving it a new one, but that didn't help either.
Not sure what I am doing here wrong, or perhaps it's just buggy, but I would appreciate getting some help on this.
If we can't figure this one, I will have to resort to creating item ability in Object Editor for each stat, which is a big overhead..
The second reason it is important for me, is because I plan to create ability system and dynamically changing the abilities will be amazing, as I don't want to have to create all the abilities and their stats in Object Editor.
One more thing regarding changing abilities dynamically ingame (via code), I would also like to change the ability hotkey (not related to item ability).
I read that people are simply creating the same ability with different hotkey multiple times, and then dynamically ingame (via code) assigning the needed ability. It sounds like it will work fine, but it's also a big overhead. I just couldn't find any documentation on how to change hotkey through code ingame. I even tried to guess native functions (BlzSetAbilityCharacterLevelField, since hotkey is a character field.. But yeah that failed
Any help will be much appreciated!