Skip to content

Instantly share code, notes, and snippets.

@AbigailBuccaneer
Created September 8, 2017 17:49
Show Gist options
  • Save AbigailBuccaneer/1faa65b1a8305b7f6e03005f17398ac9 to your computer and use it in GitHub Desktop.
Save AbigailBuccaneer/1faa65b1a8305b7f6e03005f17398ac9 to your computer and use it in GitHub Desktop.

Revisions

  1. AbigailBuccaneer created this gist Sep 8, 2017.
    21 changes: 21 additions & 0 deletions max_health_duplication.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    -- Loading this file (by placing it in lua/autorun, for example) will cause all
    -- calls to entity:SetMaxHealth() to be duplicated (by all duplicators).
    --
    -- Caution! This code has never been tested. It's never even been executed.
    --
    -- To the extent possible under law, the author(s) have dedicated all copyright
    -- and related and neighboring rights to this software to the public domain
    -- worldwide. This software is distributed without any warranty.

    do
    local entity = assert(FindMetaTable("Entity"))
    local f = assert(meta.SetMaxHealth)
    duplicator.RegisterEntityModifier("MaxHealth", function(player, entity, data)
    f(entity, data.value)
    end)

    function entity:SetMaxHealth(value)
    f(self, value)
    duplicator.StoreEntityModifier(self, "MaxHealth", { value = value })
    end
    end