Alright, sry for the missing code in the last post.
For better understanding, the Item uses up "MP" everytime it is used.
You see the keyboard_binding unchanged, so you see how I indended to do it.
The collision_test is new. I want to try to make a clone on a walkable switch to activate it (the switch deactivates when you step off of it), so the hero can pass f.e. a bridge while the clone is active. When the clone vanishes the switch should deactivate and the bridge should disappear. But maybe thats another topic ^^
And this is, what I added in the game_manager:
As always, thanks in advance
For better understanding, the Item uses up "MP" everytime it is used.
You see the keyboard_binding unchanged, so you see how I indended to do it.
The collision_test is new. I want to try to make a clone on a walkable switch to activate it (the switch deactivates when you step off of it), so the hero can pass f.e. a bridge while the clone is active. When the clone vanishes the switch should deactivate and the bridge should disappear. But maybe thats another topic ^^
Code (Lua) Select
--Script of the Item "Clone"--
local item = ...
local game = item:get_game()
--Item "Clone"--
function item:on_created()
item:set_savegame_variable("possession_clone")
item:set_assignable(true)
end
--function item:on_obtained(variant, savegame_variable)
--end
function item:on_using()
local map = item:get_map()
local player = map:get_hero()
local x, y, layer = player:get_position()
local direction = player:get_direction()
local mp_needed = 5
--Control back to Player--
function done()
game:remove_life(mp_needed)
end
--Create Dublicate Entity--
clone = map:create_custom_entity({
direction = direction,
layer = layer,
x = x,
y = y,
width = 24,
height = 24,
})
--Clone Sprites & Animationen--
function clone_animation()
player:unfreeze()
player:set_animation("clone_active")
clone_create = clone:create_sprite("entities/clone")
clone_create:set_direction(direction)
clone_create:set_animation("duplicate")
sol.timer.start(clone, 5000, function()
clone:remove_sprite()
game:set_command_keyboard_binding("item_1", "x")
done()
end)
end
--Collisions Switch-- --Not finished!!--
clone:add_collision_test("overlapping", function(clone, entity)
map:get_entity("switch_bridge"):set_activated()
end)
--Start "Clone", when enough MP--
if game:get_life() > mp_needed and
item:has_variant(1) then
player:freeze()
player:set_animation("clone", function()
clone_animation()
game:set_command_keyboard_binding("item_1", nil)
end)
end
--End Item "Clone"--
item:set_finished()
end
And this is, what I added in the game_manager:
Code (Lua) Select
function game:on_map_changed(map)
game:set_command_keyboard_binding("item_1", "x")
end
^As always, thanks in advance