15
« on: December 26, 2018, 05:53:05 AM »
I created a different entity using a simpler version of the code and I was able to get it to work with one but not with multiple entities. Multiple entities will have it work with one but multiple will make the ground effect flicker. Anyone get why this isn't working?
local entity = ...
local game = entity:get_game()
local map = entity:get_map()
local hero = map:get_hero()
local grass = false
local timer = nil
function entity:on_created()
self:set_size(16, 16)
self:set_modified_ground("traversable")
self:set_traversable_by("hero", true)
self:add_collision_test("center", function(self, hero)
if not grass then
if hero:get_animation() == "walking" or hero:get_animation() == "walking_with_shield" or hero:get_animation() == "rolling" and not grass then
grass = true
print(hero:get_walking_speed())
grass = false
local x, y, layer = hero:get_position()
sol.timer.start(self, 300, function()
return true
end)
end
end
local x, y, layer = hero:get_position()
if not map:has_entity("grassprite") and self:is_on_platform(hero) then
local grassprite = map:create_custom_entity({direction=0,
layer=layer + 1,x=x,y=y, width = 16, height = 16, model="ground_effects/nightsplash", name = "grassprite"})
end
end)
local timer = sol.timer.start(30, function()
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)
for entity in map:get_entities_by_type("custom_entity") do
if entity:get_model() == "ground_effects/nightsplash" then
entity:remove()
end
end
elseif (not self:is_on_platform(hero)) and hero:get_state() == "sword_loading" then
hero:set_walking_speed(29)
for entity in map:get_entities_by_type("custom_entity") do
if entity:get_model() == "ground_effects/nightsplash" then
entity:remove()
end
end
------------------------------------------
else
for entity in map:get_entities_by_type("custom_entity") do
if entity:get_model() == "ground_effects/nightsplash" then
entity:remove()
end
end
-------------------------------------------
end
return true
end)
end
function entity:is_on_platform(other)
local x, y, layer = hero:get_position()
return entity:overlaps(x, y)
end