RedTarantula Posted January 3, 2018 Share Posted January 3, 2018 Hello! I need some help with manipulating creatures that already exist in-game. For a character that I am creating, I need to add a tag to the birds' prefab and change the birdbrain file as well. I've seen some mods that change those things directly on modmain and I believe that's so it is easier to be compatible with other mods that change existing prefabs and brains. I know how to change those things by recreating the prefab/brain file on my mod's scripts folder, but is there a way of doing it with "AddPrefabPostInit" and that kind of thing? I still don't know how those functions work. I don't know how to add a tag, to add a function to a creature or to actually replace part of the code. For example. The birdbrain file contains this: Spoiler local function ShouldFlyAway(inst) return not (inst.sg:HasStateTag("sleeping") or inst.sg:HasStateTag("busy") or inst.sg:HasStateTag("flight")) and (TheWorld.state.isnight or (inst.components.health ~= nil and inst.components.health.takingfiredamage and not (inst.components.burnable and inst.components.burnable:IsBurning())) or FindEntity(inst, SEE_THREAT_DIST, nil, nil, { "notarget", "INLIMBO"}, { "player", "monster", "scarytoprey" }) ~= nil) end And I would like to add a tag to the birds' prefab -> "birdfriendly" And so replace the ShouldFlyAway(inst) function from that to: Spoiler local function ShouldFlyAway(inst) return not (inst.sg:HasStateTag("sleeping") or inst.sg:HasStateTag("busy") or inst.sg:HasStateTag("flight")) and (TheWorld.state.isnight or (inst.components.health ~= nil and inst.components.health.takingfiredamage and not (inst.components.burnable and inst.components.burnable:IsBurning())) or FindEntity(inst, SEE_THREAT_DIST, nil, nil, { "notarget", "INLIMBO", "birdfriendly" }, { "player", "monster", "scarytoprey" }) ~= nil) end Is there a way of doing all of that on modmain or do I need to recreate the prefab+brain in my scripts folder? Thanks in advance! Link to comment Share on other sites More sharing options...
Aquaterion Posted January 3, 2018 Share Posted January 3, 2018 for brains you use AddBrainPostInit(brain, fn) for prefabs you do AddPrefabPostInit(prefabname, fn) However I'm not sure how modifying brains post init works exactly.. But for a list of all these PostInit methods that you can use, you can check scripts/modutil.lua Link to comment Share on other sites More sharing options...
RedTarantula Posted January 4, 2018 Author Share Posted January 4, 2018 Bump Thanks for the reply. I'm studying more the file you told me to check, Aquaterion. But if anyone can explain a bit more I'd appreciate it. I still don't know how to replace, add or remove functions and components on modmain. I assume "AddPrefab" would ADD a new function to the prefab, but how do I change or remove an existing one? And how do I simply add a tag to a creature? Link to comment Share on other sites More sharing options...
Aquaterion Posted January 4, 2018 Share Posted January 4, 2018 AddPrefabPostInit(prefabname, fn) would run the given function on that prefab every time 1 spawns so: local function modifyBird(inst) inst:AddTag("birdfriendly") if not GLOBAL.TheWorld.ismastersim then--before this if = clientside stuff | after this if = serverside stuff return inst end end AddPrefabPostInit("robin", modifyBird) every time a robin spawns, modifyBird will be called resulting in it having a new tag Link to comment 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