Jump to content

Recommended Posts

Hello,

 

I have released the first version of the Pipe mod and am currently trying to get a custom action associated with it. Right now it is equipable and edible but I would like to associated a new action named 'Smoke'. 

 

If anyone could assist me in what scripts I need to add to the mod or point me in the right direction on how to add a custom action to my item. I have looked around on the workshop and can't seem to find other mods with a custom action associated to them. If anyone could show me such a mod I feel confident I could adjust it to meet my needs.

 

Thanks

Link to comment
https://forums.kleientertainment.com/forums/topic/31787-custom-actions-on-prefabs/
Share on other sites

My RPG Items mod has a looking glass which includes a new action (used to identify hidden abilities on items).

oh your mod is nice to learn about overriding prefab

have only one question :

for example AddPrefabPostInit("armorgrass", HF_addrpgarmor)

function HF_addrpgarmor will have access to local functions and variables of armorgrass prefab?

for example AddPrefabPostInit("armorgrass", HF_addrpgarmor)

function HF_addrpgarmor will have access to local functions and variables of armorgrass prefab?

Yes.  The instance of the prefab you choose (in this case armorgrass) will be passed in as the argument to the function you specify.  So with  the function looking like

 

HF_addrpgarmor( variableName )

{

 stuff

}

 

variableName  (most people use 'inst' but that isnt required)  will be the instance that just spawned in world.  At this point you would do

 

variableName.dosomething()

variableName.someValue = blah

Edited by seronis

sadly its not

i am not talking about class that will be created by fn function inside prefab file

 

i have hope that this function as second parameter of AddPrefabPostInit will be executed in prefab "namespace" and get access to his local functions and variables

 

but its not.

 

only usual functions and variables inside class

just to be clear what i mean :

lets take for example prefabs/bat.lua

 

there local variables (constant) :

local SLEEP_DIST_FROMHOME = 1

and local function

local function ShouldSleep(inst)

you able to access them in prefab namespace, but not outside, include this postinit function as second parameter of AddPrefabPostInit

 

Maybe there other way to access it? So if i want to override few parameters i dont need to make copy of whole prefab :/
 

Edited by iWitch

hm not sure that "require" is good idea for prefab

its probably pointless since prefab will return object and end his execution.

 

i mean writing anything after

return Prefab( "forest/animals/walrus", create, assets, prefabs),    Prefab( "forest/animals/little_walrus", create_little, assets)

is pointless, its will never executed.

 

thats mean you still cant access to local variable/function

 

same with "modimport" even if it able to use files outside mod

Edited by iWitch

well here some examples how to http://lua-users.org/wiki/LuaHacks, but there also alot of warnings like "this example is academic and not really intended for production use".

 

one of examples : "Hack: Proxy Table of Local Variables, _L"

 

also not sure how full LUA implemented in game, may be there alot of restrictions.

Edited by iWitch

well i made it hehe. Solution have obvious problems, but its works.

 

here my test code modname/scripts/prefabs/test.lua :

print ("TEST : Opening file...")local prefabname = "chessjunk.lua"local filename = "scripts\\prefabs\\"..prefabnamelocal patchname = "chessjunkpatch.lua"local patchfilename = "..\\mods\\wulfeplus\\scripts\\prefabs\\"..patchnamelocal file = io.open(filename, "r")if file then    local str = file:read("*a")    if not str then str = "" end    file:close()    local pos = string.find(str,"return%s+Prefab")    if pos and pos > 1 then        local retstr = string.sub(str,pos)        print ("TEST : retstr = "..retstr)        local prefabstr = string.sub(str,1,pos-1)        local pfile = io.open(patchfilename, "r")        local pstr = ""        if pfile then            pstr = pfile:read("*a")            if not pstr then pstr = "" else print ("TEST : patch found") end            pfile:close()        end        local newstr = prefabstr.."\n"..pstr.."\n"..retstr--[[ --its just for output test        file = io.open(filename..".txt", "w")       if file then            print ("TEST : writing to test file")            file:write(newstr)            file:close()        end ]]--        loadstring(newstr)()    else        print ("TEST : pos failed ")    endend

patch file here just as example:

local MAXHITS = 5print "Patch loaded, hurrah"

pro :

 - you can make few small patches which can be inserted before/after function/variable to override

cons :

 - mod like this will ignore other mods changes in this prefarb (obviosly).

Edited by iWitch

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
×
  • Create New...