local entity_id = GetUpdatedEntityID()
local pos_x, pos_y, r = EntityGetTransform( entity_id )

local components = EntityGetComponent( entity_id, "VariableStorageComponent" )

local target = EntityGetClosestWithTag(pos_x, pos_y, "homing_target")
local damage = nil
local damage_type = nil
local description = nil
local ragdoll_fx = nil

if(target ~= nil)then
    if( components ~= nil ) then

        for key,comp_id in pairs(components) do 
            local var_name = ComponentGetValue( comp_id, "name" )

            if( var_name == "damage") then
                damage = tonumber(ComponentGetValue(comp_id, "value_string"))
            end  
            if( var_name == "damage_type") then
                damage_type = ComponentGetValue(comp_id, "value_string")
            end  
            if( var_name == "description") then
                description = ComponentGetValue(comp_id, "value_string")
            end      
            if( var_name == "ragdoll_fx") then
                ragdoll_fx = ComponentGetValue(comp_id, "value_string")
            end                                                        
        end
    end     
    if(target ~= nil and damage ~= nil and type ~= nil and description ~= nil and ragdoll_fx ~= nil)then
        local target_x, target_y = EntityGetTransform(target)



        print('EntityInflictDamage('..tostring(target)..','..tostring(damage)..',"'..damage_type..'","'..description..'","'..ragdoll_fx..'",0,0,'..tostring(target)..','..tostring(target_x)..','..tostring(target_y)..',0)')

        EntityInflictDamage( target, damage, damage_type, description, ragdoll_fx, 0, 0, target, target_x, target_x, 0)
        EntityKill(entity_id)
    end
end