- Best answers
- 20
Armor Damage Script (Singleplayer)
Step 1: Set up per-agent item durability via slots and fill them in ti_on_agent_spawn
In module_constants
Python:
# First among your agent slots
agent_armor_dur_head = 100 # whatever number is open for you
agent_armor_dur_hand = agent_armor_dur_head + 1
agent_armor_dur_feet = agent_armor_dur_head + 2
agent_armor_dur_main = agent_armor_dur_head + 3
# and in your item_slots
slot_damaged_variant = 100 # Or, again, whatever you have available
Python:
agent_spawn_effects = (
ti_on_agent_spawn, 0, 0, [], [
(store_trigger_param_1, ":agent"),
(try_for_range, ":equipment_slot", 4, 8),
(agent_get_item_slot, ":equipment", ":agent", ":equipment_slot"),
(gt, ":equipment", 0), # Agent does have an armor equipped here
(item_get_hit_points, ":hp", ":equipment"),
(try_begin),
(eq, ":equipment_slot", 4), # Head
(agent_set_slot, ":agent", agent_armor_dur_head, ":hp"),
(else_try),
(eq, ":equipment_slot", 5), # Body
(agent_set_slot, ":agent", agent_armor_dur_main, ":hp"),
(else_try),
(eq, ":equipment_slot", 6), # Leg
(agent_set_slot, ":agent", agent_armor_dur_feet, ":hp"),
(else_try),
# Would be 7, Hand
(agent_set_slot, ":agent", agent_armor_dur_hand, ":hp"),
(try_end),
(try_end),
]),
You could also just make a flat hitpoint level by changing
(item_get_hit_points, ":hp", ":equipment"),
to
(assign, ":hp", 100),
Also you need to set up a script inside game_start and game_quick_start to assign the damaged variants to their original forms
Step 2: Locational Damage, Breaking and Swapping -
First, we need to determine where damage was on the agent.
In mission_templates, attached to a common ti_on_agent_hit
Python:
common_damage_system= (
ti_on_agent_hit, 0, 0, [],
[
(set_fixed_point_multiplier, 100),
(store_trigger_param, ":agent", 1),
(store_trigger_param, ":attacker", 2),
(store_trigger_param, ":damage", 3),
(store_trigger_param, ":bodypart", 4),
# (store_trigger_param, ":missile", 5),
(agent_get_troop_id, ":troop", ":agent"),
(agent_get_troop_id, ":attacker_troop", ":attacker"),
(assign, ":attacker_weapon", reg0),
(agent_is_alive, ":agent"),
(agent_is_human, ":agent"),
(store_agent_hit_points, ":health_remaining_actual", ":agent", 1),
(store_troop_health, ":current_health", ":troop"),
(troop_set_health, ":troop", 100),
(store_troop_health, ":max_health_actual", ":troop", 1),
(troop_set_health, ":troop", ":current_health"),
(try_begin),
(gt, ":attacker_weapon", 0),
(item_get_swing_damage_type, ":damage_type", ":attacker_weapon"),
# I dunno how to determine which attack was unleashed, but this will work
# We can use this to make certain damage types, such as blunt, do more damage
# to armor durability vs things like pierce which should nearly pass through
(else_try),
(assign, ":damage_type", 2), # If you don't have a weapon it's fists.
(try_end),
(try_begin),
(eq, ":damage_type", 0), # Cut
(assign, ":dampen", 30),
(else_try),
(eq, ":damage_type", 1), # Pierce
(assign, ":dampen", 35),
(else_try),
(eq, ":damage_type", 2), # Blunt
(assign, ":dampen", 15),
(try_end),
(store_div, ":durability_hit", ":damage", ":dampen"),
(agent_get_slot, ":head_durability", ":agent", agent_armor_dur_head),
(agent_get_slot, ":hand_durability", ":agent", agent_armor_dur_hand),
(agent_get_slot, ":feet_durability", ":agent", agent_armor_dur_feet),
(agent_get_slot, ":main_durability", ":agent", agent_armor_dur_main),
(agent_get_item_slot, ":head_armor", ":agent", 4),
(agent_get_item_slot, ":hand_armor", ":agent", 7),
(agent_get_item_slot, ":feet_armor", ":agent", 6),
(agent_get_item_slot, ":main_armor", ":agent", 5),
(item_get_slot, ":head_damaged_var", ":head_armor", slot_damaged_variant),
(item_get_slot, ":hand_damaged_var", ":hand_armor", slot_damaged_variant),
(item_get_slot, ":feet_damaged_var", ":feet_armor", slot_damaged_variant),
(item_get_slot, ":main_damaged_var", ":main_armor", slot_damaged_variant),
(try_begin),
(this_or_next|eq, ":bodypart", 0), # Guts
(is_between, ":bodypart", 7, 9), # Spine and Thorax
(gt, ":main_armor", 0), # Has Armor
(val_sub, ":main_durability", ":durability_hit"),
(val_max, ":main_durability", 0), # Durability cannot be negative
(agent_set_slot, ":agent", agent_armor_dur_main, ":main_durability"),
(eq, ":main_durability", 0),
(agent_unequip_item, ":agent", ":main_armor", 5),
(neq, ":main_damaged_var", 0),
(item_get_hit_points, ":hp", ":main_damaged_var"),
(agent_set_slot, ":agent", agent_armor_dur_main, ":hp"),
(agent_equip_item, ":agent", ":main_damaged_var", 5),
(else_try),
(is_between, ":bodypart", 1, 7), # Legs
(gt, ":feet_armor", 0), # Has Armor
(val_sub, ":feet_durability", ":durability_hit"),
(val_max, ":feet_durability", 0), # Durability cannot be negative
(agent_set_slot, ":agent", agent_armor_dur_feet, ":feet_durability"),
(eq, ":feet_durability", 0),
(agent_unequip_item, ":agent", ":feet_armor", 4),
(neq, ":feet_damaged_var", 0),
(item_get_hit_points, ":hp", ":feet_damaged_var"),
(agent_set_slot, ":agent", agent_armor_dur_feet, ":hp"),
(agent_equip_item, ":agent", ":feet_damaged_var", 4),
(else_try),
(eq, ":bodypart", 9), # head
(gt, ":head_armor", 0), # Has Armor
(val_sub, ":head_durability", ":durability_hit"),
(val_max, ":head_durability", 0), # Durability cannot be negative
(agent_set_slot, ":agent", agent_armor_dur_head, ":head_durability"),
(eq, ":head_durability", 0),
(agent_unequip_item, ":agent", ":head_armor", 5),
(neq, ":head_damaged_var", 0),
(item_get_hit_points, ":hp", ":head_damaged_var"),
(agent_set_slot, ":agent", agent_armor_dur_head, ":hp"),
(agent_equip_item, ":agent", ":head_damaged_var", 5),
(else_try),
(this_or_next|is_between, ":bodypart", 12, 14), # Left Forearms and Hand
(gt, ":bodypart", 17), # Right Forearms and Hand
(gt, ":hand_armor", 0), # Has Armor
(val_sub, ":hand_durability", ":durability_hit"),
(val_max, ":hand_durability", 0), # Durability cannot be negative
(agent_set_slot, ":agent", agent_armor_dur_hand, ":hand_durability"),
(eq, ":hand_durability", 0),
(agent_unequip_item, ":agent", ":hand_armor", 5),
(neq, ":hand_damaged_var", 0),
(item_get_hit_points, ":hp", ":hand_damaged_var"),
(agent_set_slot, ":agent", agent_armor_dur_hand, ":hp"),
(agent_equip_item, ":agent", ":hand_damaged_var", 5),
(try_end),
(set_trigger_result, ":damage"),
])
Tweaks I would do to make it more satisfying:
Store the location of the bone, make a particle burst at the location.
Create a physics item for the armor in the mod and allow it to pop off into the scene if destroyed.
This could probably be nested in a way to pretty it up and shorten the script, but this works for readability.
You could also simply move the item quality modifier down a stage and include various levels of disrepair that way, while keeping your items nice and tidy
Last edited: