Jump to content

Recommended Posts

I need help with an action that works from the cursor location, in general, like Maxwell's spell, there is only one.
This action should appear when the amulet is put on.
And another question: how to make an area of action that appears from the cursor?


Here's the code I usually use for actions:
AddComponentAction("POINT", "ruby_of_illusions", function(inst, doer, pos, actions, right)
 table.insert(actions, ACTIONS.RUBY_ILLUSIONS)
end)

AddAction("RUBY_ILLUSIONS", "Nigntmare", function(act)
 if act.invobject then
 act.invobject.components.ruby_illusions:nigntmare(act.inst, act.doer, act.pos, act.actions, act.right)
 return true
 end
 return false
end)

AddStategraphActionHandler("wilson", ActionHandler(ACTIONS.RUBY_ILLUSIONS, "give"))
AddStategraphActionHandler("wilson_client", ActionHandler(ACTIONS.RUBY_ILLUSIONS, "give"))

you declare RUBY_ILLUSIONS in AddAction. but you're trying to use it in AddComponentAction. the problem is that you're using the action that you declare after using it. so just change order of AddComponentAction and AddAction. AddAction have to be first and AddComponentAction second.

Edited by Mr.CrazyPotato
6 hours ago, josra102 said:

The action didn't appear.

Well, I looked at the code more. I haven;t found any problems unless you misspelled "Nightmare" to "Nigntmare" in AddAction(). Main problem has to be the AddComponentAction(). for function arguments you wrote (inst, doer, pos, actions, right) which is WRONG. You should use for POINT actions target, this is the way. So you're code might as well look like this:
 

AddAction("RUBY_ILLUSIONS", "Nightmare", function(act) -- Fixed misspell
    if act.invobject and act.invobject.components.ruby_illusions then -- Just checks that won't hurt, usually it's always added
        act.invobject.components.ruby_illusions:nightmare(act.inst, act.doer, act.pos, act.actions, act.right, act.target) -- Another fixed misspell and act.target, you need it for POINT action.
        return true
    end
    return false
end)
   
AddStategraphActionHandler("wilson", ActionHandler(ACTIONS.RUBY_ILLUSIONS, "give"))
AddStategraphActionHandler("wilson_client", ActionHandler(ACTIONS.RUBY_ILLUSIONS, "give"))

AddComponentAction("POINT", "ruby_of_illusions", function(inst, doer, pos, actions, right, target) -- Same thing
    table.insert(actions, ACTIONS.RUBY_ILLUSIONS)
end)

Make sure you're working with inventory objects but not scene prefabs, for them you'll need to use target instead of invobject.

This also didn't work, the action just doesn't appear to click. I seemed to have done as it was said but nothing. I even gave the ruby component to the character but nothing

AddAction("RUBY_OF_ILLUSIONS", "Nightmare", function(act)
    if act.invobject and act.invobject.components.ruby_of_illusions then
        act.invobject.components.ruby_of_illusions:nigntmare(act.inst, act.doer, act.pos, act.actions, act.right, act.target)
        return true
    end
    return false
end)
   
AddStategraphActionHandler("wilson", ActionHandler(ACTIONS.RUBY_OF_ILLUSIONS, "give"))
AddStategraphActionHandler("wilson_client", ActionHandler(ACTIONS.RUBY_OF_ILLUSIONS, "give"))

AddComponentAction("POINT", "ruby_of_illusions", function(inst, doer, pos, actions, right, target)
    table.insert(actions, ACTIONS.RUBY_OF_ILLUSIONS)
end)

Sorry for answearing that late, I had some things to do with school. I was wondering: what are you trying to do with this code? It's point action, sure, but I just have no idea what you're trying to achieve. You want action on the ground on right mouse button for your character which will have this component? Or is that something else? Just I've been thinking that maybe the more exact point of code will help me understand what should I do to help you.

Hi. I've been working on something else for now and only this ruby is left. So I tried to do it through "spellcaster" but it doesn't want to work, apparently because it's an item on the body and not in the hand. And I tried like a willow spell but there they go through "spellbook" and I understood how to do it and I don't need it. In general, I have no ideas. And trying to make a new action didn't work, it just doesn't appear

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