kavaline Posted May 15, 2021 Share Posted May 15, 2021 (edited) I need change 2 local function of hounded component (SummonSpawn and ReleaseSpawn). Searching about it, I found the Rezecibs UpvalueHacker. I tried many combinations with AddComponentPostInit and AddClassPostConstruct, but nothing works (the new code works when I tried with a custom hounded file in my mod, but I want compatibility with others mods that affects hound wave, and learn how to do it for future mods). That's what I'm trying to do: AddClassPostConstruct("components/hounded", function(self) local ac = GLOBAL.require("components/hounded") local function SummonSpawn(pt, wave) --added 'wave' parameter, so, Wargs will not spawn Hellhounds local spawn_pt = GetSpawnPoint(pt) if spawn_pt ~= nil then local spawn = nil if wave and math.random() < 0.9 then --checking 'wave' condition and Hellhound spawn chance (high value for test purpose) spawn = SpawnPrefab("hellhound") --custom mob tested and working else --if not hound wave or chance, use default event spawn = SpawnPrefab( (math.random() >= GetSpecialSpawnChance() and _spawndata.base_prefab) or ((TheWorld.state.iswinter or TheWorld.state.isspring) and _spawndata.winter_prefab) or _spawndata.summer_prefab ) end if spawn ~= nil then spawn.Physics:Teleport(spawn_pt:Get()) spawn:FacePoint(pt) if spawn.components.spawnfader ~= nil then spawn.components.spawnfader:FadeIn() end return spawn end end end local function ReleaseSpawn(target) if not _targetableplayers[target.GUID] or _targetableplayers[target.GUID] == "land" then local spawn = SummonSpawn(target:GetPosition(), true) --edited line, added 'true' parameter for 'wave' if spawn ~= nil then spawn.components.combat:SuggestTarget(target) return true end end return false end UpvalueHacker.SetUpvalue(ac._ctor, SummonSpawn, "SummonSpawn") UpvalueHacker.SetUpvalue(ac._ctor, ReleaseSpawn, "ReleaseSpawn") end) But during the waves, only spawns hounds. How I can fix this to work? @old "Spawning custom mob in place of other" Hi, I did a custom hound (a complete new prefab, based on files of hound, not a reskin or alternative hound). I alread spawned him to test and works fine. I want that sometimes (2% chance), instead of spawning hound from hound mounds or hound attack, spawns this mob. If this takes much effort, at least, in every hound attack, he can spawns too to attack (5% chance in every attack, spawns only one). Someone can help me or tell a mod with a friendly code to learn? Edited May 23, 2021 by kavaline Edited to direct my problem, instead of create a new topic Link to comment https://forums.kleientertainment.com/forums/topic/130015-solved-help-to-override-components-local-function/ Share on other sites More sharing options...
Gleenus Posted May 16, 2021 Share Posted May 16, 2021 The world spawn hound waves using components.hounded You will need to edit this class post init 1 Link to comment https://forums.kleientertainment.com/forums/topic/130015-solved-help-to-override-components-local-function/#findComment-1460906 Share on other sites More sharing options...
kavaline Posted May 17, 2021 Author Share Posted May 17, 2021 On 5/16/2021 at 9:06 AM, Gleenus said: The world spawn hound waves using components.hounded You will need to edit this class post init Have an example of a post init? I edited 2 functions of the hounded component (to spawn my mob, and a parameter in another function for Vargs dont spawn my mob). I think that using this post init, my mod can be compatible with others mods that affects the hound waves. (and also, I added for the hunt component too, but was not a function edit, just added my mob to "_alternate_beasts" array) Link to comment https://forums.kleientertainment.com/forums/topic/130015-solved-help-to-override-components-local-function/#findComment-1461289 Share on other sites More sharing options...
Gleenus Posted May 17, 2021 Share Posted May 17, 2021 3 hours ago, kavaline said: Have an example of a post init? I edited 2 functions of the hounded component (to spawn my mob, and a parameter in another function for Vargs dont spawn my mob). I think that using this post init, my mod can be compatible with others mods that affects the hound waves. (and also, I added for the hunt component too, but was not a function edit, just added my mob to "_alternate_beasts" array) I don't have any examples in hand right now, but you can search in your mods folder this following string AddComponentPostInit And see some examples Link to comment https://forums.kleientertainment.com/forums/topic/130015-solved-help-to-override-components-local-function/#findComment-1461367 Share on other sites More sharing options...
kavaline Posted May 19, 2021 Author Share Posted May 19, 2021 Edited the topic to redirects the main problem now. Link to comment https://forums.kleientertainment.com/forums/topic/130015-solved-help-to-override-components-local-function/#findComment-1461668 Share on other sites More sharing options...
kavaline Posted May 20, 2021 Author Share Posted May 20, 2021 Not solved yet .-. Link to comment https://forums.kleientertainment.com/forums/topic/130015-solved-help-to-override-components-local-function/#findComment-1461934 Share on other sites More sharing options...
Monti18 Posted May 21, 2021 Share Posted May 21, 2021 On 5/16/2021 at 1:44 AM, kavaline said: I need change 2 local function of hounded component (SummonSpawn and ReleaseSpawn). Searching about it, I found the Rezecibs UpvalueHacker. I tried many combinations with AddComponentPostInit and AddClassPostConstruct, but nothing works (the new code works when I tried with a custom hounded file in my mod, but I want compatibility with others mods that affects hound wave, and learn how to do it for future mods). That's what I'm trying to do: AddClassPostConstruct("components/hounded", function(self) local ac = GLOBAL.require("components/hounded") local function SummonSpawn(pt, wave) --added 'wave' parameter, so, Wargs will not spawn Hellhounds local spawn_pt = GetSpawnPoint(pt) if spawn_pt ~= nil then local spawn = nil if wave and math.random() < 0.9 then --checking 'wave' condition and Hellhound spawn chance (high value for test purpose) spawn = SpawnPrefab("hellhound") --custom mob tested and working else --if not hound wave or chance, use default event spawn = SpawnPrefab( (math.random() >= GetSpecialSpawnChance() and _spawndata.base_prefab) or ((TheWorld.state.iswinter or TheWorld.state.isspring) and _spawndata.winter_prefab) or _spawndata.summer_prefab ) end if spawn ~= nil then spawn.Physics:Teleport(spawn_pt:Get()) spawn:FacePoint(pt) if spawn.components.spawnfader ~= nil then spawn.components.spawnfader:FadeIn() end return spawn end end end local function ReleaseSpawn(target) if not _targetableplayers[target.GUID] or _targetableplayers[target.GUID] == "land" then local spawn = SummonSpawn(target:GetPosition(), true) --edited line, added 'true' parameter for 'wave' if spawn ~= nil then spawn.components.combat:SuggestTarget(target) return true end end return false end UpvalueHacker.SetUpvalue(ac._ctor, SummonSpawn, "SummonSpawn") UpvalueHacker.SetUpvalue(ac._ctor, ReleaseSpawn, "ReleaseSpawn") end) But during the waves, only spawns hounds. How I can fix this to work? This is because your function SummonSpawn that you're replacing is nil. You need to change your function to this: AddClassPostConstruct("components/hounded", function(self) local ac = GLOBAL.require("components/hounded") local GetSpawnPoint = UpvalueHacker.GetUpvalue(self.SummonSpawn, "SummonSpawn", "GetSpawnPoint") local function SummonSpawn(pt, wave) --added 'wave' parameter, so, Wargs will not spawn Hellhounds local spawn_pt = GetSpawnPoint(pt) if spawn_pt ~= nil then local spawn = nil if wave and math.random() < 0.9 then --checking 'wave' condition and Hellhound spawn chance (high value for test purpose) spawn = SpawnPrefab("hellhound") --custom mob tested and working else --if not hound wave or chance, use default event spawn = SpawnPrefab( (math.random() >= GetSpecialSpawnChance() and _spawndata.base_prefab) or ((TheWorld.state.iswinter or TheWorld.state.isspring) and _spawndata.winter_prefab) or _spawndata.summer_prefab ) end if spawn ~= nil then spawn.Physics:Teleport(spawn_pt:Get()) spawn:FacePoint(pt) if spawn.components.spawnfader ~= nil then spawn.components.spawnfader:FadeIn() end return spawn end end end local function ReleaseSpawn(target) if not _targetableplayers[target.GUID] or _targetableplayers[target.GUID] == "land" then local spawn = SummonSpawn(target:GetPosition(), true) --edited line, added 'true' parameter for 'wave' if spawn ~= nil then spawn.components.combat:SuggestTarget(target) return true end end return false end UpvalueHacker.SetUpvalue(self.SummonSpawn, SummonSpawn, "SummonSpawn") UpvalueHacker.SetUpvalue(self.ForceReleaseSpawn, ReleaseSpawn, "ReleaseSpawn") end) Don't forget to have a local SpawnPrefab = GLOBAL.SpawnPrefab in your modmain. 1 1 Link to comment https://forums.kleientertainment.com/forums/topic/130015-solved-help-to-override-components-local-function/#findComment-1462309 Share on other sites More sharing options...
kavaline Posted May 22, 2021 Author Share Posted May 22, 2021 (edited) On 5/21/2021 at 9:47 AM, Monti18 said: This is because your function SummonSpawn that you're replacing is nil. You need to change your function to this: AddClassPostConstruct("components/hounded", function(self) local ac = GLOBAL.require("components/hounded") local GetSpawnPoint = UpvalueHacker.GetUpvalue(self.SummonSpawn, "SummonSpawn", "GetSpawnPoint") local function SummonSpawn(pt, wave) --added 'wave' parameter, so, Wargs will not spawn Hellhounds local spawn_pt = GetSpawnPoint(pt) if spawn_pt ~= nil then local spawn = nil if wave and math.random() < 0.9 then --checking 'wave' condition and Hellhound spawn chance (high value for test purpose) spawn = SpawnPrefab("hellhound") --custom mob tested and working else --if not hound wave or chance, use default event spawn = SpawnPrefab( (math.random() >= GetSpecialSpawnChance() and _spawndata.base_prefab) or ((TheWorld.state.iswinter or TheWorld.state.isspring) and _spawndata.winter_prefab) or _spawndata.summer_prefab ) end if spawn ~= nil then spawn.Physics:Teleport(spawn_pt:Get()) spawn:FacePoint(pt) if spawn.components.spawnfader ~= nil then spawn.components.spawnfader:FadeIn() end return spawn end end end local function ReleaseSpawn(target) if not _targetableplayers[target.GUID] or _targetableplayers[target.GUID] == "land" then local spawn = SummonSpawn(target:GetPosition(), true) --edited line, added 'true' parameter for 'wave' if spawn ~= nil then spawn.components.combat:SuggestTarget(target) return true end end return false end UpvalueHacker.SetUpvalue(self.SummonSpawn, SummonSpawn, "SummonSpawn") UpvalueHacker.SetUpvalue(self.ForceReleaseSpawn, ReleaseSpawn, "ReleaseSpawn") end) Don't forget to have a local SpawnPrefab = GLOBAL.SpawnPrefab in your modmain. So, if the replacing function is nil, the game will not override and will works with the original function? I tried your suggestion, return an error of "attempt to index global '_targetableplayers' (a nil value)", I will try fix it @edit Added this line before the functions and worked; local _targetableplayers = {} Thanks so much! Edited May 22, 2021 by kavaline Link to comment https://forums.kleientertainment.com/forums/topic/130015-solved-help-to-override-components-local-function/#findComment-1462737 Share on other sites More sharing options...
Monti18 Posted May 23, 2021 Share Posted May 23, 2021 Oh yeah, I forgot about this variable, sorry Sorry, I was a bit unclear with the nil function. I think the function you were overriding was not existing (which I meant by nil) that's why there was no change as the function was not at all referenced in the hounded component, so if it's not called, you will never hear of it. I'm not an expert with the UpValueHacker, but I woud recommend you to get all the variables that are needed for the function from the component. local _targetableplayers = {} is also in hounded component, but it could change. Your targeteableplayer table will never change, so there could be some bugs that could arise. I would take this value the same way as I did it with GetSpawnPoint. As I said, I'm no expert here, so it could also be wrong and not change anything. 2 Link to comment https://forums.kleientertainment.com/forums/topic/130015-solved-help-to-override-components-local-function/#findComment-1462816 Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now