Jump to content

Recommended Posts

Hi. I'm trying to make a mod that changes the behavior of tooth traps. So far, I've been able to do what I wanted, all that is left (pun intended) is to allow tooth traps to be reset with left mouse and spacebar instead of right mouse. How exactly do I change that? Will I have to add an action replacing RESETMINE, or a component action replacing it? How exactly would I go about doing that?

Edited by Snowhusky5
local function abc(inst, doer, actions, right)
    if inst.prefab == "trap_teeth" and inst:HasTag("minesprung") then
       table.insert(actions, ACTIONS.RESETMINE)
    end
end

AddComponentAction("SCENE", "mine", abc)

 

Edited by zUsername
9 hours ago, zUsername said:

local function abc(inst, doer, actions, right)
    if inst.prefab == "trap_teeth" and inst:HasTag("minesprung") then
       table.insert(actions, ACTIONS.RESETMINE)
    end
end

AddComponentAction("SCENE", "mine", abc)

 

This worked in making the action become left click instead of right click, but for some reason spacebar does not do anything. I've tried fixing it, but I can't figure it out. I've tried reassigning the action's priority (to 1), canforce (true), and rangecheckfn (to PICK's rangecheckfn), but it hasn't worked. Is there some other part of spacebar actions that I should be aware of?

1 hour ago, Snowhusky5 said:

This worked in making the action become left click instead of right click, but for some reason spacebar does not do anything. I've tried fixing it, but I can't figure it out. I've tried reassigning the action's priority (to 1), canforce (true), and rangecheckfn (to PICK's rangecheckfn), but it hasn't worked. Is there some other part of spacebar actions that I should be aware of?

Try this.

local oldactionpickup = GLOBAL.ACTIONS.PICKUP.fn
GLOBAL.ACTIONS.PICKUP.fn = function(act)
	if act.target ~= nil and act.target.components.mine ~= nil and act.target:HasTag("minesprung") then
        act.target.components.mine:Reset()
        return true
    end
	return oldactionpickup(act)
end

 

Edited by zUsername
2 hours ago, Snowhusky5 said:

This worked in making the action become left click instead of right click, but for some reason spacebar does not do anything. I've tried fixing it, but I can't figure it out. I've tried reassigning the action's priority (to 1), canforce (true), and rangecheckfn (to PICK's rangecheckfn), but it hasn't worked. Is there some other part of spacebar actions that I should be aware of?

As far as I know, the spacebar action is controlled by PlayerController:GetActionButtonAction in components/playercontroller.lua. Setting its field actionbuttonoverride seems like a good way to alter its behavior.

Ok, thanks for your help @zUsername and @Muche. Because I have no idea how to go about setting actionbuttonoverride, I just hijacked the PICK action, which works 99% like how I want it to (it says 'pick tooth trap' instead of 'reset tooth trap' when moused over). Will add the mod link here once I'm done making an image and uploading it to steam.

EDIT: http://steamcommunity.com/sharedfiles/filedetails/?id=617944113

Edited by Snowhusky5
local function abc(inst, doer, actions, right)
    if inst.prefab == "trap_teeth" and inst:HasTag("minesprung") then
        if right then
            if not inst:HasTag("rightclick") then inst:AddTag("rightclick") end
            table.insert(actions, ACTIONS.PICKUP)  -- right mouse will pick up teeth trap
        else
            if inst:HasTag("rightclick") then inst:RemoveTag("rightclick") end
            table.insert(actions, ACTIONS.RESETMINE) -- left mouse will reset teeth trap
        end
    end
end

AddComponentAction("SCENE", "mine", abc)

local oldactionpickup = GLOBAL.ACTIONS.PICKUP.fn
GLOBAL.ACTIONS.PICKUP.fn = function(act)
    if act.target ~= nil and act.target.prefab == "trap_teeth" and act.target.components.mine ~= nil and act.target:HasTag("minesprung") and not act.target:HasTag("rightclick") then
        act.target.components.mine:Reset()
        return true
    end
    return oldactionpickup(act)
end

Add this code in your modmain .

Edited by zUsername

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