Jump to content

Recommended Posts

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.ActionStringOverride

If someone could help me out or point me in the direction of a tutorial, that'd be great!

@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)

 

Edited by Blueberrys

@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 changing

if not STRINGS.ACTIONS[action_name] or ACTIONS[action_name] then

into

if not STRINGS.ACTIONS[action_name] or not ACTIONS[action_name] then

This 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?

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...