dofile_once( "data/scripts/lib/utilities.lua" )

local entity_id    = GetUpdatedEntityID()
local x, y, angle = EntityGetTransform( entity_id )

--local recall_entities = EntityGetWithTag("recall_projectile")

local projectile_component = EntityGetFirstComponent(entity_id, "ProjectileComponent")

local owner = ComponentGetValue(projectile_component, "mWhoShot")

local tp_x = tonumber(GlobalsGetValue("tp_x", "0"))
local tp_y = tonumber(GlobalsGetValue("tp_y", "0")) 
local old_entity = tonumber(GlobalsGetValue("old_recall", "0")) 

if(tp_x ~= 0 or tp_y ~= 0)then
    EntitySetTransform( owner, tp_x, tp_y)
    EntityKill(entity_id)
    GlobalsSetValue("teleported_back", "1")
    EntityKill(old_entity)
    GlobalsSetValue("tp_x", "0")
    GlobalsSetValue("tp_y", "0")
    GlobalsSetValue("old_recall", "0")
else
    GlobalsSetValue("tp_x", tostring(x))
    GlobalsSetValue("tp_y", tostring(y))  
    GlobalsSetValue("old_recall", tostring(entity_id))
end
--[[
for k,entity in pairs(recall_entities)do
    if(entity ~= entity_id)then
        teleport_components = EntityGetComponent(entity, "TeleportProjectileComponent")
        for k,component in pairs(teleport_components)do
            EntityRemoveComponent(entity, component)
        end

        EntityKill(entity)
    end
end
]]