Request: Allow to abort teletransportations if some condition is satisfied

Started by Diarandor, December 17, 2015, 12:47:27 AM

Previous topic - Next topic
Hi! I need help/advice for this problem:

I would like to abort teletransportation if some condition is satisfied.

In particular, what I want is that if the hero is jumping over some teletransporter, then he should not be teleported. This is the purpose I had in mind, and until now I was disabling all teletransporters of the map before the jump for 1 second and then enabling them with a timer, which is not a clean solution in my opinion because you have to get all the teletransporters of the map.

Note that we have to avoid using the method "teletransporter:on_activated()" because we could be overriding it when it is defined, so we should not use it to teletransport the hero to the same map and position (also that would play the teletransporter sound...).

My ideas:

From the engine part: I suggest/request to add an optional method "teletransporter:teleportation_test()" returning a boolean (this would be similar to custom collision test functions). If this method is not defined, then the behaviour would be as usual. Otherwise, the engine would use that method as a test to know if the teletransporter can be used or not.

Another solution could be to use sensors or custom entities as teletransporters, but I think that the engine should give a cleaner solution allowing to use built-in teletransporters.

What do you recommend me to do? Do you have some better idea?
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

I don't have a better idea than teletransporter:on_activated() or custom entities.
There is a more general problem that events can be defined only once. It would be better to be allowed to add several teletransporter:on_activated() events, enemy:on_dead() events, etc. but this would require a total change of syntax.

Ok, thanks a lot for the help. It is a hard problem indeed.

I think I will use the following solution for my problem: using the function "map:get_entities(x, y, width, height)" during the jump to get all neighboring teletransporters and disable them during the jump. That should be faster. The only annoying thing is that I will have to avoid using sprites on teletransporters since they will disappear during the jump when I disable them. Or maybe I will just use custom entities...
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."

Maybe you can use a teletransporter just for the ease of the GUI in the quest editor, and automatically disable teletransporters at runtime and replace them by custom entities.

Thats a great idea! I will do that. I just need a function in the map metatable to change the nonscrolling teletransporters by custom entities when the maps are loaded. It should be really easy to code that. Besides, anyone could use the scripted jump without need to change directly the teletransporters of each map, and as you say that eases the creation of teletransporters in the editor.  ;D
"If you make people think they're thinking, they'll love you. But if you really make them think, they'll hate you."