Hi
I was wondering if it was possible to save a single custom entity state on the map when there are copies of the same entity ?
This is my alternate chest script (issue bellow)
It works fine when loaded in-game (though it can be optimized), the chest, animation, interraction and treasure works fine, same for the logic (if it is open then you can't re-open it), the issue is, if I place some copies of the same entity on the same map / another map, it acts as it was opened because it re-use the same way than the 1st chest do. And I want this script to be copied, used and functionnal on many dungeon maps without recreating a code for each chest
I don't have many idea so I don't really know if that would work and I don't really know how to render this possible, i'm stuck with this issue, if someone have any idea, I'm on.
I was wondering if it was possible to save a single custom entity state on the map when there are copies of the same entity ?
This is my alternate chest script (issue bellow)
Code (lua) Select
local entity = ...
local game = entity:get_game()
local map = entity:get_game():get_map()
local hero = entity:get_map():get_entity("hero")
-- Chest example : Small Key (code from : Big chest example : Master Key)
-- Hud notification : check hero & entity direction and tell by the way of a hud info if it can be opened
entity:add_collision_test("touching", function()
if not open and hero:get_direction() == entity:get_direction() then
game:set_custom_command_effect("action", "open")
else
game:set_custom_command_effect("action", nil)
end
end)
function entity:on_created()
self:set_drawn_in_y_order(true)
self:set_can_traverse("hero", false)
self:set_traversable_by("hero", false)
-- check if open
if open then
self:get_sprite():set_animation("open")
end
end
function entity:on_interaction()
local x,y = entity:get_position()
local hero = entity:get_map():get_entity("hero")
if not open then
open = false
end
if hero:get_direction() == entity:get_direction() and not open then
if entity:get_direction() == 0 then --right
hero:set_position(x-16, y)
elseif entity:get_direction() == 1 then --up
hero:set_position(x, y+16)
elseif entity:get_direction() == 2 then --left
hero:set_position(x+16, y)
elseif entity:get_direction() == 3 then --down
hero:set_position(x, y-16)
end
hero:freeze()
game:set_pause_allowed(false)
sol.timer.start(1,function()
hero:set_animation("drop")
end)
sol.timer.start(200,function()
if hero:get_direction() == 3 or hero:get_direction() == 1 then
hero:set_animation("stopped")
else
hero:set_animation("grabbing")
end
end)
sol.timer.start(300,function()
if hero:get_direction() == 0 or hero:get_direction() == 2 then
hero:set_animation("stopped")
end
self:get_sprite():set_animation("open")
sol.audio.play_sound("/common/chest_open")
end)
sol.timer.start(600,function()
hero:set_animation("stopped")
if hero:get_direction() == entity:get_direction() then
if entity:get_direction() == 0 then --right
hero:set_direction(3)
elseif entity:get_direction() == 1 then --up
hero:set_direction(2)
elseif entity:get_direction() == 2 then --left
hero:set_direction(3)
end
end
end)
sol.timer.start(750,function()
hero:set_animation("chest_holding_before_brandish")
end)
sol.timer.start(1500, function()
hero:unfreeze()
hero:start_treasure("small_key")
hero:set_animation("brandish_alternate") -- overwrite the default brandish animation for this particular item
game:set_pause_allowed(true)
hero:set_direction(entity:get_direction())
open = true
end)
elseif not open then
game:start_dialog("gameplay.cannot_open_chest_side")
end
end
It works fine when loaded in-game (though it can be optimized), the chest, animation, interraction and treasure works fine, same for the logic (if it is open then you can't re-open it), the issue is, if I place some copies of the same entity on the same map / another map, it acts as it was opened because it re-use the same way than the 1st chest do. And I want this script to be copied, used and functionnal on many dungeon maps without recreating a code for each chest
I don't have many idea so I don't really know if that would work and I don't really know how to render this possible, i'm stuck with this issue, if someone have any idea, I'm on.