[SOLVED] Implementing Attributes library

edited December 2015 in Questions

Hello everyone. I have a problem with the mod I'm trying to make. I'm trying to change attributes scaling using MNoya's attributes library, but when I start the game I get an error regarding 'OnHeroInGame(hero)' function. Here's the code of OnHeroInGame( hero ) function:

function ZombieArena:OnHeroInGame( hero )
    local hero_name = hero:GetUnitName()
    print("[ZOMBIEARENA] OnHeroInGame "..hero_name)


Here's the console error showing up during loading:

Script Runtime Error: scripts/vscripts/ZombieArena.lua:129: attempt to index local 'hero' (a nil value)
 stack traceback:
    scripts/vscripts/ZombieArena.lua:129: in function 'OnHeroInGame'
    ...addons\zombie_arena\scripts\vscripts\addon_game_mode.lua:28: in function <...addons\zombie_arena\scripts\vscripts\addon_game_mode.lua:25>

Have I to define 'hero' somewhere? Whenever I try to define it, it gives other errors of 'nil value'. Thanks in advance :D.


  • Posts: 1,670

    'hero' gets passed to the OnHeroInGame through the OnNPCSpawned event hook. You are probablye calling OnHeroInGame incorrectly from there. Show more code, pastebin your whole ZombieArena lua

    The concept of Modding Community doesn't go well together with Competitive Business
    My Project Page || My GitHub Profile ||

  • Yeah just noticed it. Thank you! I now managed to run "OnNPCSpawned" function, but still there are no changes in attributes scaling. Console is giving error about "attempting to index field 'applier' (a nil value)".

     scripts/vscripts/libraries/attributes.lua:61: attempt to index field 'applier' (a nil value)
     stack traceback:
        scripts/vscripts/libraries/timers.lua:135: in function '__index'
        scripts/vscripts/libraries/attributes.lua:61: in function <scripts/vscripts/libraries/attributes.lua:33>
        [C]: in function 'xpcall'
        scripts/vscripts/libraries/timers.lua:134: in function <scripts/vscripts/libraries/timers.lua:95>

    Here's ZombieArena lua: http://pastebin.com/7uhz0xgW

    And Attributes lua library: http://pastebin.com/JGyaQEJD

    Thank you again for helping me so fast and for your work!!!!

  • edited December 2015 Posts: 1,670

    You probably haven't added the "item_stat_modifier" or some of the other dependancies required for the lib to work:

    I've edited your thread title to make it more descriptive of the problem now

    Note: If you need less stats than dota values, you'll need to edit the modifiers a bit.

    The concept of Modding Community doesn't go well together with Competitive Business
    My Project Page || My GitHub Profile ||

  • edited December 2015 Posts: 45

    As you said, I forgot "item_stat_modifier" in my files. Other dependancies were already added. However it still gives me the same "attempt to index field 'applier'" error, in the same line of 'attributes lua'. As I'm new to modding (and programming too), I don't really know what do you mean with 'merge files'. I have put the 'require("")' codes in "addon_game_mode.lua": http://pastebin.com/fgi3NRnG Forgetting something?

    Thank you again for your help!!!

    OT: Is it normal that with this function the console tells me that 'FindByName' needs 3 arguments instead of 2? In Developer's API there are just 2 (handle FindByName(handle lastEnt, string searchString)

    function ZombieArena:OnPlayerPickHero(keys)
        print ('[ZOMBIEARENA] OnPlayerPickHero')
        local hero = EntIndexToHScript(keys.heroindex)
        local player = EntIndexToHScript(keys.player)
        local playerID = hero:GetPlayerID()
        local GoldenIdol = Entities.FindByName(nil, "building_gold_idol")
        GoldenIdol:SetControllableByPlayer(playerID, false)
  • For the latter question you are doing Entities.FindByName when you should be doing Entities:FindByName


  • Posts: 1,670

    By merge files I mean, drop the txt I gave you inside an items/ folder and use ModKit combine KV to make sure the item key values are part of npc_items_custom.txt. The .txt by itself doesnt do anything, it's just our way of organizing the files into different entries, and combine them with a tool.

    After the item is part of npc_items_custom.txt, the CreateItem function will actually work.

    The concept of Modding Community doesn't go well together with Competitive Business
    My Project Page || My GitHub Profile ||

  • Thanks rap_game_anti_mage for the hint, now I understand which 3rd argument the console was referring to. Thank you Noya, now it all works fine!!! I'll mark this as solved.