ID:296815
 
Warps by Forum_account
An easy way to create tiles that warp mobs to another location.
5 fans · Created Feb 11 2012
The library defines the /warp type which you can use to create warps. All you have to do is define a sub-type of /warp (ex: /warp/warp_01), open the map editor, and place the warp on two tiles. When you run the game, the player will be teleported from one tile to the other when they step on the warp.

The library is simple but can be used in more complex ways. It comes with five demos that show how to use it in different ways. The demos are:
  • conditional-warp-demo - Shows how to create a warp that only works if the mob using it meets certain criteria. Also shows how to create a warp with two destinations that picks a destination based on the mob using the warp.
  • one-way-demo - Shows how to create warps that only work in one direction.
  • simple-demo - Shows the basic usage of the library - creating pairs of turfs that teleport the player back and forth when stepped on.
  • transition-demo - Shows how to implement a simple fade in/out transition when a warp is used.
  • warp-function-demo - Shows how to customize multi-tile warps by overriding the warp_function proc.

Version History

Version 2 (posted 02-14-2012)
  • Added support for multi-tile warp areas. By default, the library will group all adjacent turfs in the same warp area and treat them as a single entrance/exit point. If you place the same warp area on both sides of a three tile wide doorway, the library will treat each group of three turfs as a single group and will know to move objects to the other group.
  • Added partition.dm which contains the warp.partition() proc. This proc is used to split the turfs in a warp into disjoint sets, which is needed for multi-tile warps.
  • Updated the default behavior of destination(). If the warp has a target type defined, it finds a turf in that area. If it contains two turfs, it returns the one the object isn't on. Otherwise, it calls warp_function().
  • Added the warp.warp_function() proc. By default, this proc partitions the turfs and defines the destination to be the first turf found in a different set.
  • Updated the simple-demo to include a multi-tile warp and icons for the warp areas.
  • Added the warp-function-demo which shows how to modify warps by overriding their warp_function proc.
  • Added the transition-demo which shows how to create transitions between screens.
  • Removed the advanced-demo and door-demo.
Version 1 (posted 02-11-2012)
  • Initial version.
I was hesitant to post this because it's very simple (including whitespace and comments the library is 58 lines). The demos are almost more complicated than the library.

Still, this is something that I use so I figured there's no harm in making it available to other people. Also, it could be useful to have some simpler libraries so people can get used to using libraries (running demos that come with them, including them in projects, etc.).
I just posted an update which added some new functionality and consolidated the content of the demos to make room for new ones.

The library still works the same way - you place the /warp area on the map and a warp is created between the turfs place inside the same type of area. The difference is that the library now has support for multi-tile warps. For example, suppose you have a doorway that's three tiles wide:

 ##########
# #
# #
# #
# #
####...###

on another z level:

##########
##########
##########
##########
####...###

. = warp
# = wall

The library will detect that the warp area contains more than two tiles and it'll partition the contents of the area into disjoint sets. In this example there are two disjoint sets (two sets of three turfs each). When you use the warp it'll move you to a turf that's not in the set you stepped in. This way you'll automatically be moved back and forth between the interior and exterior.
This is really awesome!

I was wondering, would there be a simplified way to handle this situation with your warps library?:

I use a turf-based warp system that goes off of names for this but I'm considering switching to your library since it seems a lot better.

overworld

In this screenshot we have the overworld. The blue tile is a town that the player can enter.

town

That blue tile on the overworld sends the player to the blue tile in the town. This blue tile in the town is locked however, and cannot be used to return to the overworld so it's all one-way. The tiles marked with the red surround the entire perimeter of the town, and if the player ventures onto those he's warped back to the overworld, HOWEVER.

overworld

The player, if he steps on any of the red tiles, is sent to the red tile on the overworld. From there I have set up a variable to offset the player a tile over onto the town, so that it appears he exited from the town (blue) tile. The red tile on the overworld there is locked and cannot be used to go into the town (one-way.)

My problem is that for every town I have to whip up four instances of the warp tile (I modify all that stuff in the map editor's instance creator) to handle warping into the town, the locked warp that corresponds to entering the town, the exit files surrounding the town, and the locked warp that corresponds to exiting the town and putting the player over on the town tile. It's really time consuming and I'm wondering if with your library there would be a faster way to simplify this whole process without having to make four instances of tiles to handle all that.
Yep, you can easily handle that. I'm not sure what the red spot is on the first and last screenshots. Is the town shown as two tiles? Or is it just the blue tile?

warp
town_01
// place this around the perimeter of the town
exit
target = /warp/town_01/outside

// place this on the town on the overworld map
outside
target = /warp/town_01/inside

// place this inside the town where you want players to be moved to
inside
warp()

The /warp/town_01/inside type only exists to be a target. We override its warp() proc to make it not do anything when we step on it.

Placing three areas on the map is certainly easier than editing turf instances in the map editor =)
The town's just one tile. The red tile in the first and last screenshots is a locked warp turf that is basically used to be where the red exit perimeter in the town sends the player.

e: The code you posted does exactly what I was doing but with a lot less effort. Thank you!
Hrm. I have a door on top of one of my warps and when I open it, when it closes again it ends up getting warped. Not sure how to stop that.
You can override the warp's warp() proc to check the type of the object its warping:

warp
warp(mob/m)
if(istype(m))
..()
I tried that but it didn't work at first, but then I realized I already had a ..() going on for non-mobs, whoops. Thanks!