Unfortunately that won't work because lever connectors pass the LeverComponent as the first argument if connected to a ScriptControllerComponent, and you can't pass a component through a delayedCall without breaking save games. So you are either not imitating the connector correctly (which will break people's mods) or you are breaking save games (which will break people's mods).
You must use LeverComponent:toggle() to handle the connectors. There is no other way.
A disabled LeverComponent won't trigger its connectors. So the simplest way to do this is to start it out disabled, and have your onAnimationEvent hook enable it, toggle it, then disable it again. And remember to disable the ClickableComponent during this so that the player can't toggle the lever again themselves and mess it up. Like this:
Code: Select all
defineObject{
name = "rc_stone_ground_lever",
components = {
{
class = "Model",
model = "mod_assets/vanblam/red_cave/models/env/rc_stone_ground_lever.fbx",
staticShadow = true,
},
{
class = "Animation",
animations = {
activate = "mod_assets/vanblam/red_cave/animations/rc_stone_ground_lever_activate.fbx",
deactivate = "mod_assets/vanblam/red_cave/animations/rc_stone_ground_lever_deactivate.fbx",
},
onAnimationEvent = function(self, event)
if event == "rc_sgl_start" then
self.go.clickable:disable()
elseif event == "rc_sgl_activate" then
self.go.lever_hit1:restart()
self.go.lever:enable()
self.go.lever:toggle()
self.go.lever:disable()
self.go.clickable:enable()
elseif event == "rc_sgl_deactivate" then
self.go.lever_hit2:restart()
end
end,
},
{
class = "Clickable",
offset = vec(0,0.9,-0.7),
size = vec(1, 0.6, 0.2),
maxDistance = 1,
--debugDraw = true,
},
{
class = "Lever",
sound = "rc_stone_lever",
enabled = false,
},
{
class = "Particle",
name = "lever_hit1",
offset = vec(-0.158,0.54,-0.7),
particleSystem = "rc_hit_lever",
},
{
class = "Particle",
name = "lever_hit2",
offset = vec(0.155,0.54,-0.7),
particleSystem = "rc_hit_lever",
},
},
placement = "wall",
editorIcon = 12,
tags = { "red cave", "vanblam" },
}
defineAnimationEvent{
animation = "mod_assets/vanblam/red_cave/animations/rc_stone_ground_lever_activate.fbx",
event = "rc_sgl_start",
frame = 0,
}
defineAnimationEvent{
animation = "mod_assets/vanblam/red_cave/animations/rc_stone_ground_lever_activate.fbx",
event = "rc_sgl_activate",
frame = 19,
}
defineAnimationEvent{
animation = "mod_assets/vanblam/red_cave/animations/rc_stone_ground_lever_deactivate.fbx",
event = "rc_sgl_deactivate",
frame = 19,
}
(warning I was too lazy to actually test this specific code)
Note that this will only trigger the lever's onToggle and onDeactivate connectors, not its onActivate connectors. You might prefer to leave the LeverComponent enabled the whole time instead, which will make it trigger its onActivate and onToggle connectors when initially pulled, and its onDeactivate and onToggle connectors when it flips back up.