Jump to content

Editing prefabs


Recommended Posts

Hey all! I'm trying to edit prefab so it will work with my mod. Is it posible to somehow eddit some functions and add some components to prefab without re-adding it?

If someoe'll help me, I'll give him some skins such as:

Tuxedo Gloves

Green Sweater Vest

Knee Pants

Blue Sneakers :)

  • Like 1
Link to comment
Share on other sites

Without much information this is as generic as I can make it.

AddPrefabPostInit(
    "someprefabname",
    function(inst)
        if GLOBAL.TheWorld.ismastersim
        then
            inst:AddComponent("somecomponentname")
        end
        local somefunction_old = inst.somefunction
        if somefunction_old
        then
            inst.somefunction = function(self, arg1, arg2, ...)
                -- Prehook here
                somefunction_old(self, arg1, arg2, ...)
                -- Posthook here
            end
        end
    end
)

 

Link to comment
Share on other sites

7 hours ago, CarlZalph said:

Without much information this is as generic as I can make it.


AddPrefabPostInit(
    "someprefabname",
    function(inst)
        if GLOBAL.TheWorld.ismastersim
        then
            inst:AddComponent("somecomponentname")
        end
        local somefunction_old = inst.somefunction
        if somefunction_old
        then
            inst.somefunction = function(self, arg1, arg2, ...)
                -- Prehook here
                somefunction_old(self, arg1, arg2, ...)
                -- Posthook here
            end
        end
    end
)

 

What is _old for? I need to add it to the name of my function?

  • Like 1
Link to comment
Share on other sites

24 minutes ago, makar5000 said:

What is _old for? I need to add it to the name of my function?

"Somefunction_old" is an example name of a variable you can use to store old version of the function, before you replaced it with a new, custom one.

It allows you to use the old function when needed.

Edited by PanAzej
words
Link to comment
Share on other sites

22 hours ago, CarlZalph said:

Without much information this is as generic as I can make it.


AddPrefabPostInit(
    "someprefabname",
    function(inst)
        if GLOBAL.TheWorld.ismastersim
        then
            inst:AddComponent("somecomponentname")
        end
        local somefunction_old = inst.somefunction
        if somefunction_old
        then
            inst.somefunction = function(self, arg1, arg2, ...)
                -- Prehook here
                somefunction_old(self, arg1, arg2, ...)
                -- Posthook here
            end
        end
    end
)

 

Ok, thx. Give me youre trade link, so I can give you your reward :)

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...