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

local entity_id = GetUpdatedEntityID()

local x, y, r = EntityGetTransform(entity_id)

local damage = 0

local components = EntityGetComponent( entity_id, "VariableStorageComponent" )

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
end    


EntityInflictDamage( entity_id, damage, "DAMAGE_PROJECTILE", "bleeding", "BLOOD_EXPLOSION", 0, 0, entity_id, x, y, 0)

   --[[ local buffer_damage_entity = EntityCreateNew()

    EntitySetTransform(buffer_damage_entity, x, y, r, 1, 1)

    EntityAddComponent( buffer_damage_entity, "VariableStorageComponent", 
    { 
        name = "damage",
        value_string = damage,
    }) 
    EntityAddComponent( buffer_damage_entity, "VariableStorageComponent", 
    { 
        name = "damage_type",
        value_string = "DAMAGE_PROJECTILE",
    })    
    EntityAddComponent( buffer_damage_entity, "VariableStorageComponent", 
    { 
        name = "description",
        value_string = "bleeding",
    }) 
    EntityAddComponent( buffer_damage_entity, "VariableStorageComponent", 
    { 
        name = "ragdoll_fx",
        value_string = "BLOOD_EXPLOSION",
    })              
    EntityAddComponent( buffer_damage_entity, "LuaComponent", 
    { 
        execute_on_added="1",
        script_source_file="mods/spellbound_bundle/files/scripts/utilities/damage_entity.lua",
        execute_every_n_frame="-1",
        remove_after_executed="1",
    })                         
]]
