Jump to content

Adding new action

Recommended Posts

Hello! It has been a while since I have worked on modding, so i'm pretty rusty. (Not that i was good to begin with)

I'm looking to replicate something similar to Wortox's teleport ability but without the use of souls/blinkstaff without an item, i have gotten it to work with the use of souls but it seems to me the only other bit I need to change is the blink action itself.

ACTIONS.BLINK.strfn = function(act)
    return act.invobject == nil and act.doer ~= nil and act.doer:HasTag("soulstealer") and "SOUL" or nil

ACTIONS.BLINK.fn = function(act)
	local act_pos = act:GetActionPoint()
    if act.invobject ~= nil then
        if act.invobject.components.blinkstaff ~= nil then
            return act.invobject.components.blinkstaff:Blink(act_pos, act.doer)
    elseif act.doer ~= nil
        and act.doer.sg ~= nil
        and act.doer.sg.currentstate.name == "portal_jumpin_pre"
        and act_pos ~= nil
        and act.doer.components.inventory ~= nil
        and act.doer.components.inventory:Has("wortox_soul", 1) then
        act.doer.components.inventory:ConsumeByName("wortox_soul", 1)
        act.doer.sg:GoToState("portal_jumpin", act_pos)
        return true

I'm going to need a new tag and remove the "and "SOUL" or nil" bit, but then if someone plays wortox that will mess them up i assume.

Basically the question is, how can I make a new one of these actions without hindering other characters, i assume I shouldnt touch the actions.lua file at all, and if that is the case how would I do that in my character file?

Bonus questions: How can i make custom localization so it does not say Soul hop, and make it say something else? Is it possible to change the key bind wrong right clicking to another key? I currently have it possible to use a keyhandler, but i'm not sure how to pass in anything other than right click

local function GetPointSpecialActions(inst, pos, useitem, right)
    if right and useitem == nil then
        local rider = inst.replica.rider
        if rider == nil or not rider:IsRiding() then
            return { ACTIONS.BLINK }
    return {}

the "right" is there, but trying to change it to a key value like 122 will not read correctly like I have for other things.


Thanks in advance!

Edited by TheBigDeal
Link to comment
Share on other sites

When it comes to changing anything in game, people usually store the original function/action in a variable, run their own code, and if they need a value from the old function or if it needs to run, they call it somewhere in there. You should check out my torch+ mod that does something similar with actions. I'll paste a snippet of it here:

--the above line will, like before, store the whole function(and it's looooong)

--this will override the original function. It will perform it, but then check to see if the item can be cooked by the torch(also through the food's caloric value)
GLOBAL.ACTIONS.COOK.fn = function(act)
	if act.invobject.components.cooker then
		local temp = act.invobject
		act.invobject = act.target
		act.target = temp
	local cancook, str = COOKFN(act)
	if not cancook then
		if act.invobject:HasTag("lightcooker") and act.target.components.edible ~= nil and act.target.components.edible.hungervalue > TUNING.CALORIES_SMALL then
			return false, "TOODENSE"
		elseif act.target:HasTag("lightcooker") and act.invobject.components.edible ~= nil and act.invobject.components.edible.hungervalue > TUNING.CALORIES_SMALL then
			return false, "TOODENSE"
			return cancook, str
		return cancook, str

We store the old COOK.fn in COOKFN. What we're doing here is allowing the torch to cook food only with a small calorie value. In modmain we added a cooker component to the torch prefab as well as a tag called "lightcooker" that lets us know it was a torch. All we change in COOK.fn is this: if the cooker was a torch, and the food has a large food value, then return false. This is because we only want the torch to cook small things. My point here is that you can hack into the actions functions as long as you make it specific enough to what you want. And, if the action has calls to other functions, then you should probably run it at some point in your replacement function.

As for changing the string of Soul hop, you might be able to find where it is defined in strings.lua. GLOBAL.STRINGS.ACTIONS.BLINK.SOUL might be what you're looking for. Maybe in mod main you can do something like GLOBAL.STRINGS.ACTIONS.BLINK.SOUL = "Your text here". Although if you have a new action you can just make it your own string like GLOBAL.STRINGS.ACTIONS.BLINK.MYACTION = "Your text here".

Edited by rawii22
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

  • Create New...