Wight Posted February 23, 2014 Share Posted February 23, 2014 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 Share on other sites More sharing options...
Heavenfall Posted February 23, 2014 Share Posted February 23, 2014 My RPG Items mod has a looking glass which includes a new action (used to identify hidden abilities on items). Link to comment Share on other sites More sharing options...
TheDanaAddams Posted February 23, 2014 Share Posted February 23, 2014 And Link has the bombs' "drop single" action, also used in Din's Fire. Plus a neat trick that renames the potions' action from eat to drink. Link to comment Share on other sites More sharing options...
NikMik Posted February 25, 2014 Share Posted February 25, 2014 Plus a neat trick that renames the potions' action from eat to drink.Thank you so much for this information. Link to comment Share on other sites More sharing options...
Wight Posted February 25, 2014 Author Share Posted February 25, 2014 Both your mods helped me out a ton and were exactly what I was looking for. Thanks you! Link to comment Share on other sites More sharing options...
iWitch Posted February 25, 2014 Share Posted February 25, 2014 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 prefabhave only one question :for example AddPrefabPostInit("armorgrass", HF_addrpgarmor)function HF_addrpgarmor will have access to local functions and variables of armorgrass prefab? Link to comment Share on other sites More sharing options...
seronis Posted February 25, 2014 Share Posted February 25, 2014 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 Link to comment Share on other sites More sharing options...
iWitch Posted February 25, 2014 Share Posted February 25, 2014 sadly its noti 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 Link to comment Share on other sites More sharing options...
iWitch Posted February 25, 2014 Share Posted February 25, 2014 just to be clear what i mean :lets take for example prefabs/bat.lua there local variables (constant) :local SLEEP_DIST_FROMHOME = 1and local functionlocal 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 :/ Link to comment Share on other sites More sharing options...
seronis Posted February 25, 2014 Share Posted February 25, 2014 Oh i get what you're saying. There is some way to do it using the 'require' keyword but i dont know the specifics as im not that good with lua Link to comment Share on other sites More sharing options...
iWitch Posted February 25, 2014 Share Posted February 25, 2014 hm not sure that "require" is good idea for prefabits probably pointless since prefab will return object and end his execution. i mean writing anything afterreturn 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 Link to comment Share on other sites More sharing options...
iWitch Posted February 25, 2014 Share Posted February 25, 2014 all what i dream about is AddPrefabPostInit-like function which execute something before Prefab function inside prefab.lua will called something like AddPrefabPreInit(prefab_name_here,preprefabfunc) Link to comment Share on other sites More sharing options...
Heavenfall Posted February 25, 2014 Share Posted February 25, 2014 No, there's no way to access local variables unless they get stored somewhere. Link to comment Share on other sites More sharing options...
iWitch Posted February 25, 2014 Share Posted February 25, 2014 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. Link to comment Share on other sites More sharing options...
iWitch Posted February 25, 2014 Share Posted February 25, 2014 (del)nwm its wrong anyway Link to comment Share on other sites More sharing options...
iWitch Posted February 25, 2014 Share Posted February 25, 2014 nah forget about it, game scripts probably not changing that often, so just_copy_prefab_and_change_what_you_want is way to go Link to comment Share on other sites More sharing options...
iWitch Posted February 25, 2014 Share Posted February 25, 2014 --del Link to comment Share on other sites More sharing options...
iWitch Posted February 25, 2014 Share Posted February 25, 2014 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 ") endendpatch 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 overridecons : - mod like this will ignore other mods changes in this prefarb (obviosly). Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.