I am wondering how to get the hero in an item script.
I want to do this:
--slow the hero down
function item:on_map_changed(map)
hero:set_walking_speed(30)
end
I tried:
local item = ...
local game = item:get_game()
local hero = game:get_hero()
and
local item = ...
local game = item:get_game()
local map = item:get_map()
local hero = map:get_entity("hero")
and
local item = ...
local game = item:get_game()
local map = item:get_map()
local hero = map:get_hero()
One solution is using "self". I did this when making boots that speed up walking.
function item:on_obtaining()
self:get_map():get_entity("hero"):set_walking_speed(120)
end
if game:get_value("sola_house_f1_heart_gem_finish") then
function item:on_map_changed(map)
self:get_map():get_entity("hero"):set_walking_speed(120)
end
end
--slow the hero down
function item:on_map_changed(map)
local hero = map:get_hero()
hero:set_walking_speed(30)
end
@Christopho @Zefk
Both solutions work! Thank you!