-- Copyright ©2022 by Todd Hundersmarck (ThundR)
-- All Rights Reserved
THButterfly = {} local THButterfly_mt = Class(THButterfly, Butterfly) local dynamicIds = {} local function runScript() local globalEnv = g_thMain:getGlobalEnv() globalEnv.THButterfly = THButterfly g_thMain:hookFunction("Butterfly", "update", THButterfly) g_thMain:hookFunction("Butterfly", "delete", THButterfly) end function THButterfly:onCreate(id, ...) if entityExists(id) then dynamicIds[id] = true return THButterfly:superClass().onCreate(self, id, ...) end end function THButterfly:hook_update(superFunc, dt, ...) local id = self.id if entityExists(id) then local globalEnv = g_thMain:getGlobalEnv() local setTranslation_orig = globalEnv.setTranslation local setRotation_orig = globalEnv.setRotation if dynamicIds[id] then globalEnv.setTranslation = globalEnv.setWorldTranslation globalEnv.setRotation = globalEnv.setWorldRotation end local ra,rb,rc,rd,re = superFunc(self, dt, ...) globalEnv.setTranslation = setTranslation_orig globalEnv.setRotation = setRotation_orig for _, butterfly in pairs(self.butterflies) do if butterfly ~= self.activeButterfly then local butterflyId = butterfly.butterflyId if butterflyId ~= nil and not getVisibility(butterflyId) then butterfly.splinePos = 0 end end end return ra,rb,rc,rd,re end end function THButterfly:hook_delete(superFunc, ...) if self.id ~= nil then dynamicIds[self.id] = nil end g_currentMission:removeUpdateable(self) return superFunc(self, ...) end runScript()