Page 1 of 1

Spawn Button / Lever connected to Door

Posted: Wed Sep 19, 2012 2:34 pm
by djoldgames
Is there any way how to connect my spawned Button or Lever (in the script ewntity) with the door?
I am missing some hook on Button entity like "onActivate = function(self)......"

I need spawn some buttons "on-the-fly" in my script entity (after activate pressure plate) and these must be active - connected to doors.
- Or eventually How to I remove entity (button/lever) created by editor
- Or eventually How to I hide entity (button/lever) created by editor
- Or eventually How to I move entity (to wall) or change its facing

Code: Select all

-- first: clone new custom button in the objects.lua
cloneObject{
       name = "Custom_wall_button",
       baseObject = "wall_button",
       -- need the onActivate hook
}

-- next in the lua script entity
function ActivatePressurePlate()
       spawn("Custom_wall_button", 1, 10, 21, 2, "MyWallbutton1")
       -- is there any way to connect MyWallbutton1 to the door?
end
Thanks for answer.

Re: Spawn Button / Lever connected to Door

Posted: Wed Sep 19, 2012 2:36 pm
by petri
You can use the addConnector() method to connect the button to the door. There was an example script somewhere on the forum.

Re: Spawn Button / Lever connected to Door

Posted: Wed Sep 19, 2012 2:44 pm
by Montis
petri wrote:You can use the addConnector() method to connect the button to the door. There was an example script somewhere on the forum.
Is this method described somewhere in the documentation? I can't seem to find it.

Re: Spawn Button / Lever connected to Door

Posted: Wed Sep 19, 2012 3:44 pm
by djoldgames
petri wrote:You can use the addConnector() method to connect the button to the door. There was an example script somewhere on the forum.
Thank you for the tip. BTW addConnector() example script isn't anywhere on the forum, only in this thread ;-)
I do some try/catch in the editor and this is the right code:

addConnector(Event, Target, Toggle)
-- all parameters must be strings

Code: Select all

function ActivatePressurePlate()
       spawn("Custom_wall_button", 1, 10, 21, 2, "MyWallbutton1")
       MyWallbutton1:addConnector("toggle","dungeon_door_metal_6","toggle")
end

Re: Spawn Button / Lever connected to Door

Posted: Wed Sep 19, 2012 5:02 pm
by Komag
This is very nice! I've added it to the script repository :)

does it have to be a custom (newly cloned) wall button?

EDIT - no, it can just be "wall_button" that is spawned