lunick44 Posted February 18, 2015 Share Posted February 18, 2015 I'm interested in creating an item mod, but I'm currently stuck at trying to figure out how to temporarily change the name of an action's string. I'm looking for something along the lines of changing "mine," "chop," etc. to something else while having a certain hand-equipable item equiped, but still producing the same result. (i.e. a custom axe that says "cut" instead of "chop" when you mouse over a tree) The closest I've come is finding this snippet of code in the Tiny Alchemy Powers mod, but it's still not quite what I'm looking for.AddSimPostInit(function(inst) local oldactionstringoverride = inst.ActionStringOverrideIf someone could help me out or point me in the direction of a tutorial, that'd be great! Link to comment Share on other sites More sharing options...
Blueberrys Posted February 18, 2015 Share Posted February 18, 2015 @lunick44 Use this._G = GLOBALACTIONS = _G.ACTIONSSTRINGS = _G.STRINGSlocal function AddActionOption(action_name, new_key, new_str, fn) -- Check if action exists if not STRINGS.ACTIONS[action_name] or not ACTIONS[action_name] then return end -- Preserve old str local old_str = STRINGS.ACTIONS[action_name] -- If str, convert to table if type(old_str) == "string" then STRINGS.ACTIONS[action_name] = { GENERIC = old_str } end -- Add your key/value STRINGS.ACTIONS[action_name][new_key] = new_str -- Preserve old fn, if exists local old_strfn = ACTIONS[action_name].strfn -- Set new fn ACTIONS[action_name].strfn = function(act) if fn(act) then return new_key elseif old_strfn then return old_strfn(act) end endendAddActionOption("CHOP", "CUT", "Cut", function(act) if act.invobject.prefab == "your_item_prefab" then return true endend)Edit: Fixed the mistakes mentioned below. ( ACTIONS[action_name] and old_strfn ) Edit 2: Slightly improved code. (Removed unnecessary table condition) Link to comment Share on other sites More sharing options...
lunick44 Posted February 19, 2015 Author Share Posted February 19, 2015 @Blueberrys After using the code you provided, I wasn't having any luck. My item still showed "Chop," but after some staring, and trial and error, I got it working by changingif not STRINGS.ACTIONS[action_name] or ACTIONS[action_name] thenintoif not STRINGS.ACTIONS[action_name] or not ACTIONS[action_name] thenThis gave me the effect I wanted, but when I tried switching to a gold axe, the game crashed and gave me this error: SCRIPT ERROR! Showing error screen ...ps/common/dont_starve/data/../mods/HMmod/modmain.lua:36: attempt to call upvalue 'old_strfn' (a nil value)LUA ERROR stack traceback: C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/../mods/HMmod/modmain.lua(36,1) in function 'strfn' C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/bufferedaction.lua(65,1) in function 'GetActionString' C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/widgets/hoverer.lua(51,1) in function 'OnUpdate' C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/frontend.lua(538,1) in function 'Update' C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/frontend.lua(589,1) in function 'PushScreen' C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/frontend.lua(697,1) in function 'ShowScreen' C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/frontend.lua(725,1) in function 'DisplayError' C:/Program Files (x86)/Steam/steamapps/common/dont_starve/data/scripts/mainfunctions.lua(851,1)Assert failure 'mPurgeList.empty()' at ..\source\simlib\EntityManager.cpp(87): Trace follows... Any advice? Link to comment Share on other sites More sharing options...
lunick44 Posted February 19, 2015 Author Share Posted February 19, 2015 @Blueberrys Just posting this because I didn't know I had to use BBCode for member names, and I can't edit posts yet x-x Link to comment Share on other sites More sharing options...
Blueberrys Posted February 19, 2015 Share Posted February 19, 2015 @lunick44Whoops. Nice catch on that, btw. As for the error,Change thiselse return old_strfn(act)end to thiselseif old_strfn then return old_strfn(act)end Link to comment Share on other sites More sharing options...
lunick44 Posted February 19, 2015 Author Share Posted February 19, 2015 @Blueberrys Thanks so much, it works perfectly now! I'll be sure to credit you in this if I ever decide to upload the mod! Link to comment Share on other sites More sharing options...
itsy73 Posted February 23, 2015 Share Posted February 23, 2015 @BlueberrysFinally I got my "Drinking"-action working (couldn't make it out in a week, as I am a no-programmer). And I have learned a lot! Thank you very much!Would you mind, if I implement it in my mod too? Of course with credits Link to comment Share on other sites More sharing options...
Blueberrys Posted February 23, 2015 Share Posted February 23, 2015 @itsy73 Sure, go ahead! For anyone else who comes across this, feel free to use it however you like. 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.