Hey, I created a custom grass entity in 1.5.0. Everything worked fine until I downloaded 1.5.3, and now there'es a problem. The code creates grass beneath the hero that normally disappears when the hero leaves the grass or cuts the grass down, but in 1.5.3 the grass doesn't disappear anymore.
This is the code:
local entity = ...
local game = entity:get_game()
local map = entity:get_map()
local hero = map:get_hero()
local grass = false
local function resetherospeed()
local hero = map:get_hero()
hero:set_walking_speed(88)
end
local function on_collision(torch, other, torch_sprite, other_sprite)
if other:get_type() == "custom_entity" then
local other_model = other:get_model()
if other_model == "fire" or other_model == "bluefire" then
local x, y, layer = entity:get_position()
map:create_pickable({layer = layer, x=x, y=y, treasure_name="random"})
if map:has_entity("grassprite") then
map:get_entity("grassprite"):remove()
end
map:create_custom_entity({direction=0,
layer=layer,x=x,y=y, width = 40, height = 56, model="ground_effects/falling_leaves", name = "leaves"})
entity:remove()
sol.timer.start(350, function()
local x,y, layer = entity:get_position()
if other_model == "fire" then
map:create_custom_entity({direction=0,
layer=layer,x=x,y=y + 16, width = 16, height = 16, model="fire"})
map:create_custom_entity({direction=0,
layer=layer,x=x,y=y - 16, width = 16, height = 16, model="fire"})
map:create_custom_entity({direction=0,
layer=layer,x=x + 16,y=y, width = 16, height = 16, model="fire"})
map:create_custom_entity({direction=0,
layer=layer,x=x - 16,y=y, width = 16, height = 16, model="fire"})
elseif other_model == "bluefire" then
map:create_custom_entity({direction=0,
layer=layer,x=x,y=y + 16, width = 16, height = 16, model="bluefire"})
map:create_custom_entity({direction=0,
layer=layer,x=x,y=y - 16, width = 16, height = 16, model="bluefire"})
map:create_custom_entity({direction=0,
layer=layer,x=x + 16,y=y, width = 16, height = 16, model="bluefire"})
map:create_custom_entity({direction=0,
layer=layer,x=x - 16,y=y, width = 16, height = 16, model="bluefire"})
end
end)
end
end
end
-- Event called when the custom entity is initialized.
function entity:on_created()
self:set_size(16, 16)
self:set_modified_ground("traversable")
self:set_traversable_by("hero", true)
self:create_sprite("entities/grass")
self:add_collision_test("center", function(entity, hero)
if not grass then
if hero:get_animation() == "walking" or hero:get_animation() == "walking_with_shield" or hero:get_animation() == "rolling" or hero:get_animation() == "carrying_walking" and not grass then
grass = true
print(hero:get_walking_speed())
grass = false
local x, y, layer = hero:get_position()
if not map:get_entity("leaves") then
map:create_custom_entity({direction=0,
layer=layer,x=x,y=y, width = 40, height = 56, model="ground_effects/falling_leaves", name = "leaves"})
end
sol.timer.start(300, function()
return true
end)
end
end
local x, y, layer = hero:get_position()
if not map:get_entity("grassprite") then
map:create_custom_entity({direction=0,
layer=layer + 1,x=x,y=y, width = 16, height = 16, model="ground_effects/grass", name = "grassprite"})
end
end)
sol.timer.start(entity, 30, function()
-- Save or clear solid ground position on this platform.
if self:is_on_platform(hero) and (hero:get_state() == "free" or hero:get_state() == "carrying") then
hero:set_walking_speed(70)
elseif self:is_on_platform(hero) and hero:get_state() == "sword_loading" then
hero:set_walking_speed(29)
elseif (not self:is_on_platform(hero)) and (hero:get_state() == "free" or hero:get_state() == "carrying") then
hero:set_walking_speed(88)
if map:has_entity("grassprite") then
map:get_entity("grassprite"):remove()
end
elseif (not self:is_on_platform(hero)) and hero:get_state() == "sword_loading" then
hero:set_walking_speed(29)
if map:has_entity("grassprite") then
map:get_entity("grassprite"):remove()
end
------------------------------------------
else
if map:has_entity("grassprite") then
map:get_entity("grassprite"):remove()
end
-------------------------------------------
end
return true
end)
entity:add_collision_test("sprite", function(entity, other_entity, sprite, other_sprite)
-- Do nothing if the animation set is not of the sword, or if the sword is not close enough.
if other_sprite == nil then return end
local animation_set = other_sprite:get_animation_set()
local sword_id = map:get_hero():get_sword_sprite_id()
if animation_set ~= sword_id then return end
if entity:get_distance(other_entity) > 28 then return end -- Set a max distance to cut.
local x, y, layer = entity:get_position()
map:create_pickable({layer = layer, x=x, y=y, treasure_name="random"})
if map:has_entity("grassprite") then
map:get_entity("grassprite"):remove()
end
map:create_custom_entity({direction=0,
layer=layer,x=x,y=y, width = 40, height = 56, model="ground_effects/falling_leaves", name = "leaves"})
entity:remove()
end)
entity:add_collision_test("center", function(entity, hookshot)
if hookshot:get_sprite():get_animation() == "hook" then
local x, y, layer = entity:get_position()
map:create_pickable({layer = layer, x=x, y=y, treasure_name="random"})
if map:has_entity("grassprite") then
map:get_entity("grassprite"):remove()
end
map:create_custom_entity({direction=0,
layer=layer,x=x,y=y, width = 40, height = 56, model="ground_effects/falling_leaves", name = "leaves"})
entity:remove()
end
end)
end
function entity:is_on_platform(other)
local x, y, layer = hero:get_position()
return entity:overlaps(x, y)
end
entity:add_collision_test("sprite", on_collision)
entity:add_collision_test("overlapping", on_collision)