Skip to content

Instantly share code, notes, and snippets.

@StylianosGakis
Created December 10, 2019 23:11
Show Gist options
  • Save StylianosGakis/af6df1a6f1a85b28ad76f44597ef413f to your computer and use it in GitHub Desktop.
Save StylianosGakis/af6df1a6f1a85b28ad76f44597ef413f to your computer and use it in GitHub Desktop.
Health container pickup including adding extra max health (Note: Needs the MaxHealthAmount variable inside the config.lua to be defined as well)
dofile_once( "data/scripts/game_helpers.lua" )
dofile_once("data/scripts/lib/utilities.lua")
dofile( "mods/health_container/config.lua" )
function item_pickup( entity_item, entity_who_picked, item_name )
local pos_x, pos_y = EntityGetTransform( entity_item )
local damagemodels = EntityGetComponent( entity_who_picked, "DamageModelComponent" )
if( damagemodels ~= nil ) then
for i,v in ipairs(damagemodels) do
current_max_hp = tonumber( ComponentGetValue( v, "max_hp") )
current_hp = tonumber( ComponentGetValue( v, "hp" ) )
-- Health values are scaled up by 25 in the UI apparently. So using the 0.04 multiplier will allow the correct hp to be set
local target_max_hp = current_max_hp + (MaxHealthAmount * 0.04)
local target_hp = current_hp + (HealAmount * 0.04)
ComponentSetValue( v, "max_hp", target_max_hp)
if( target_hp > target_max_hp ) then target_hp = target_max_hp end
ComponentSetValue( v, "hp", target_hp)
break
end
end
GamePlaySound("mods/health_container/files/health_container_audio.snd", "health_container/hc_heal", pos_x, pos_y)
shoot_projectile( entity_item, "mods/health_container/files/data/entities/particles/health_container_pickup.xml", pos_x, pos_y, 0, 0 )
EntityKill( entity_item )
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment